bison-patches
[Top][All Lists]
Advanced

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

Re: push parser


From: Joel E. Denny
Subject: Re: push parser
Date: Wed, 20 Dec 2006 02:49:47 -0500 (EST)

I committed this.  Maybe yynerrs isn't very useful, but I don't see any 
advantage to disabling it for push mode.  I'd rather keep it consistent 
with pull mode.

Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1635
diff -p -u -r1.1635 ChangeLog
--- ChangeLog   20 Dec 2006 06:46:20 -0000      1.1635
+++ ChangeLog   20 Dec 2006 07:35:43 -0000
@@ -1,5 +1,19 @@
 2006-12-20  Joel E. Denny  <address@hidden>
 
+       Remove some unnecessary differences between the pull parser code and
+       the push parser code.  This patch enables yynerrs in push mode.
+       * data/push.c: Reformat M4 a little.
+       (b4_yyerror_range): Remove and convert all uses to just yyerror_range.
+       (b4_declare_scanner_communication_variables): Don't omit yynerrs just
+       because push mode is on.  Instead, if pure mode is on, move yynerrs
+       to...
+       (b4_declare_parser_state_variables): ... here.
+       (yynerrs, yyerror_range): For push mode, #define each NAME in this list
+       to yyps->NAME so it can be used in yypush_parse.
+       (yypush_parse): Don't omit uses of yynerrs in push mode.
+
+2006-12-20  Joel E. Denny  <address@hidden>
+
        Fix bug such that the first pushed token's value and location are
        sometimes overwritten (sometimes by %initial-action) before being used.
        * data/push.c (yypush_parse): Rename arguments yynchar, yynlval, and
Index: data/push.c
===================================================================
RCS file: /sources/bison/bison/data/push.c,v
retrieving revision 1.22
diff -p -u -r1.22 push.c
--- data/push.c 20 Dec 2006 06:46:20 -0000      1.22
+++ data/push.c 20 Dec 2006 07:35:44 -0000
@@ -994,22 +994,22 @@ int yychar;
 
 /* The semantic value of the lookahead symbol.  */
 YYSTYPE yylval;
-
-/* Number of syntax errors so far.  */
-]b4_push_if([],[
-int yynerrs;])b4_locations_if([[
+]b4_locations_if([[
 /* Location data for the lookahead symbol.  */
-YYLTYPE yylloc;]])
-])
-
-m4_define([b4_yyerror_range],b4_push_if([yyps->yyerror_range],[yyerror_range]))
+YYLTYPE yylloc;
+]])b4_pure_if([], [[
+/* Number of syntax errors so far.  */
+int yynerrs;
+]])])
 
 # b4_declare_parser_state_variables
 # ---------------------------------
 # Declare all the variables that are needed to maintain the parser state
 # between calls to yypush_parse.
 m4_define([b4_declare_parser_state_variables],
-[[
+[b4_pure_if([[    /* Number of syntax errors so far.  */
+    int yynerrs;
+]])[
     int yystate;
     int yyn;
     int yyresult;
@@ -1040,13 +1040,16 @@ m4_define([b4_declare_parser_state_varia
     YYLTYPE yylsa[YYINITDEPTH];
     YYLTYPE *yyls;
     YYLTYPE *yylsp;
+
     /* The locations where the error started and ended.  */
-    YYLTYPE yyerror_range[2];]])[
+    YYLTYPE yyerror_range[2];
+]])[
     YYSIZE_T yystacksize;
+
     /* The variables used to return semantic value and location from the
        action routines.  */
     YYSTYPE yyval;
-]b4_locations_if([[  YYLTYPE yyloc;
+]b4_locations_if([[    YYLTYPE yyloc;
 ]])])
 
 m4_divert_pop([KILL])dnl# ====================== End of M4 code.
@@ -1077,7 +1080,8 @@ b4_push_if(
   free (yyps);
 }
 
-#define yystate yyps->yystate
+]b4_pure_if([[#define ]b4_prefix[nerrs yyps->]b4_prefix[nerrs
+]])[#define yystate yyps->yystate
 #define yyn yyps->yyn
 #define yyresult yyps->yyresult
 #define yyerrstatus yyps->yyerrstatus
@@ -1091,6 +1095,7 @@ b4_push_if(
 ]b4_locations_if([[#define yylsa yyps->yylsa
 #define yyls yyps->yyls
 #define yylsp yyps->yylsp
+#define yyerror_range yyps->yyerror_range
 ]])[#define yystacksize yyps->yystacksize
 #define yyval yyps->yyval
 ]b4_locations_if([[#define yyloc yyps->yyloc
@@ -1142,7 +1147,7 @@ b4_c_function_def([yyparse], [int], b4_p
 
   yystate = 0;
   yyerrstatus = 0;
-]b4_push_if([], [[  yynerrs = 0;]])[
+  yynerrs = 0;
   yychar = YYEMPTY; /* Cause a token to be read.  */
 
   /* Initialize stack pointers.
@@ -1401,7 +1406,7 @@ yyerrlab:
   /* If not already recovering from an error, report this error.  */
   if (!yyerrstatus)
     {
-]b4_push_if([],[ ++yynerrs;])[
+      ++yynerrs;
 #if ! YYERROR_VERBOSE
       yyerror (]b4_yyerror_args[YY_("syntax error"));
 #else
@@ -1439,7 +1444,7 @@ yyerrlab:
 #endif
     }
 
-]b4_locations_if([[  ]b4_yyerror_range[[0] = yylloc;]])[
+]b4_locations_if([[  yyerror_range[0] = yylloc;]])[
 
   if (yyerrstatus == 3)
     {
@@ -1476,7 +1481,7 @@ yyerrorlab:
   if (/*CONSTCOND*/ 0)
      goto yyerrorlab;
 
-]b4_locations_if([[  ]b4_yyerror_range[[0] = yylsp[1-yylen];
+]b4_locations_if([[  yyerror_range[0] = yylsp[1-yylen];
 ]])[  /* Do not reclaim the symbols of the rule which action triggered
      this YYERROR.  */
   YYPOPSTACK (yylen);
@@ -1510,7 +1515,7 @@ yyerrlab1:
       if (yyssp == yyss)
        YYABORT;
 
-]b4_locations_if([[      ]b4_yyerror_range[[0] = *yylsp;]])[
+]b4_locations_if([[      yyerror_range[0] = *yylsp;]])[
       yydestruct ("Error: popping",
                  yystos[yystate], yyvsp]b4_locations_if([, 
yylsp])[]b4_user_args[);
       YYPOPSTACK (1);
@@ -1520,10 +1525,10 @@ yyerrlab1:
 
   *++yyvsp = yylval;
 ]b4_locations_if([[
-  ]b4_yyerror_range[[1] = yylloc;
+  yyerror_range[1] = yylloc;
   /* Using YYLLOC is tempting, but would change the location of
      the lookahead.  YYLOC is available though.  */
-  YYLLOC_DEFAULT (yyloc, (]b4_yyerror_range[- 1), 2);
+  YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
   *++yylsp = yyloc;]])[
 
   /* Shift the error token.  */
@@ -1609,8 +1614,7 @@ b4_token_enums_defines(b4_tokens)
 # define YYSTYPE_IS_DECLARED 1
 #endif
 
-]b4_pure_if([],
-[extern YYSTYPE b4_prefix[]lval;])
+]b4_pure_if([], [[extern YYSTYPE ]b4_prefix[lval;]])
 
 b4_locations_if(
 [#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED
@@ -1626,8 +1630,7 @@ typedef struct YYLTYPE
 # define YYLTYPE_IS_TRIVIAL 1
 #endif
 
-]b4_pure_if([],
-          [extern YYLTYPE b4_prefix[]lloc;])
+]b4_pure_if([], [[extern YYLTYPE ]b4_prefix[lloc;]])
 )dnl b4_locations_if
 
 b4_push_if([[#ifndef YYPUSH_DECLS




reply via email to

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