bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Synchronising GLR and YACC debugging traces


From: Akim Demaille
Subject: Synchronising GLR and YACC debugging traces
Date: 13 Nov 2002 10:46:44 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter)

I'm installing this patch, which helps comparing the behavior of the
two parsers on deterministic parsing.  In particular, it helps
tracking down the test 42 failure by comparison with test 41.  Plus,
it improves the parsers readability.

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        
        * data/yacc.c: Leave bigger chunks of quoted text.
        (YYDSYMPRINTF): New.
        Use it to report symbol activities.
        * data/glr.c (YYDSYMPRINTF): New.
        Use it.
        
Index: data/yacc.c
--- data/yacc.c Wed, 13 Nov 2002 07:26:21 +0100 akim
+++ data/yacc.c Wed, 13 Nov 2002 08:22:54 +0100 akim
@@ -138,7 +138,7 @@ m4_define([b4_rhs_location],
 m4_divert(0)dnl
 @output @output_parser_name@
 b4_copyright([Skeleton parser for Yacc-like parsing with Bison],
-             [1984, 1989, 1990, 2000, 2001, 2002])
+             [1984, 1989, 1990, 2000, 2001, 2002])[
 
 /* As a special exception, when this file is copied by Bison into a
    Bison output file, you may use that output file without restriction.
@@ -155,7 +155,7 @@ m4_define([b4_rhs_location],
    define necessary library symbols; they are noted "INFRINGES ON
    USER NAME SPACE" below.  */
 
-b4_identification
+]b4_identification
 m4_if(b4_prefix[], [yy], [],
 [/* If NAME_PREFIX is specified substitute the variables and functions
    names.  */
@@ -166,16 +166,16 @@ m4_define([b4_rhs_location],
 #define yychar  b4_prefix[]char
 #define yydebug b4_prefix[]debug
 #define yynerrs b4_prefix[]nerrs
-b4_location_if([#define yylloc b4_prefix[]lloc])])
+b4_location_if([#define yylloc b4_prefix[]lloc])])[
 
-b4_token_defines(b4_tokens)
+]b4_token_defines(b4_tokens)[
 
 /* Copy the first part of user declarations.  */
-b4_pre_prologue
+]b4_pre_prologue[
 
 /* Enabling traces.  */
 #ifndef YYDEBUG
-# define YYDEBUG b4_debug
+# define YYDEBUG ]b4_debug[
 #endif
 
 /* Enabling verbose error messages.  */
@@ -183,16 +183,16 @@ m4_define([b4_rhs_location],
 # undef YYERROR_VERBOSE
 # define YYERROR_VERBOSE 1
 #else
-# define YYERROR_VERBOSE b4_error_verbose
+# define YYERROR_VERBOSE ]b4_error_verbose[
 #endif
 
 #ifndef YYSTYPE
-m4_ifdef([b4_stype],
+]m4_ifdef([b4_stype],
 [b4_syncline([b4_stype_line], [b4_filename])
 typedef union b4_stype yystype;
 /* Line __line__ of __file__.  */
 b4_syncline(address@hidden@], address@hidden@])],
-[typedef int yystype;])
+[typedef int yystype;])[
 # define YYSTYPE yystype
 # define YYSTYPE_IS_TRIVIAL 1
 #endif
@@ -205,15 +205,15 @@ m4_define([b4_rhs_location],
   int last_line;
   int last_column;
 } yyltype;
-# define YYLTYPE b4_location_type
+# define YYLTYPE ]b4_location_type[
 # define YYLTYPE_IS_TRIVIAL 1
 #endif
 
 /* Copy the second part of user declarations.  */
-b4_post_prologue
+]b4_post_prologue[
 
 /* Line __line__ of __file__.  */
-b4_syncline(address@hidden@], address@hidden@])
+]b4_syncline(address@hidden@], address@hidden@])[
 
 #if ! defined (yyoverflow) || YYERROR_VERBOSE
 
@@ -256,22 +256,22 @@ m4_define([b4_rhs_location],
 {
   short yyss;
   YYSTYPE yyvs;
-  b4_location_if([  YYLTYPE yyls;
+  ]b4_location_if([  YYLTYPE yyls;
 ])dnl
-};
+[};
 
 /* The size of the maximum gap between one aligned stack and the next.  */
 # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
 
 /* The size of an array large to enough to hold all stacks, each with
    N elements.  */
-b4_location_if(
+]b4_location_if(
 [# define YYSTACK_BYTES(N) \
      ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE))     \
       + 2 * YYSTACK_GAP_MAX)],
 [# define YYSTACK_BYTES(N) \
      ((N) * (sizeof (short) + sizeof (YYSTYPE))                                
\
-      + YYSTACK_GAP_MAX)])
+      + YYSTACK_GAP_MAX)])[
 
 /* Copy COUNT objects from FROM to TO.  The source and destination do
    not overlap.  */
@@ -285,7 +285,7 @@ m4_define([b4_rhs_location],
        {                                       \
          register YYSIZE_T yyi;                \
          for (yyi = 0; yyi < (Count); yyi++)   \
-           (To)[[yyi]] = (From)[[yyi]];        \
+           (To)[yyi] = (From)[yyi];            \
        }                                       \
       while (0)
 #  endif
@@ -316,22 +316,22 @@ m4_define([b4_rhs_location],
 #endif
 
 /* YYFINAL -- State number of the termination state. */
-#define YYFINAL  b4_final_state_number
+#define YYFINAL  ]b4_final_state_number[
 /* YYLAST -- Last index in YYTABLE.  */
-#define YYLAST   b4_last
+#define YYLAST   ]b4_last[
 
 /* YYNTOKENS -- Number of terminals. */
-#define YYNTOKENS  b4_tokens_number
+#define YYNTOKENS  ]b4_tokens_number[
 /* YYNNTS -- Number of nonterminals. */
-#define YYNNTS  b4_nterms_number
+#define YYNNTS  ]b4_nterms_number[
 /* YYNRULES -- Number of rules. */
-#define YYNRULES  b4_rules_number
+#define YYNRULES  ]b4_rules_number[
 /* YYNRULES -- Number of states. */
-#define YYNSTATES  b4_states_number
+#define YYNSTATES  ]b4_states_number[
 
 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
-#define YYUNDEFTOK  b4_undef_token_number
-#define YYMAXUTOK   b4_user_token_number_max[
+#define YYUNDEFTOK  ]b4_undef_token_number[
+#define YYMAXUTOK   ]b4_user_token_number_max[
 
 #define YYTRANSLATE(YYX)                                               \
   ((YYX <= 0) ? YYEOF :                                                        
\
@@ -441,7 +441,7 @@ m4_define([b4_rhs_location],
    symbol of state STATE-NUM.  */
 static const b4_int_type_for([b4_stos]) yystos[[]] =
 {
-  b4_stos
+  b4_stos[
 };
 
 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
@@ -489,7 +489,7 @@ m4_define([b4_rhs_location],
     }                                                          \
   else                                                         \
     {                                                          \
-      yyerror (b4_yyerror_args"syntax error: cannot back up"); \
+      yyerror (]b4_yyerror_args["syntax error: cannot back up");\
       YYERROR;                                                 \
     }                                                          \
 while (0)
@@ -501,19 +501,19 @@ m4_define([b4_rhs_location],
    are run).  */
 
 #ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N)           \
-  Current.first_line   = Rhs[[1]].first_line;      \
-  Current.first_column = Rhs[[1]].first_column;    \
-  Current.last_line    = Rhs[[N]].last_line;       \
-  Current.last_column  = Rhs[[N]].last_column;
+# define YYLLOC_DEFAULT(Current, Rhs, N)         \
+  Current.first_line   = Rhs[1].first_line;      \
+  Current.first_column = Rhs[1].first_column;    \
+  Current.last_line    = Rhs[N].last_line;       \
+  Current.last_column  = Rhs[N].last_column;
 #endif
 
 /* YYLEX -- calling `yylex' with the right arguments.  */
 
 #ifdef YYLEX_PARAM
-# define YYLEX yylex (b4_pure_if([&yylval[]b4_location_if([, &yylloc]), 
])YYLEX_PARAM)
+# define YYLEX yylex (]b4_pure_if([&yylval[]b4_location_if([, &yylloc]), 
])[YYLEX_PARAM)
 #else
-# define YYLEX b4_c_function_call([yylex], [int], b4_lex_param)
+# define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
 #endif
 
 /* Enable debugging if requested.  */
@@ -534,17 +534,29 @@ m4_define([b4_rhs_location],
   if (yydebug)                                 \
     yysymprint Args;                           \
 } while (0)
+# define YYDSYMPRINTF(Title, Token, Value, Location)           \
+do {                                                           \
+  if (yydebug)                                                 \
+    {                                                          \
+      YYFPRINTF (stderr, "%s ", Title);                                \
+      yysymprint (stderr,                                      \
+                  Token, Value]b4_location_if([, Location])[); \
+      YYFPRINTF (stderr, "\n");                                        \
+    }                                                          \
+} while (0)
+
 /* Nonzero means print parse trace.  It is left uninitialized so that
    multiple parsers can coexist.  */
 int yydebug;
 #else /* !YYDEBUG */
 # define YYDPRINTF(Args)
 # define YYDSYMPRINT(Args)
+# define YYDSYMPRINTF(Title, Token, Value, Location)
 #endif /* !YYDEBUG */
 
 /* YYINITDEPTH -- initial size of the parser's stacks.  */
 #ifndef        YYINITDEPTH
-# define YYINITDEPTH b4_stack_depth_init
+# define YYINITDEPTH ]b4_stack_depth_init[
 #endif
 
 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
@@ -559,7 +571,7 @@ m4_define([b4_rhs_location],
 #endif
 
 #ifndef YYMAXDEPTH
-# define YYMAXDEPTH b4_stack_depth_max
+# define YYMAXDEPTH ]b4_stack_depth_max[
 #endif
 
 
@@ -620,9 +632,9 @@ m4_define([b4_rhs_location],
 
 
 #if YYDEBUG
-b4_yysymprint_generate([b4_c_function_def])
+]b4_yysymprint_generate([b4_c_function_def])[
 #endif /* YYDEBUG. */
-b4_yydestruct_generate([b4_c_function_def])
+]b4_yydestruct_generate([b4_c_function_def])
 
 
 /* Prevent warnings from -Wmissing-prototypes.  */
@@ -853,9 +865,7 @@ yybackup:
     {
       /* We have to keep this `#if YYDEBUG', since we use variables
         which are defined only if `YYDEBUG' is set.  */
-      YYDPRINTF ((stderr, "Next token is "));
-      YYDSYMPRINT ((stderr, yytoken, &yylval]b4_location_if([, &yyloc])[));
-      YYDPRINTF ((stderr, "\n"));
+      YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
     }
 
   /* If the proper action on seeing token YYTOKEN is to reduce or to
@@ -876,8 +886,7 @@ yybackup:
     YYACCEPT;
 
   /* Shift the lookahead token.  */
-  YYDPRINTF ((stderr, "Shifting token %d (%s), ",
-             yytoken, yytname[yytoken]));
+  YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
 
   /* Discard the token being shifted unless it is eof.  */
   if (yytoken != YYEOF)
@@ -933,13 +942,13 @@ yyreduce:
     {
       int yyi;
 
-      YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
+      YYFPRINTF (stderr, "Reducing by rule %d (line %d), ",
                 yyn - 1, yyrline[yyn]);
 
       /* Print the symbols being reduced, and their result.  */
       for (yyi = yyprhs[yyn]; 0 <= yyrhs[yyi]; yyi++)
        YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
-      YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
+      YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyn]]);
     }
 #endif
   switch (yyn)
@@ -1060,19 +1069,14 @@ yyerrlab1:
          /* Pop the rest of the stack.  */
          while (yyss < yyssp)
            {
-             YYDPRINTF ((stderr, "Error: popping "));
-             YYDSYMPRINT ((stderr,
-                           yystos[*yyssp],
-                           yyvsp]b4_location_if([, yylsp])[));
-             YYDPRINTF ((stderr, "\n"));
+             YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
              yydestruct (yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
              YYPOPSTACK;
            }
          YYABORT;
         }
 
-      YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
-                 yytoken, yytname[yytoken]));
+      YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
       yydestruct (yytoken, &yylval]b4_location_if([, &yylloc])[);
       yytoken = YYEMPTY;
     }
@@ -1100,11 +1104,7 @@ yyerrlab1:
       if (yyssp == yyss)
        YYABORT;
 
-      YYDPRINTF ((stderr, "Error: popping "));
-      YYDSYMPRINT ((stderr,
-                   yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[));
-      YYDPRINTF ((stderr, "\n"));
-
+      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
       yydestruct (yystos[yystate], yyvsp]b4_location_if([, yylsp])[);
       yyvsp--;
       yystate = *--yyssp;
Index: data/glr.c
--- data/glr.c Wed, 13 Nov 2002 07:26:21 +0100 akim
+++ data/glr.c Wed, 13 Nov 2002 08:11:33 +0100 akim
@@ -467,6 +467,17 @@ m4_define([b4_rhs_location],
     yysymprint Args;                           \
 } while (0)
 
+# define YYDSYMPRINTF(Title, Token, Value, Location)           \
+do {                                                           \
+  if (yydebug)                                                 \
+    {                                                          \
+      YYFPRINTF (stderr, "%s ", Title);                                \
+      yysymprint (stderr,                                      \
+                  Token, Value]b4_location_if([, Location])[); \
+      YYFPRINTF (stderr, "\n");                                        \
+    }                                                          \
+} while (0)
+
 /* Nonzero means print parse trace.  It is left uninitialized so that
    multiple parsers can coexist.  */
 int yydebug;
@@ -476,6 +487,7 @@ m4_define([b4_rhs_location],
   /* Avoid empty `if' bodies.  */
 # define YYDPRINTF(Args)   {}
 # define YYDSYMPRINT(Args) {}
+# define YYDSYMPRINTF(Title, Token, Value, Location) {}
 
 #endif /* !YYDEBUG */
 
@@ -1100,12 +1112,12 @@ m4_define([b4_rhs_location],
 yy_reduce_print (size_t yyk, yyRuleNum yyrule)
 {
   int yyi;
-  YYDPRINTF ((stderr, "Reducing stack %d by rule %d (line %d),",
+  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]; 0 <= yyrhs[yyi]; yyi++)
     YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi]));
-  YYFPRINTF (stderr, " -> %s\n", yytokenName (yyr1[yyrule]));
+  YYFPRINTF (stderr, "-> %s\n", yytokenName (yyr1[yyrule]));
 }
 #endif
 
@@ -1526,8 +1538,7 @@ m4_define([b4_rhs_location],
              YYDPRINTF ((stderr, "Reading a token: "));
              yychar = YYLEX;
              *yytokenp = YYTRANSLATE (yychar);
-             YYDPRINTF ((stderr, "Next token is %s\n",
-                         yytokenName (*yytokenp)));
+             YYDSYMPRINTF ("Next token is", *yytokenp, yylvalp, yyllocp);
            }
          yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);
 
@@ -1646,11 +1657,9 @@ m4_define([b4_rhs_location],
            while (yystack->yytops.yystates[0] != NULL)
              {
                yyGLRState *yys = yystack->yytops.yystates[0];
-               YYDPRINTF ((stderr, "Error: popping "));
-               YYDSYMPRINT ((stderr,
+               YYDSYMPRINTF ("Error: popping",
                              yystos[yys->yylrState],
-                             &yys->yysemantics.yysval]b4_location_if([, 
&yys->yyloc])[));
-               YYDPRINTF ((stderr, "\n"));
+                             &yys->yysemantics.yysval, &yys->yyloc);
                yydestruct (yystos[yys->yylrState],
                            &yys->yysemantics.yysval]b4_location_if([, 
&yys->yyloc])[);
                yystack->yytops.yystates[0] = yys->yypred;
@@ -1661,14 +1670,13 @@ m4_define([b4_rhs_location],
          }
        if (*yytokenp != YYEMPTY)
          {
-           YYDPRINTF ((stderr, "Discarding token %s\n",
-                       yytokenName (*yytokenp)));
+           YYDSYMPRINTF ("Error: discarding", *yytokenp, yylvalp, yyllocp);
            yydestruct (*yytokenp, yylvalp]b4_location_if([, yyllocp])[);
          }
        YYDPRINTF ((stderr, "Reading a token: "));
        yychar = YYLEX;
        *yytokenp = YYTRANSLATE (yychar);
-       YYDPRINTF ((stderr, "Next token is %s\n", yytokenName (*yytokenp)));
+       YYDSYMPRINTF ("Next token is", *yytokenp, yylvalp, yyllocp);
        yyj = yypact[yystack->yytops.yystates[0]->yylrState];
        if (yyis_pact_ninf (yyj))
          /* Something's not right; we shouldn't be here.  */
@@ -1708,14 +1716,14 @@ m4_define([b4_rhs_location],
              YYDPRINTF ((stderr, "Shifting error token, "));
              yyglrShift (yystack, 0, yytable[yyj],
                          yys->yyposn, *yylvalp, yyllocp]b4_user_args[);
+             YYDPRINTF ((stderr, "Entering state %d\n",
+                         yystack->yytops.yystates[0]->yylrState));
              break;
            }
        }
-      YYDPRINTF ((stderr, "Error: popping "));
-      YYDSYMPRINT ((stderr,
+      YYDSYMPRINTF ("Error: popping",
                    yystos[yys->yylrState],
-                   &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[));
-      YYDPRINTF ((stderr, "\n"));
+                   &yys->yysemantics.yysval, &yys->yyloc);
       yydestruct (yystos[yys->yylrState],
                  &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
       yystack->yytops.yystates[0] = yys->yypred;
@@ -1808,8 +1816,7 @@ m4_define([b4_rhs_location],
                  YYDPRINTF ((stderr, "Reading a token: "));
                  yychar = YYLEX;
                  yytoken = YYTRANSLATE (yychar);
-                 YYDPRINTF ((stderr, "Next token is %s\n",
-                             yytokenName (yytoken)));
+                  YYDSYMPRINTF ("Next token is", yytoken, yylvalp, yyllocp);
                }
              yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
              if (*yyconflicts != 0)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]