summaryrefslogtreecommitdiff
path: root/support/splint/cweb/bs.w
diff options
context:
space:
mode:
Diffstat (limited to 'support/splint/cweb/bs.w')
-rw-r--r--support/splint/cweb/bs.w60
1 files changed, 54 insertions, 6 deletions
diff --git a/support/splint/cweb/bs.w b/support/splint/cweb/bs.w
index adefd23f8b..8b32617ef3 100644
--- a/support/splint/cweb/bs.w
+++ b/support/splint/cweb/bs.w
@@ -1,4 +1,4 @@
-@q Copyright 2012-2020, Alexander Shibakov@>
+@q Copyright 2012-2024, Alexander Shibakov@>
@q This file is part of SPLinT@>
@q SPLinT is free software: you can redistribute it and/or modify@>
@@ -31,7 +31,6 @@ be done here.
_register_table_d(yypgoto)@;
_register_table_d(yytable)@;
_register_table_d(yycheck)@;
- _register_table_d(yytoknum)@;
_register_table_d(yystos)@;
_register_table_d(yytname)@;
_register_table_d(yyprhs)@;
@@ -46,8 +45,13 @@ with version~\.{3.0}) does not generate |yyprhs| and |yyrhs| or any
other arrays that contain similar information, so we fake them here if
such a crippled version of \bison\ is used.
+The |yyrimplicit| array will be used by the table output code, together with
+the postprocessor to output right hand side lengths for the term references that
+require them in the case when the `native' \bison\ references are
+used.
@<Variables and types local to the parser@>=
unsigned int yyrthree[YYNRULES + 1] = { 0 };
+ int yyrimplicit[YYNRULES + 1] = { 0 };
#ifdef BISON_IS_CRIPPLED
unsigned int yyrhs[YYNRULES + 1] = { -1 };
unsigned int yyprhs[YYNRULES + 1] = { 0 };
@@ -102,6 +106,23 @@ such a crippled version of \bison\ is used.
@<Parser table names@>=
_register_table_d(yyrthree)@;
+@ We list some macros that are used to assist the post
+processor and take advantage of the |yyrimlicit| array. As at this
+time the size of the array is unknown (the preamble is included before
+the parser file by \.{mkeparser.w} so the number of rules is unknown
+at this point), we declare the array as a pointer.
+@d BZ( term, anchor ) ( ((YYSTYPE *)&(term)) - ((YYSTYPE *)&(anchor)) + 1 )
+@d BZZ( term, anchor ) (
+ (yyrimplicit_p[yyn] = ((yyrimplicit_p[yyn] < 0) ?
+ yyrimplicit_p[yyn] : ((YYSTYPE *)&(term)) - ((YYSTYPE *)&(anchor)) + 1)),
+ ((YYSTYPE *)&(term)) - ((YYSTYPE *)&(anchor)) + 1
+)
+@<\Cee\ setup code specific to \bison@>=
+ int *yyrimplicit_p;
+
+@ @<Output parser semantic actions@>=
+ yyrimplicit_p = yyrimplicit;
+
@*2Actions. There are several ways of making |yyparse()| execute all portions of
the action code. The one chosen here makes sure that none of the
tables gets written past its last element. To see how it works, it
@@ -154,6 +175,7 @@ change affects the generated parser.
yyr1[i] = YYNTOKENS;
yydefact[0] = i;
+ yyrimplicit[i] = -yyr2[i];
yyr2[i] = 0;
yyparse(YYPARSE_PARAMETERS);
@@ -173,18 +195,32 @@ change affects the generated parser.
}
+ for ( int i = 1; i < YYNRULES + 1; i++ ) {
+
+ if ( yyrimplicit[i] > 0 ) {
+ fprintf( tables_out, "\\yyimplicitlengthset{%d}{%d}%%\n", i, yyrimplicit[i] );
+ }
+
+ }
+
@*2Constants. A generic list of constants to be used later in different contexts is defined below.
As before, the appropriate macro will be defined generically to do what is required with these
names (for example, we can turn each name into a string for reporting purposes).
@<Parser constants@>=
_register_const_d(YYEMPTY)@;
_register_const_d(YYPACT_NINF)@;
- _register_const_d(YYEOF)@;
_register_const_d(YYLAST)@;
_register_const_d(YYNTOKENS)@;
_register_const_d(YYNRULES)@;
_register_const_d(YYNSTATES)@;
_register_const_d(YYFINAL)@;
+#ifndef YYEOF
+ _register_const_d(YYSYMBOL_YYEOF)@;
+#endif
+
+@ Constants defined to maintain compatibility with the older versions of \bison.
+@<Parser virtual constants@>=
+ _register_const_d(YYSYMBOL_YYEOF, YYEOF)@;
@*2Tokens.
Similar techniques are employed in token output. Tokens are parser
@@ -582,20 +618,32 @@ rules are not output if a crippled \bison\ is used.
@ \TeX\ constant output is another place where the techniques described above are applied.
As before, the macro handles the repetitive work of initialization, declaration, etc in
-each place where the corresponding constant is mentioned. The one exception is \.{YYPACT\_NINF},
-which has to be handled separately because the underscore in its name makes it difficult to
-use it as a command sequence name.
+each place where the corresponding constant is mentioned. The exceptions are \.{YYPACT\_NINF}
+and \.{YYSYMBOL\_YYEOF} that have to be handled separately because the
+underscore in its name makes it difficult to use it as a command sequence name.
\def\YYPACTxNINFxdesc{\.{YYPACT\_NINF\_}\\{desc}}
+\def\YYSYMBOLxYYEOFxdesc{\.{YYSYMBOL\_YYEOF\_}\\{desc}}
@s YYPACT_NINF_desc TeX
+@s YYSYMBOL_YYEOF_desc TeX
@<Prepare \TeX\ format for parser constants@>=
#define _register_const_d(c_name) @[c_name##_desc.format = "\\constset{%s}{%d}%%\n"; \
c_name##_desc.name = #c_name; \
+ c_name##_desc.value = c_name; \
output_desc.output_##c_name = 1;@]
@<Parser constants@>@;
#undef _register_const_d
+#ifdef YYEOF /* other values have already been set correctly */
+#define _register_const_d(c_name,vvalue) @[c_name##_desc.format = "\\constset{%s}{%d}%%\n"; \
+ c_name##_desc.name = #c_name; \
+ c_name##_desc.value = vvalue; \
+ output_desc.output_##c_name = 1;@]
+ @<Parser virtual constants@>@;
+#undef _register_const_d
+#endif
YYPACT_NINF_desc.name = "YYPACTNINF";
+YYSYMBOL_YYEOF_desc.name = "YYSYMBOLxYYEOF";
@ Token definitions round off the \TeX\ output mode.