summaryrefslogtreecommitdiff
path: root/data/lalr1.java
diff options
context:
space:
mode:
authorJoel E. Denny <jdenny@clemson.edu>2009-08-25 19:41:49 -0400
committerJoel E. Denny <jdenny@clemson.edu>2009-08-25 20:34:28 -0400
commitd5eb0826afb8ede89bfe314671f2b37db55bd817 (patch)
treea101e23f9c055c54adb619ba31d2d07df777a31b /data/lalr1.java
parent1fa303077dee822a501002089f81c60fd3f5988d (diff)
downloadbison-d5eb0826afb8ede89bfe314671f2b37db55bd817.tar.gz
More fixes related to last two patches.
* data/c.m4 (b4_table_value_equals): Comment that YYID must be defined. * data/glr.c, data/lalr1.cc, data/lalr1.java, data/yacc.c: Fix yytable comments: zero indicates syntax error not default action. * data/glr.c (yyis_pact_ninf): Rename to... (yypact_value_is_default): ... this. (yyisDefaultedState): Update for rename. (yyis_table_ninf): Rename to... (yytable_value_is_error): ... this, and check for value zero besides just YYTABLE_NINF. (yygetLRActions): Check for default value from yypact. It appears that this check is always performed before this function is invoked, and so adding the check here is probably redundant. However, the code may evolve after this subtlety is forgotten. Also, update for rename to yytable_value_is_error. Because that macro now checks for zero, a different but equivalent branch of the if-then-else here is evaluated. (yyreportSyntaxError): Update for rename to yytable_value_is_error. The zero condition was mishandled before. (yyrecoverSyntaxError): Update for renames. No behavioral changes. * data/lalr1.cc, data/lalr1.java (yy_pact_value_is_default_): New function. (yy_table_value_is_error_): New function. (parse): Use new functions where possible. No behavioral changes. (yysyntax_error_, yysyntax_error): Use yy_table_value_is_error_. The zero condition was mishandled before. * data/yacc.c (yyis_pact_ninf): Rename to... (yypact_value_is_default): ... this. (yyis_table_ninf): Rename to... (yytable_value_is_error): ... this, and check for value zero besides just YYTABLE_NINF. (yysyntax_error): Update for rename to yytable_value_is_error. The zero condition was mishandled before. (yyparse): Update for renames. No behavioral changes. * src/tables.h: Improve comments about yypact, yytable, etc. more. Most importantly, say yytable value of zero means syntax error not default action. (cherry picked from commit f2b30bdf3713e6fa9fafd0fc6caed68e38248ebc) Conflicts: data/bison.m4 data/lalr1.cc data/lalr1.java data/yacc.c src/parse-gram.c src/parse-gram.h
Diffstat (limited to 'data/lalr1.java')
-rw-r--r--data/lalr1.java29
1 files changed, 23 insertions, 6 deletions
diff --git a/data/lalr1.java b/data/lalr1.java
index 950a515c..5010ba6a 100644
--- a/data/lalr1.java
+++ b/data/lalr1.java
@@ -489,7 +489,7 @@ m4_popdef([b4_at_dollar])])dnl
/* Take a decision. First try without lookahead. */
yyn = yypact_[yystate];
- if (yyn == yypact_ninf_)
+ if (yy_pact_value_is_default_ (yyn))
{
label = YYDEFAULT;
break;
@@ -528,7 +528,7 @@ m4_popdef([b4_at_dollar])])dnl
/* <= 0 means reduce or error. */
else if ((yyn = yytable_[yyn]) <= 0)
{
- if (yyn == 0 || yyn == yytable_ninf_)
+ if (yy_table_value_is_error_ (yyn))
label = YYFAIL;
else
{
@@ -632,7 +632,7 @@ m4_popdef([b4_at_dollar])])dnl
for (;;)
{
yyn = yypact_[yystate];
- if (yyn != yypact_ninf_)
+ if (!yy_pact_value_is_default_ (yyn))
{
yyn += yyterror_;
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
@@ -701,7 +701,7 @@ m4_popdef([b4_at_dollar])])dnl
int count = 0;
for (int x = yyxbegin; x < yyxend; ++x)
if (yycheck_[x + yyn] == x && x != yyterror_
- && yycheck_[x + yyn] != yytable_ninf_)
+ && !yy_table_value_is_error_ (yycheck_[x + yyn]))
++count;
// FIXME: This method of building the message is not compatible
@@ -713,7 +713,7 @@ m4_popdef([b4_at_dollar])])dnl
count = 0;
for (int x = yyxbegin; x < yyxend; ++x)
if (yycheck_[x + yyn] == x && x != yyterror_
- && yycheck_[x + yyn] != yytable_ninf_)
+ && !yy_table_value_is_error_ (yycheck_[x + yyn]))
{
res.append (count++ == 0 ? ", expecting " : " or ");
res.append (yytnamerr_ (yytname_[x]));
@@ -726,6 +726,23 @@ m4_popdef([b4_at_dollar])])dnl
return "syntax error";
}
+ /**
+ * Whether the given <code>yypact_</code> value indicates a defaulted state.
+ * @@param yyvalue the value to check
+ */
+ private static boolean yy_pact_value_is_default_ (int yyvalue)
+ {
+ return yyvalue == yypact_ninf_;
+ }
+
+ /**
+ * Whether the given <code>yytable_</code> value indicates a syntax error.
+ * @@param yyvalue the value to check
+ */
+ private static boolean yy_table_value_is_error_ (int yyvalue)
+ {
+ return yyvalue == 0 || yyvalue == yytable_ninf_;
+ }
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
@@ -758,7 +775,7 @@ m4_popdef([b4_at_dollar])])dnl
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule which
- number is the opposite. If zero, do what YYDEFACT says. */
+ number is the opposite. If zero or YYTABLE_NINF_, syntax error. */
private static final ]b4_int_type_for([b4_table])[ yytable_ninf_ = ]b4_table_ninf[;
private static final ]b4_int_type_for([b4_table])[
yytable_[] =