* src/output.c (prepare): Move the definition of `tokens_number',

`nterms_number', `undef_token_number', `user_token_number_max'
to...
(prepare_tokens): Here.
(prepare_tokens): Rename as...
(prepare_symbols): this.
(prepare): Move the definition of `rules_number' to...
(prepare_rules): here.
(prepare): Move the definition of `last', `final_state_number',
`states_number' to...
(prepare_states): here.
* data/yacc.c, data/lalr1.cc, data/glr.c: Normalize `>' into `<'.
This commit is contained in:
Akim Demaille
2002-10-20 11:20:15 +00:00
parent 20c1e2ad98
commit 39912f5263
6 changed files with 63 additions and 45 deletions

View File

@@ -1,3 +1,18 @@
2002-10-20 Akim Demaille <akim@epita.fr>
* src/output.c (prepare): Move the definition of `tokens_number',
`nterms_number', `undef_token_number', `user_token_number_max'
to...
(prepare_tokens): Here.
(prepare_tokens): Rename as...
(prepare_symbols): this.
(prepare): Move the definition of `rules_number' to...
(prepare_rules): here.
(prepare): Move the definition of `last', `final_state_number',
`states_number' to...
(prepare_states): here.
* data/yacc.c, data/lalr1.cc, data/glr.c: Normalize `>' into `<'.
2002-10-20 Akim Demaille <akim@epita.fr> 2002-10-20 Akim Demaille <akim@epita.fr>
* src/tables.h, src/tables.c, src/output.c: Comment changes. * src/tables.h, src/tables.c, src/output.c: Comment changes.

View File

@@ -231,6 +231,7 @@ static YYLTYPE yyloc_default;
/* YYFINAL -- State number of the termination state. */ /* YYFINAL -- State number of the termination state. */
#define YYFINAL ]b4_final_state_number[ #define YYFINAL ]b4_final_state_number[
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST ]b4_last[ #define YYLAST ]b4_last[
/* YYNTOKENS -- Number of terminals. */ /* YYNTOKENS -- Number of terminals. */
@@ -739,7 +740,7 @@ yyLRgotoState (yyStateNum yystate, yySymbol yylhs)
static inline bool static inline bool
yyisShiftAction (int yyaction) yyisShiftAction (int yyaction)
{ {
return yyaction > 0; return 0 < yyaction;
} }
static inline bool static inline bool
@@ -825,14 +826,14 @@ yyexpandGLRStack (yyGLRStack* yystack)
size_t yysize, yynewSize; size_t yysize, yynewSize;
size_t yyn; size_t yyn;
yysize = yystack->yynextFree - yystack->yyitems; yysize = yystack->yynextFree - yystack->yyitems;
if (yysize >= YYMAXDEPTH) if (YYMAXDEPTH <= yysize)
yyFail (yystack, "parsing stack overflow (%d items)", yysize); yyFail (yystack, "parsing stack overflow (%d items)", yysize);
yynewSize = 2*yysize; yynewSize = 2*yysize;
if (yynewSize > YYMAXDEPTH) if (YYMAXDEPTH < yynewSize)
yynewSize = YYMAXDEPTH; yynewSize = YYMAXDEPTH;
yyinitGLRStack (&yynewStack, yynewSize); yyinitGLRStack (&yynewStack, yynewSize);
for (yyp0 = yystack->yyitems, yyp1 = yynewStack.yyitems, yyn = yysize; for (yyp0 = yystack->yyitems, yyp1 = yynewStack.yyitems, yyn = yysize;
yyn > 0; 0 < yyn;
yyn -= 1, yyp0 += 1, yyp1 += 1) yyn -= 1, yyp0 += 1, yyp1 += 1)
{ {
*yyp1 = *yyp0; *yyp1 = *yyp0;
@@ -1024,7 +1025,7 @@ yydoAction (yyGLRStack* yystack, int yyk, yyRuleNum yyrule,
int yyi; int yyi;
yyGLRState* yys; yyGLRState* yys;
yyGLRStackItem yyrhsVals[YYMAXRHS]; yyGLRStackItem yyrhsVals[YYMAXRHS];
for (yyi = yynrhs-1, yys = yystack->yytops.yystates[yyk]; yyi >= 0; for (yyi = yynrhs-1, yys = yystack->yytops.yystates[yyk]; 0 <= yyi;
yyi -= 1, yys = yys->yypred) yyi -= 1, yys = yys->yypred)
{ {
assert (yys->yypred != NULL); assert (yys->yypred != NULL);
@@ -1078,7 +1079,7 @@ yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
YYDPRINTF ((stderr, "Reducing stack %d by rule %d (line %d),", YYDPRINTF ((stderr, "Reducing stack %d by rule %d (line %d),",
yyk, yyrule - 1, yyrline[yyrule])); yyk, yyrule - 1, yyrline[yyrule]));
/* Print the symbols being reduced, and their result. */ /* Print the symbols being reduced, and their result. */
for (yyi = yyprhs[yyrule]; yyrhs[yyi] >= 0; yyi++) for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi])); YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi]));
YYFPRINTF (stderr, " -> %s\n", yytokenName (yyr1[yyrule])); YYFPRINTF (stderr, " -> %s\n", yytokenName (yyr1[yyrule]));
} }
@@ -1099,7 +1100,7 @@ yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule,
yyStateNum yynewLRState; yyStateNum yynewLRState;
for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule); for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
yyn > 0; yyn -= 1) 0 < yyn; yyn -= 1)
{ {
yys = yys->yypred; yys = yys->yypred;
assert (yys != NULL); assert (yys != NULL);
@@ -1222,7 +1223,7 @@ yypreference (yySemanticOption* y0, yySemanticOption* y1)
return 0; return 0;
if (p0 < p1) if (p0 < p1)
return 3; return 3;
if (p0 > p1) if (p1 < p0)
return 2; return 2;
return 0; return 0;
} }
@@ -1235,7 +1236,7 @@ static YYRESULTTAG
yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack) yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack)
{ {
YYRESULTTAG yyflag; YYRESULTTAG yyflag;
if (yyn > 0) if (0 < yyn)
{ {
assert (yys->yypred != NULL); assert (yys->yypred != NULL);
yyflag = yyresolveStates (yys->yypred, yyn-1, yystack); yyflag = yyresolveStates (yys->yypred, yyn-1, yystack);
@@ -1263,7 +1264,7 @@ yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack,
yynrhs = yyrhsLength (yyopt->yyrule); yynrhs = yyrhsLength (yyopt->yyrule);
YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack)); YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack));
for (yyi = yynrhs-1, yys = yyopt->yystate; yyi >= 0; for (yyi = yynrhs-1, yys = yyopt->yystate; 0 <= yyi;
yyi -= 1, yys = yys->yypred) yyi -= 1, yys = yys->yypred)
{ {
assert (yys->yypred != NULL); assert (yys->yypred != NULL);
@@ -1294,14 +1295,14 @@ static void yyreportTree (yySemanticOption* yyx, int yyindent)
yyGLRState* yys; yyGLRState* yys;
yyGLRState* yystates[YYMAXRHS]; yyGLRState* yystates[YYMAXRHS];
for (yyi = yynrhs, yys = yyx->yystate; yyi > 0; yyi -= 1, yys = yys->yypred) for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
yystates[yyi] = yys; yystates[yyi] = yys;
if (yys == NULL) if (yys == NULL)
yystates[0] = &YYLEFTMOST_STATE; yystates[0] = &YYLEFTMOST_STATE;
else else
yystates[0] = yys; yystates[0] = yys;
if (yys->yyposn+1 > yyx->yystate->yyposn) if (yyx->yystate->yyposn < yys->yyposn + 1)
YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n", YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)), yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
yyx->yyrule); yyx->yyrule);
@@ -1735,7 +1736,7 @@ yyparse (YYPARSE_PARAM_ARG)
yytoken = YYEMPTY; yytoken = YYEMPTY;
yyposn += 1; yyposn += 1;
yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp); yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp);
if (yystack.yyerrState > 0) if (0 < yystack.yyerrState)
yystack.yyerrState -= 1; yystack.yyerrState -= 1;
YYDPRINTF ((stderr, "Entering state %d\n", YYDPRINTF ((stderr, "Entering state %d\n",
yystack.yytops.yystates[0]->yylrState)); yystack.yytops.yystates[0]->yylrState));

View File

@@ -257,6 +257,7 @@ namespace yy
/* Constants. */ /* Constants. */
static const int eof_; static const int eof_;
/* LAST_ -- Last index in TABLE_. */
static const int last_; static const int last_;
static const int nnts_; static const int nnts_;
static const int empty_; static const int empty_;
@@ -374,7 +375,7 @@ yy::b4_parser_class_name::parse ()
} }
n_ += ilooka_; n_ += ilooka_;
if (n_ < 0 || n_ > last_ || check_[[n_]] != ilooka_) if (n_ < 0 || last_ < n_ || check_[[n_]] != ilooka_)
goto yydefault; goto yydefault;
/* Reduce or error. */ /* Reduce or error. */
@@ -442,7 +443,7 @@ yy::b4_parser_class_name::parse ()
YYCDEBUG << "Reducing via rule " << n_ - 1 YYCDEBUG << "Reducing via rule " << n_ - 1
<< " (line " << rline_[[n_]] << "), "; << " (line " << rline_[[n_]] << "), ";
for (b4_int_type_for([b4_prhs]) i = prhs_[[n_]]; for (b4_int_type_for([b4_prhs]) i = prhs_[[n_]];
rhs_[[i]] >= 0; ++i) 0 <= rhs_[[i]]; ++i)
YYCDEBUG << name_[[rhs_[i]]] << ' '; YYCDEBUG << name_[[rhs_[i]]] << ' ';
YYCDEBUG << "-> " << name_[[r1_[n_]]] << std::endl; YYCDEBUG << "-> " << name_[[r1_[n_]]] << std::endl;
} }
@@ -483,7 +484,7 @@ yy::b4_parser_class_name::parse ()
/* Shift the result of the reduction. */ /* Shift the result of the reduction. */
n_ = r1_[[n_]]; n_ = r1_[[n_]];
state_ = pgoto_[[n_ - ntokens_]] + state_stack_[[0]]; state_ = pgoto_[[n_ - ntokens_]] + state_stack_[[0]];
if (state_ >= 0 && state_ <= last_ && check_[[state_]] == state_stack_[[0]]) if (0 <= state_ && state_ <= last_ && check_[[state_]] == state_stack_[[0]])
state_ = table_[[state_]]; state_ = table_[[state_]];
else else
state_ = defgoto_[[n_ - ntokens_]]; state_ = defgoto_[[n_ - ntokens_]];

View File

@@ -319,6 +319,7 @@ b4_location_if(
/* YYFINAL -- State number of the termination state. */ /* YYFINAL -- State number of the termination state. */
#define YYFINAL b4_final_state_number #define YYFINAL b4_final_state_number
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST b4_last #define YYLAST b4_last
/* YYNTOKENS -- Number of terminals. */ /* YYNTOKENS -- Number of terminals. */
@@ -811,7 +812,7 @@ yyparse (YYPARSE_PARAM_ARG)
yysetstate: yysetstate:
*yyssp = yystate; *yyssp = yystate;
if (yyssp >= yyss + yystacksize - 1) if (yyss + yystacksize - 1 <= yyssp)
{ {
/* Get the current used size of the three stacks, in elements. */ /* Get the current used size of the three stacks, in elements. */
YYSIZE_T yysize = yyssp - yyss + 1; YYSIZE_T yysize = yyssp - yyss + 1;
@@ -843,10 +844,10 @@ yyparse (YYPARSE_PARAM_ARG)
goto yyoverflowlab; goto yyoverflowlab;
# else # else
/* Extend the stack our own way. */ /* Extend the stack our own way. */
if (yystacksize >= YYMAXDEPTH) if (YYMAXDEPTH <= yystacksize)
goto yyoverflowlab; goto yyoverflowlab;
yystacksize *= 2; yystacksize *= 2;
if (yystacksize > YYMAXDEPTH) if (YYMAXDEPTH < yystacksize)
yystacksize = YYMAXDEPTH; yystacksize = YYMAXDEPTH;
{ {
@@ -872,7 +873,7 @@ yyparse (YYPARSE_PARAM_ARG)
YYDPRINTF ((stderr, "Stack size increased to %lu\n", YYDPRINTF ((stderr, "Stack size increased to %lu\n",
(unsigned long int) yystacksize)); (unsigned long int) yystacksize));
if (yyssp >= yyss + yystacksize - 1) if (yyss + yystacksize - 1 <= yyssp)
YYABORT; YYABORT;
} }
@@ -1005,7 +1006,7 @@ yyreduce:
yyn - 1, yyrline[yyn]); yyn - 1, yyrline[yyn]);
/* Print the symbols being reduced, and their result. */ /* Print the symbols being reduced, and their result. */
for (yyi = yyprhs[yyn]; yyrhs[yyi] >= 0; yyi++) for (yyi = yyprhs[yyn]; 0 <= yyrhs[yyi]; yyi++)
YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]); YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]); YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
} }
@@ -1126,7 +1127,7 @@ yyerrlab1:
/* Pop the error token. */ /* Pop the error token. */
YYPOPSTACK; YYPOPSTACK;
/* Pop the rest of the stack. */ /* Pop the rest of the stack. */
while (yyssp > yyss) while (yyss < yyssp)
{ {
YYDPRINTF ((stderr, "Error: popping ")); YYDPRINTF ((stderr, "Error: popping "));
YYDSYMPRINT ((stderr, YYDSYMPRINT ((stderr,

View File

@@ -107,19 +107,25 @@ GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_item_number_table, item_number_t)
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number_t) GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number_t)
/*-----------------------------------------------------------------. /*------------------------------------------------------------------.
| Prepare the muscles related to the tokens: translate, tname, and | | Prepare the muscles related to the symbols: translate, tname, and |
| toknum. | | toknum. |
`-----------------------------------------------------------------*/ `------------------------------------------------------------------*/
static void static void
prepare_tokens (void) prepare_symbols (void)
{ {
MUSCLE_INSERT_INT ("tokens_number", ntokens);
MUSCLE_INSERT_INT ("nterms_number", nvars);
MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number);
MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number);
muscle_insert_symbol_number_table ("translate", muscle_insert_symbol_number_table ("translate",
token_translations, token_translations,
token_translations[0], token_translations[0],
1, max_user_token_number + 1); 1, max_user_token_number + 1);
/* tname -- token names. */
{ {
int i; int i;
int j = 0; int j = 0;
@@ -215,6 +221,8 @@ prepare_rules (void)
muscle_insert_short_table ("dprec", dprec, 0, 0, nrules); muscle_insert_short_table ("dprec", dprec, 0, 0, nrules);
muscle_insert_short_table ("merger", merger, 0, 0, nrules); muscle_insert_short_table ("merger", merger, 0, 0, nrules);
MUSCLE_INSERT_INT ("rules_number", nrules);
free (rhs); free (rhs);
free (prhs); free (prhs);
free (rline); free (rline);
@@ -238,6 +246,10 @@ prepare_states (void)
values[i] = states[i]->accessing_symbol; values[i] = states[i]->accessing_symbol;
muscle_insert_symbol_number_table ("stos", values, muscle_insert_symbol_number_table ("stos", values,
0, 1, nstates); 0, 1, nstates);
MUSCLE_INSERT_INT ("last", high);
MUSCLE_INSERT_INT ("final_state_number", final_state->number);
MUSCLE_INSERT_INT ("states_number", nstates);
} }
@@ -566,20 +578,6 @@ prepare (void)
MUSCLE_INSERT_STRING ("output_parser_name", parser_file_name); MUSCLE_INSERT_STRING ("output_parser_name", parser_file_name);
MUSCLE_INSERT_STRING ("output_header_name", spec_defines_file); MUSCLE_INSERT_STRING ("output_header_name", spec_defines_file);
/* Symbols. */
MUSCLE_INSERT_INT ("tokens_number", ntokens);
MUSCLE_INSERT_INT ("nterms_number", nvars);
MUSCLE_INSERT_INT ("undef_token_number", undeftoken->number);
MUSCLE_INSERT_INT ("user_token_number_max", max_user_token_number);
/* Rules. */
MUSCLE_INSERT_INT ("rules_number", nrules);
/* States. */
MUSCLE_INSERT_INT ("last", high);
MUSCLE_INSERT_INT ("final_state_number", final_state->number);
MUSCLE_INSERT_INT ("states_number", nstates);
/* User Code. */ /* User Code. */
obstack_1grow (&pre_prologue_obstack, 0); obstack_1grow (&pre_prologue_obstack, 0);
obstack_1grow (&post_prologue_obstack, 0); obstack_1grow (&post_prologue_obstack, 0);
@@ -609,7 +607,7 @@ output (void)
{ {
obstack_init (&format_obstack); obstack_init (&format_obstack);
prepare_tokens (); prepare_symbols ();
prepare_rules (); prepare_rules ();
prepare_states (); prepare_states ();
prepare_actions (); prepare_actions ();

View File

@@ -85,8 +85,10 @@
default (from YYDEFACT or YYDEFGOTO) should be used. Otherwise, default (from YYDEFACT or YYDEFGOTO) should be used. Otherwise,
YYTABLE[P+I] should be used. YYTABLE[P+I] should be used.
YYFINAL = the state number of the termination state. YYFLAG = most YYFINAL = the state number of the termination state.
negative short int. Used to flag ?? */
YYLAST ( = high) the number of the last element of YYTABLE, i.e.,
sizeof (YYTABLE) - 1. */
extern int nvectors; extern int nvectors;