+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>
* src/tables.h, src/tables.c, src/output.c: Comment changes.
/* YYFINAL -- State number of the termination state. */
#define YYFINAL ]b4_final_state_number[
+/* YYLAST -- Last index in YYTABLE. */
#define YYLAST ]b4_last[
/* YYNTOKENS -- Number of terminals. */
static inline bool
yyisShiftAction (int yyaction)
{
- return yyaction > 0;
+ return 0 < yyaction;
}
static inline bool
size_t yysize, yynewSize;
size_t yyn;
yysize = yystack->yynextFree - yystack->yyitems;
- if (yysize >= YYMAXDEPTH)
+ if (YYMAXDEPTH <= yysize)
yyFail (yystack, "parsing stack overflow (%d items)", yysize);
yynewSize = 2*yysize;
- if (yynewSize > YYMAXDEPTH)
+ if (YYMAXDEPTH < yynewSize)
yynewSize = YYMAXDEPTH;
yyinitGLRStack (&yynewStack, yynewSize);
for (yyp0 = yystack->yyitems, yyp1 = yynewStack.yyitems, yyn = yysize;
- yyn > 0;
+ 0 < yyn;
yyn -= 1, yyp0 += 1, yyp1 += 1)
{
*yyp1 = *yyp0;
int yyi;
yyGLRState* yys;
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)
{
assert (yys->yypred != NULL);
YYDPRINTF ((stderr, "Reducing stack %d by rule %d (line %d),",
yyk, yyrule - 1, yyrline[yyrule]));
/* 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\n", yytokenName (yyr1[yyrule]));
}
yyStateNum yynewLRState;
for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
- yyn > 0; yyn -= 1)
+ 0 < yyn; yyn -= 1)
{
yys = yys->yypred;
assert (yys != NULL);
return 0;
if (p0 < p1)
return 3;
- if (p0 > p1)
+ if (p1 < p0)
return 2;
return 0;
}
yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack)
{
YYRESULTTAG yyflag;
- if (yyn > 0)
+ if (0 < yyn)
{
assert (yys->yypred != NULL);
yyflag = yyresolveStates (yys->yypred, yyn-1, yystack);
yynrhs = yyrhsLength (yyopt->yyrule);
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)
{
assert (yys->yypred != NULL);
yyGLRState* yys;
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;
if (yys == NULL)
yystates[0] = &YYLEFTMOST_STATE;
else
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",
yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
yyx->yyrule);
yytoken = YYEMPTY;
yyposn += 1;
yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp);
- if (yystack.yyerrState > 0)
+ if (0 < yystack.yyerrState)
yystack.yyerrState -= 1;
YYDPRINTF ((stderr, "Entering state %d\n",
yystack.yytops.yystates[0]->yylrState));
/* Constants. */
static const int eof_;
+ /* LAST_ -- Last index in TABLE_. */
static const int last_;
static const int nnts_;
static const int empty_;
}
n_ += ilooka_;
- if (n_ < 0 || n_ > last_ || check_[[n_]] != ilooka_)
+ if (n_ < 0 || last_ < n_ || check_[[n_]] != ilooka_)
goto yydefault;
/* Reduce or error. */
YYCDEBUG << "Reducing via rule " << n_ - 1
<< " (line " << rline_[[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_[[r1_[n_]]] << std::endl;
}
/* Shift the result of the reduction. */
n_ = r1_[[n_]];
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_]];
else
state_ = defgoto_[[n_ - ntokens_]];
/* YYFINAL -- State number of the termination state. */
#define YYFINAL b4_final_state_number
+/* YYLAST -- Last index in YYTABLE. */
#define YYLAST b4_last
/* YYNTOKENS -- Number of terminals. */
yysetstate:
*yyssp = yystate;
- if (yyssp >= yyss + yystacksize - 1)
+ if (yyss + yystacksize - 1 <= yyssp)
{
/* Get the current used size of the three stacks, in elements. */
YYSIZE_T yysize = yyssp - yyss + 1;
goto yyoverflowlab;
# else
/* Extend the stack our own way. */
- if (yystacksize >= YYMAXDEPTH)
+ if (YYMAXDEPTH <= yystacksize)
goto yyoverflowlab;
yystacksize *= 2;
- if (yystacksize > YYMAXDEPTH)
+ if (YYMAXDEPTH < yystacksize)
yystacksize = YYMAXDEPTH;
{
YYDPRINTF ((stderr, "Stack size increased to %lu\n",
(unsigned long int) yystacksize));
- if (yyssp >= yyss + yystacksize - 1)
+ if (yyss + yystacksize - 1 <= yyssp)
YYABORT;
}
yyn - 1, yyrline[yyn]);
/* 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\n", yytname[yyr1[yyn]]);
}
/* Pop the error token. */
YYPOPSTACK;
/* Pop the rest of the stack. */
- while (yyssp > yyss)
+ while (yyss < yyssp)
{
YYDPRINTF ((stderr, "Error: popping "));
YYDSYMPRINT ((stderr,
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number_t)
-/*-----------------------------------------------------------------.
-| Prepare the muscles related to the tokens: translate, tname, and |
-| toknum. |
-`-----------------------------------------------------------------*/
+/*------------------------------------------------------------------.
+| Prepare the muscles related to the symbols: translate, tname, and |
+| toknum. |
+`------------------------------------------------------------------*/
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",
token_translations,
token_translations[0],
1, max_user_token_number + 1);
+ /* tname -- token names. */
{
int i;
int j = 0;
muscle_insert_short_table ("dprec", dprec, 0, 0, nrules);
muscle_insert_short_table ("merger", merger, 0, 0, nrules);
+ MUSCLE_INSERT_INT ("rules_number", nrules);
+
free (rhs);
free (prhs);
free (rline);
values[i] = states[i]->accessing_symbol;
muscle_insert_symbol_number_table ("stos", values,
0, 1, nstates);
+
+ MUSCLE_INSERT_INT ("last", high);
+ MUSCLE_INSERT_INT ("final_state_number", final_state->number);
+ MUSCLE_INSERT_INT ("states_number", nstates);
}
that case. Nevertheless, it seems even better to be able to use
the GLR skeletons even without the non-deterministic tables. */
muscle_insert_unsigned_int_table ("conflict_list_heads", conflict_table,
- conflict_table[0], 1, high+1);
+ conflict_table[0], 1, high + 1);
muscle_insert_unsigned_int_table ("conflicting_rules", conflict_list,
conflict_list[0], 1, conflict_list_cnt);
}
MUSCLE_INSERT_STRING ("output_parser_name", parser_file_name);
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. */
obstack_1grow (&pre_prologue_obstack, 0);
obstack_1grow (&post_prologue_obstack, 0);
{
obstack_init (&format_obstack);
- prepare_tokens ();
+ prepare_symbols ();
prepare_rules ();
prepare_states ();
prepare_actions ();
default (from YYDEFACT or YYDEFGOTO) should be used. Otherwise,
YYTABLE[P+I] should be used.
- YYFINAL = the state number of the termination state. YYFLAG = most
- negative short int. Used to flag ?? */
+ YYFINAL = the state number of the termination state.
+
+ YYLAST ( = high) the number of the last element of YYTABLE, i.e.,
+ sizeof (YYTABLE) - 1. */
extern int nvectors;