Some code and documentation improvements.

* data/c.m4 (b4_table_value_equals): New macro to capture
some repeated code.
* data/glr.c (yyis_pact_ninf): Use it here.
(yyis_table_ninf): Likewise.
(yyreportSyntaxError): Improve internal comments.
* data/yacc.c (yyis_pact_ninf): New macro copied from glr.c.
Use it everywhere possible.
(yyis_table_ninf): Likewise.
(yysyntax_error): Improve internal comments.
* data/lalr1.cc (yysyntax_error_): Likewise.
* data/lalr1.java (yysyntax_error): Likewise.
* src/tables.h: Improve comments about yypact, yytable, etc.
(cherry picked from commit 8741288212)

Conflicts:

	data/lalr1.java
	data/yacc.c
This commit is contained in:
Joel E. Denny
2009-08-25 01:12:37 -04:00
parent 890ab17c84
commit 77373efad2
9 changed files with 216 additions and 168 deletions

View File

@@ -1,3 +1,19 @@
2009-08-25 Joel E. Denny <jdenny@clemson.edu>
Some code and documentation improvements.
* data/c.m4 (b4_table_value_equals): New macro to capture
some repeated code.
* data/glr.c (yyis_pact_ninf): Use it here.
(yyis_table_ninf): Likewise.
(yyreportSyntaxError): Improve internal comments.
* data/yacc.c (yyis_pact_ninf): New macro copied from glr.c.
Use it everywhere possible.
(yyis_table_ninf): Likewise.
(yysyntax_error): Improve internal comments.
* data/lalr1.cc (yysyntax_error_): Likewise.
* data/lalr1.java (yysyntax_error): Likewise.
* src/tables.h: Improve comments about yypact, yytable, etc.
2009-08-21 Joel E. Denny <jdenny@clemson.edu> 2009-08-21 Joel E. Denny <jdenny@clemson.edu>
Use locale when quoting. Use locale when quoting.

View File

@@ -134,6 +134,16 @@ m4_define([b4_int_type_for],
[b4_int_type($1_min, $1_max)]) [b4_int_type($1_min, $1_max)])
# b4_table_value_equals(TABLE, VALUE, LITERAL)
# --------------------------------------------
# Without inducing a comparison warning from the compiler, check if the
# literal value LITERAL equals VALUE from table TABLE, which must have
# TABLE_min and TABLE_max defined.
m4_define([b4_table_value_equals],
[m4_if(m4_eval($3 < m4_indir([b4_]$1[_min])
|| m4_indir([b4_]$1[_max]) < $3), [1],
[[YYID (0)]],
[[((]$2[) == (]$3[))]])])
## ---------## ## ---------##
## Values. ## ## Values. ##

View File

@@ -1014,9 +1014,7 @@ yylhsNonterm (yyRuleNum yyrule)
} }
#define yyis_pact_ninf(yystate) \ #define yyis_pact_ninf(yystate) \
]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), [1], ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
[0],
[((yystate) == YYPACT_NINF)])[
/** True iff LR state STATE has only a default reduction (regardless /** True iff LR state STATE has only a default reduction (regardless
* of token). */ * of token). */
@@ -1034,9 +1032,7 @@ yydefaultAction (yyStateNum yystate)
} }
#define yyis_table_ninf(yytable_value) \ #define yyis_table_ninf(yytable_value) \
]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1], ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
[YYID (0)],
[((yytable_value) == YYTABLE_NINF)])[
/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN. /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
* Result R means * Result R means
@@ -2119,7 +2115,8 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
char const *yyprefix = yyexpecting; char const *yyprefix = yyexpecting;
/* Start YYX at -YYN if negative to avoid negative indexes in /* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. */ YYCHECK. In other words, skip the first -YYN actions for this
state because they are default actions. */
int yyxbegin = yyn < 0 ? -yyn : 0; int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */ /* Stay within bounds of both yycheck and yytname. */

View File

@@ -841,7 +841,8 @@ b4_error_verbose_if([, int tok])[)
if (yypact_ninf_ < yyn && yyn <= yylast_) if (yypact_ninf_ < yyn && yyn <= yylast_)
{ {
/* Start YYX at -YYN if negative to avoid negative indexes in /* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. */ YYCHECK. In other words, skip the first -YYN actions for this
state because they are default actions. */
int yyxbegin = yyn < 0 ? -yyn : 0; int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */ /* Stay within bounds of both yycheck and yytname. */

View File

@@ -691,7 +691,8 @@ m4_popdef([b4_at_dollar])])dnl
StringBuffer res; StringBuffer res;
/* Start YYX at -YYN if negative to avoid negative indexes in /* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. */ YYCHECK. In other words, skip the first -YYN actions for this
state because they are default actions. */
int yyxbegin = yyn < 0 ? -yyn : 0; int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */ /* Stay within bounds of both yycheck and yytname. */

View File

@@ -586,6 +586,12 @@ static const ]b4_int_type_for([b4_table])[ yytable[] =
]b4_table[ ]b4_table[
}; };
#define yyis_pact_ninf(yystate) \
]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
#define yyis_table_ninf(yytable_value) \
]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
static const ]b4_int_type_for([b4_check])[ yycheck[] = static const ]b4_int_type_for([b4_check])[ yycheck[] =
{ {
]b4_check[ ]b4_check[
@@ -934,7 +940,8 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
char const *yyprefix = yyexpecting; char const *yyprefix = yyexpecting;
/* Start YYX at -YYN if negative to avoid negative indexes in /* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. */ YYCHECK. In other words, skip the first -YYN actions for this
state because they are default actions. */
int yyxbegin = yyn < 0 ? -yyn : 0; int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */ /* Stay within bounds of both yycheck and yytname. */
@@ -1347,7 +1354,7 @@ yybackup:
/* First try to decide what to do without reference to lookahead token. */ /* First try to decide what to do without reference to lookahead token. */
yyn = yypact[yystate]; yyn = yypact[yystate];
if (yyn == YYPACT_NINF) if (yyis_pact_ninf (yyn))
goto yydefault; goto yydefault;
/* Not known => get a lookahead token if don't already have one. */ /* Not known => get a lookahead token if don't already have one. */
@@ -1397,7 +1404,7 @@ yyread_pushed_token:]])[
yyn = yytable[yyn]; yyn = yytable[yyn];
if (yyn <= 0) if (yyn <= 0)
{ {
if (yyn == 0 || yyn == YYTABLE_NINF) if (yyn == 0 || yyis_table_ninf (yyn))
goto yyerrlab; goto yyerrlab;
yyn = -yyn; yyn = -yyn;
goto yyreduce; goto yyreduce;
@@ -1581,7 +1588,7 @@ yyerrlab1:
for (;;) for (;;)
{ {
yyn = yypact[yystate]; yyn = yypact[yystate];
if (yyn != YYPACT_NINF) if (!yyis_pact_ninf (yyn))
{ {
yyn += YYTERROR; yyn += YYTERROR;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
/* A Bison parser, made by GNU Bison 2.4.1.86-ae09ec. */ /* A Bison parser, made by GNU Bison 2.4.1.120-890ab. */
/* Skeleton interface for Bison's Yacc-like parsers in C /* Skeleton interface for Bison's Yacc-like parsers in C
@@ -161,7 +161,7 @@
typedef union YYSTYPE typedef union YYSTYPE
{ {
/* Line 1677 of yacc.c */ /* Line 1684 of yacc.c */
#line 94 "parse-gram.y" #line 94 "parse-gram.y"
symbol *symbol; symbol *symbol;
@@ -176,8 +176,8 @@ typedef union YYSTYPE
/* Line 1677 of yacc.c */ /* Line 1684 of yacc.c */
#line 181 "../../branch-2.5/src/parse-gram.h" #line 181 "parse-gram.h"
} YYSTYPE; } YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define yystype YYSTYPE /* obsolescent; will be withdrawn */

View File

@@ -54,8 +54,15 @@
something else to do. something else to do.
YYPACT[S] = index in YYTABLE of the portion describing state S. YYPACT[S] = index in YYTABLE of the portion describing state S.
The lookahead token's type is used to index that portion to find The lookahead token's number, I, is used to index that portion of
out what to do. YYTABLE to find out what action to perform.
If YYPACT[S] == YYPACT_NINF, if YYPACT[S] + I is outside the bounds
of YYTABLE (from 0 to YYLAST), or if YYCHECK indicates that I is
outside the bounds of the portion for S, then the default action
(from YYDEFACT and YYDEFGOTO) should be used instead of YYTABLE.
Otherwise, the value YYTABLE[YYPACT[S] + I] should be used even if
YYPACT[S] < 0.
If the value in YYTABLE is positive, we shift the token and go to If the value in YYTABLE is positive, we shift the token and go to
that state. that state.
@@ -64,6 +71,8 @@
If the value is zero, the default action from YYDEFACT[S] is used. If the value is zero, the default action from YYDEFACT[S] is used.
If the value is YYTABLE_NINF, it's a syntax error.
YYPGOTO[I] = the index in YYTABLE of the portion describing what to YYPGOTO[I] = the index in YYTABLE of the portion describing what to
do after reducing a rule that derives variable I + NTOKENS. This do after reducing a rule that derives variable I + NTOKENS. This
portion is indexed by the parser state number, S, as of before the portion is indexed by the parser state number, S, as of before the