[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
08-yylast.patch
From: |
Akim Demaille |
Subject: |
08-yylast.patch |
Date: |
Mon, 21 Oct 2002 09:23:54 +0200 |
Index: ChangeLog
from Akim Demaille <address@hidden>
* 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 `<'.
Index: src/output.c
--- src/output.c Sun, 20 Oct 2002 09:55:38 +0200 akim
+++ src/output.c Sun, 20 Oct 2002 10:25:18 +0200 akim
@@ -106,19 +106,25 @@
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;
@@ -214,6 +220,8 @@
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);
@@ -237,6 +245,10 @@
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);
}
@@ -448,7 +460,7 @@
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);
}
@@ -525,20 +537,6 @@
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);
@@ -568,7 +566,7 @@
{
obstack_init (&format_obstack);
- prepare_tokens ();
+ prepare_symbols ();
prepare_rules ();
prepare_states ();
prepare_actions ();
Index: src/tables.h
--- src/tables.h Sun, 20 Oct 2002 09:55:38 +0200 akim
+++ src/tables.h Sun, 20 Oct 2002 10:16:25 +0200 akim
@@ -85,8 +85,10 @@
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;
Index: data/yacc.c
--- data/yacc.c Sun, 20 Oct 2002 09:51:53 +0200 akim
+++ data/yacc.c Sun, 20 Oct 2002 10:23:03 +0200 akim
@@ -319,6 +319,7 @@ m4_define([b4_symbol_actions],
/* 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. */
@@ -811,7 +812,7 @@ m4_define([b4_declare_parser_variables],
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;
@@ -843,10 +844,10 @@ m4_define([b4_declare_parser_variables],
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;
{
@@ -872,7 +873,7 @@ m4_define([b4_declare_parser_variables],
YYDPRINTF ((stderr, "Stack size increased to %lu\n",
(unsigned long int) yystacksize));
- if (yyssp >= yyss + yystacksize - 1)
+ if (yyss + yystacksize - 1 <= yyssp)
YYABORT;
}
@@ -1005,7 +1006,7 @@ yyreduce:
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]]);
}
@@ -1126,7 +1127,7 @@ yyerrlab1:
/* Pop the error token. */
YYPOPSTACK;
/* Pop the rest of the stack. */
- while (yyssp > yyss)
+ while (yyss < yyssp)
{
YYDPRINTF ((stderr, "Error: popping "));
YYDSYMPRINT ((stderr,
Index: data/lalr1.cc
--- data/lalr1.cc Sun, 20 Oct 2002 08:30:29 +0200 akim
+++ data/lalr1.cc Sun, 20 Oct 2002 10:18:20 +0200 akim
@@ -257,6 +257,7 @@ m4_define([b4_constructor],
/* Constants. */
static const int eof_;
+ /* LAST_ -- Last index in TABLE_. */
static const int last_;
static const int nnts_;
static const int empty_;
@@ -374,7 +375,7 @@ yy::b4_parser_class_name::parse ()
}
n_ += ilooka_;
- if (n_ < 0 || n_ > last_ || check_[[n_]] != ilooka_)
+ if (n_ < 0 || last_ < n_ || check_[[n_]] != ilooka_)
goto yydefault;
/* Reduce or error. */
@@ -442,7 +443,7 @@ yy::b4_parser_class_name::parse ()
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;
}
@@ -483,7 +484,7 @@ yy::b4_parser_class_name::parse ()
/* 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_]];
Index: data/glr.c
--- data/glr.c Sun, 20 Oct 2002 09:51:53 +0200 akim
+++ data/glr.c Sun, 20 Oct 2002 10:28:10 +0200 akim
@@ -231,6 +231,7 @@ m4_define_default([b4_header_guard],
/* 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. */
@@ -739,7 +740,7 @@ m4_define_default([b4_header_guard],
static inline bool
yyisShiftAction (int yyaction)
{
- return yyaction > 0;
+ return 0 < yyaction;
}
static inline bool
@@ -825,14 +826,14 @@ m4_define_default([b4_header_guard],
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;
@@ -1024,7 +1025,7 @@ m4_define_default([b4_header_guard],
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);
@@ -1078,7 +1079,7 @@ m4_define_default([b4_header_guard],
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]));
}
@@ -1099,7 +1100,7 @@ m4_define_default([b4_header_guard],
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);
@@ -1222,7 +1223,7 @@ m4_define_default([b4_header_guard],
return 0;
if (p0 < p1)
return 3;
- if (p0 > p1)
+ if (p1 < p0)
return 2;
return 0;
}
@@ -1235,7 +1236,7 @@ m4_define_default([b4_header_guard],
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);
@@ -1263,7 +1264,7 @@ m4_define_default([b4_header_guard],
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);
@@ -1294,14 +1295,14 @@ m4_define_default([b4_header_guard],
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);
@@ -1735,7 +1736,7 @@ m4_define_default([b4_header_guard],
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));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 08-yylast.patch,
Akim Demaille <=