@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@>
@q it under the terms of the GNU General Public License as published by@>
@q the Free Software Foundation, either version 3 of the License, or@>
@q (at your option) any later version.@>
@q SPLinT is distributed in the hope that it will be useful,@>
@q but WITHOUT ANY WARRANTY; without even the implied warranty of@>
@q MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the@>
@q GNU General Public License for more details.@>
@q You should have received a copy of the GNU General Public License@>
@q along with SPLinT. If not, see .@>
@*1\eatone{Bison}\bison\ specific routines.
The placeholder code left blank in the common routines is filed in
with the code relevant to the output of parser tables in the following sections.
@*2Tables. \namedspot{bsfile}Here are all the parser table names. Some tables are not output but adding
one to the list in the future will be easy: it does not even have to
be done here.
@=
_register_table_d(yytranslate)@;
_register_table_d(yyr1)@;
_register_table_d(yyr2)@;
_register_table_d(yydefact)@;
_register_table_d(yydefgoto)@;
_register_table_d(yypact)@;
_register_table_d(yypgoto)@;
_register_table_d(yytable)@;
_register_table_d(yycheck)@;
_register_table_d(yystos)@;
_register_table_d(yytname)@;
_register_table_d(yyprhs)@;
_register_table_d(yyrhs)@;
@ One special table requires a little bit more preparation. This is a
table that lists the depth of the stack before an implicit terminal. It
is not one of the tables that is used by \bison\ itself but is needed
if the symbolic name processing is to be implemented (\bison\ has
access to this information `on the fly'). The `new' \bison\ (starting
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.
@=
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 };
#endif
@ We populate this table below $\ldots$
@=
#ifndef BISON_IS_CRIPPLED
assert( YYNRULES + 1 == sizeof(yyprhs)/sizeof(yyprhs[0]) );
{ int i, j;
for ( i = 1; i <= YYNRULES; i++ ) {
for ( j = 0; yyrhs[ yyprhs[i] + j ] != -1; j++ ) {
assert( yyprhs[i] + j < sizeof(yyrhs) );
assert( j < yyr1[i] );
if ( @ ) {
@@;
}
}
}
}
#endif
@ @=
( strlen( yytname[ yyrhs[yyprhs[i]+j] ] ) > 1 ) &&
( yytname[ yyrhs[yyprhs[i]+j] ][0] == '$' ) &&
( yytname[ yyrhs[yyprhs[i]+j] ][1] == '@@' )
@ @=
int rule_number;
for ( rule_number = 1; rule_number < YYNRULES; rule_number++ ) {
if ( yyr1[rule_number] == yyrhs[yyprhs[i]+j] ) {
yyrthree[rule_number] = j;
break;
}
}
assert( rule_number < YYNRULES );
@ $\ldots$ and add its name to the list.
@=
_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;
@ @