X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/77373efad24be4ed77391c9e8ab2f85285810311..f953cb20cfbf775f0f9755a57924bc02c73c657f:/data/lalr1.java diff --git a/data/lalr1.java b/data/lalr1.java index 74778f87..32462d78 100644 --- a/data/lalr1.java +++ b/data/lalr1.java @@ -1,6 +1,6 @@ # Java skeleton for Bison -*- autoconf -*- -# Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. +# Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ m4_ifval(m4_defn([b4_symbol_destructors]), m4_divert_push(0)dnl @output(b4_parser_file_name@)@ b4_copyright([Skeleton implementation for Bison LALR(1) parsers in Java], - [2007, 2008, 2009]) + [2007, 2008, 2009, 2010]) b4_percent_define_ifdef([package], [package b4_percent_define_get([package]); ])[/* First part of user declarations. */ @@ -308,11 +308,9 @@ b4_lexer_if([[ * printing an error message. */ public static final int YYERROR = 2; - /** - * Returned by a Bison action in order to print an error message and start - * error recovery. */ - public static final int YYFAIL = 3; - + // Internal return codes that are not supported for user semantic + // actions. + private static final int YYERRLAB = 3; private static final int YYNEWSTATE = 4; private static final int YYDEFAULT = 5; private static final int YYREDUCE = 6; @@ -489,7 +487,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,8 +526,8 @@ m4_popdef([b4_at_dollar])])dnl /* <= 0 means reduce or error. */ else if ((yyn = yytable_[yyn]) <= 0) { - if (yyn == 0 || yyn == yytable_ninf_) - label = YYFAIL; + if (yy_table_value_is_error_ (yyn)) + label = YYERRLAB; else { yyn = -yyn; @@ -563,7 +561,7 @@ m4_popdef([b4_at_dollar])])dnl case YYDEFAULT: yyn = yydefact_[yystate]; if (yyn == 0) - label = YYFAIL; + label = YYERRLAB; else label = YYREDUCE; break; @@ -580,7 +578,7 @@ m4_popdef([b4_at_dollar])])dnl /*------------------------------------. | yyerrlab -- here on detecting error | `------------------------------------*/ - case YYFAIL: + case YYERRLAB: /* If not already recovering from an error, report this error. */ if (yyerrstatus_ == 0) { @@ -632,7 +630,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_) @@ -688,42 +686,62 @@ m4_popdef([b4_at_dollar])])dnl int yyn = yypact_[yystate]; if (yypact_ninf_ < yyn && yyn <= yylast_) { - StringBuffer res; - - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for this - state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = yylast_ - yyn + 1; - int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; - int count = 0; - for (int x = yyxbegin; x < yyxend; ++x) - if (yycheck_[x + yyn] == x && x != yyterror_) - ++count; - - // FIXME: This method of building the message is not compatible - // with internationalization. - res = new StringBuffer ("syntax error, unexpected "); - res.append (yytnamerr_ (yytname_[tok])); - if (count < 5) - { - count = 0; - for (int x = yyxbegin; x < yyxend; ++x) - if (yycheck_[x + yyn] == x && x != yyterror_) - { - res.append (count++ == 0 ? ", expecting " : " or "); - res.append (yytnamerr_ (yytname_[x])); - } - } - return res.toString (); + StringBuffer res; + + /* Start YYX at -YYN if negative to avoid negative + indexes in YYCHECK. In other words, skip the first + -YYN actions for this state because they are default + actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = yylast_ - yyn + 1; + int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; + int count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn] == x && x != yyterror_ + && !yy_table_value_is_error_ (yytable_[x + yyn])) + ++count; + + // FIXME: This method of building the message is not compatible + // with internationalization. + res = new StringBuffer ("syntax error, unexpected "); + res.append (yytnamerr_ (yytname_[tok])); + if (count < 5) + { + count = 0; + for (int x = yyxbegin; x < yyxend; ++x) + if (yycheck_[x + yyn] == x && x != yyterror_ + && !yy_table_value_is_error_ (yytable_[x + yyn])) + { + res.append (count++ == 0 ? ", expecting " : " or "); + res.append (yytnamerr_ (yytname_[x])); + } + } + return res.toString (); } } return "syntax error"; } + /** + * Whether the given yypact_ 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 yytable_ value indicates a syntax error. + * @@param yyvalue the value to check + */ + private static boolean yy_table_value_is_error_ (int yyvalue) + { + return yyvalue == yytable_ninf_; + } /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ @@ -756,7 +774,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 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_[] =