]> git.saurik.com Git - bison.git/commitdiff
Some code and documentation improvements.
authorJoel E. Denny <jdenny@clemson.edu>
Tue, 25 Aug 2009 05:12:37 +0000 (01:12 -0400)
committerJoel E. Denny <jdenny@clemson.edu>
Tue, 25 Aug 2009 06:56:46 +0000 (02:56 -0400)
* 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.

ChangeLog
data/c.m4
data/glr.c
data/lalr1.cc
data/lalr1.java
data/yacc.c
src/tables.h

index b831d11623ff6a7b3db25b48d843d83bab082243..dc11d517d6ee2f427ab78f408e9d2f23d54726e0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        Use locale when quoting.
 2009-08-21  Joel E. Denny  <jdenny@clemson.edu>
 
        Use locale when quoting.
index 33a4186c446570ad8f2d63afb00a36b88fcde31d..3ba48db5ea55034fb67541caa77dc8f0adb2b837 100644 (file)
--- a/data/c.m4
+++ b/data/c.m4
@@ -157,6 +157,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.  ##
index a4b921f14612a5ebe3a47093cc1dc777d068c80f..b0ad1003fb06dc1254c321cdd8a96b582fbea04e 100644 (file)
@@ -954,9 +954,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],
-        [0],
-        [((yystate) == YYPACT_NINF)])[
+  ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
 
 /** True iff LR state STATE has only a default reduction (regardless
  *  of token).  */
 
 /** True iff LR state STATE has only a default reduction (regardless
  *  of token).  */
@@ -974,9 +972,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],
-        [YYID (0)],
-        [((yytable_value) == YYTABLE_NINF)])[
+  ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
 
 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
  *  Result R means
 
 /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
  *  Result R means
@@ -2048,7 +2044,8 @@ yyreportSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
          char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
 
          /* Start YYX at -YYN if negative to avoid negative indexes in
          char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
 
          /* 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;
 
          /* Stay within bounds of both yycheck and yytname.  */
          int yyxbegin = yyn < 0 ? -yyn : 0;
 
          /* Stay within bounds of both yycheck and yytname.  */
index 2a9316de82cf1720be01c3ff7d9b54be9e864ad6..5ce0b47b70788f8bdaa72372ac03403006620d90 100644 (file)
@@ -954,7 +954,8 @@ b4_error_verbose_if([state_type yystate, int yytoken],
     if (yypact_ninf_ < yyn && yyn <= yylast_)
       {
        /* Start YYX at -YYN if negative to avoid negative indexes in
     if (yypact_ninf_ < yyn && yyn <= yylast_)
       {
        /* 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;
 
        /* Stay within bounds of both yycheck and yytname.  */
        int yyxbegin = yyn < 0 ? -yyn : 0;
 
        /* Stay within bounds of both yycheck and yytname.  */
index e68650d9f5cfc989ee4e188deb35f22bae577c19..7e274d64f12af1a55b949750fc9f1ef545eaaae5 100644 (file)
@@ -735,7 +735,8 @@ m4_popdef([b4_at_dollar])])dnl
             StringBuffer res;
 
             /* Start YYX at -YYN if negative to avoid negative indexes in
             StringBuffer res;
 
             /* 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;
 
             /* Stay within bounds of both yycheck and yytname.  */
             int yyxbegin = yyn < 0 ? -yyn : 0;
 
             /* Stay within bounds of both yycheck and yytname.  */
index fa14cc54242f43d6704bce3193bb8e6e8255b43d..968922310c2678dc14a4283b98266f014fadea78 100644 (file)
@@ -525,8 +525,14 @@ static const ]b4_int_type_for([b4_toknum])[ yytoknum[] =
 
 #define YYPACT_NINF ]b4_pact_ninf[
 
 
 #define YYPACT_NINF ]b4_pact_ninf[
 
+#define yyis_pact_ninf(yystate) \
+  ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf])[
+
 #define YYTABLE_NINF ]b4_table_ninf[
 
 #define YYTABLE_NINF ]b4_table_ninf[
 
+#define yyis_table_ninf(yytable_value) \
+  ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf])[
+
 ]b4_parser_tables_define[
 
 #define yyerrok                (yyerrstatus = 0)
 ]b4_parser_tables_define[
 
 #define yyerrok                (yyerrstatus = 0)
@@ -848,7 +854,8 @@ yysyntax_error (char *yyresult, int yystate, int yytoken)
       char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
 
       /* Start YYX at -YYN if negative to avoid negative indexes in
       char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
 
       /* 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;
 
       /* Stay within bounds of both yycheck and yytname.  */
       int yyxbegin = yyn < 0 ? -yyn : 0;
 
       /* Stay within bounds of both yycheck and yytname.  */
@@ -1271,7 +1278,7 @@ yybackup:
 
   /* First try to decide what to do without reference to lookahead token.  */
   yyn = yypact[yystate];
 
   /* First try to decide what to do without reference to lookahead token.  */
   yyn = yypact[yystate];
-  if (yyn == YYPACT_NINF)
+  if (yyis_pact_ninf (yyn))
     goto yydefault;
 
   /* Not known => get a lookahead token if don't already have one.  */
     goto yydefault;
 
   /* Not known => get a lookahead token if don't already have one.  */
@@ -1321,7 +1328,7 @@ yyread_pushed_token:]])[
   yyn = yytable[yyn];
   if (yyn <= 0)
     {
   yyn = yytable[yyn];
   if (yyn <= 0)
     {
-      if (yyn == 0 || yyn == YYTABLE_NINF)
+      if (yyn == 0 || yyis_table_ninf (yyn))
        goto yyerrlab;
       yyn = -yyn;
       goto yyreduce;
        goto yyerrlab;
       yyn = -yyn;
       goto yyreduce;
@@ -1505,7 +1512,7 @@ yyerrlab1:
   for (;;)
     {
       yyn = yypact[yystate];
   for (;;)
     {
       yyn = yypact[yystate];
-      if (yyn != YYPACT_NINF)
+      if (!yyis_pact_ninf (yyn))
        {
          yyn += YYTERROR;
          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
        {
          yyn += YYTERROR;
          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
index a44cdb863a1ba4c826f75538007cff62af6cc7a8..b21fa7b0b0079520ee130bec35339d440c4bd749 100644 (file)
    something else to do.
 
    YYPACT[S] = index in YYTABLE of the portion describing state S.
    something else to do.
 
    YYPACT[S] = index in YYTABLE of the portion describing state S.
-   The lookahead token's type is used to index that portion to find
-   out what to do.
+   The lookahead token's number, I, is used to index that portion of
+   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
    that state.
 
    If the value in YYTABLE is positive, we shift the token and go to
    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
    do after reducing a rule that derives variable I + NTOKENS.  This
    portion is indexed by the parser state number, S, as of before the
    YYPGOTO[I] = the index in YYTABLE of the portion describing what to
    do after reducing a rule that derives variable I + NTOKENS.  This
    portion is indexed by the parser state number, S, as of before the