]> git.saurik.com Git - bison.git/commitdiff
yacc: fix YYBACKUP.
authorAkim Demaille <demaille@gostai.com>
Wed, 25 Jan 2012 15:57:58 +0000 (16:57 +0100)
committerAkim Demaille <demaille@gostai.com>
Thu, 26 Jan 2012 20:18:24 +0000 (21:18 +0100)
Reported by David Kastrup:
https://lists.gnu.org/archive/html/bug-bison/2011-10/msg00002.html.

* data/yacc.c (YYBACKUP): Accept rhs size.
Restore the proper state value.
* TODO (YYBACKUP): Make it...
* tests/actions.at: a new test case.
* NEWS, THANKS: Update.

NEWS
THANKS
TODO
data/yacc.c
tests/actions.at

diff --git a/NEWS b/NEWS
index 5c2783f93a04833175c6892c040debf726ab9be9..a9922c0994f471eba079e6f0c496ca8f14bfe146 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -66,6 +66,8 @@ Bison News
 
 ** Minor improvements have been made to the manual.
 
 
 ** Minor improvements have been made to the manual.
 
+** YYBACKUP works as expected.
+
 * Changes in version 2.5 (2011-05-14):
 
 ** Grammar symbol names can now contain non-initial dashes:
 * Changes in version 2.5 (2011-05-14):
 
 ** Grammar symbol names can now contain non-initial dashes:
diff --git a/THANKS b/THANKS
index 1ec0fb37f1c7a32c46d7ffaf43f92587aba4900a..d25e6f700260d9a22c0d834e6893e5ebd0a0fc14 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -29,6 +29,7 @@ Csaba Raduly              csaba_22@yahoo.co.uk
 Dagobert Michelsen        dam@baltic-online.de
 Daniel Hagerty            hag@gnu.org
 David J. MacKenzie        djm@gnu.org
 Dagobert Michelsen        dam@baltic-online.de
 Daniel Hagerty            hag@gnu.org
 David J. MacKenzie        djm@gnu.org
+David Kastrup             dak@gnu.org
 Derek M. Jones            derek@knosof.co.uk
 Di-an Jan                 dianj@freeshell.org
 Dick Streefland           dick.streefland@altium.nl
 Derek M. Jones            derek@knosof.co.uk
 Di-an Jan                 dianj@freeshell.org
 Dick Streefland           dick.streefland@altium.nl
diff --git a/TODO b/TODO
index 404317f96be6c8ea1ccc0f99b40a40714905dade..588bf468af20800d05299a22ae065165746bdaae 100644 (file)
--- a/TODO
+++ b/TODO
@@ -118,50 +118,6 @@ so both 256 and 257 are "mysterious".
 ** YYFAIL
 It is seems to be *really* obsolete now, shall we remove it?
 
 ** YYFAIL
 It is seems to be *really* obsolete now, shall we remove it?
 
-** YYBACKUP
-There is no test about it, no examples in the doc, and I'm not sure
-what it should look like.  For instance what follows crashes.
-
-  %error-verbose
-  %debug
-  %pure-parser
-  %code {
-  # include <stdio.h>
-  # include <stdlib.h>
-  # include <assert.h>
-
-    static void yyerror (const char *msg);
-    static int yylex (YYSTYPE *yylval);
-  }
-  %%
-  exp:
-    'a'   { printf ("a: %d\n", $1); }
-  | 'b'   { YYBACKUP('a', 123); }
-  ;
-  %%
-  static int
-  yylex (YYSTYPE *yylval)
-  {
-    static char const input[] = "b";
-    static size_t toknum;
-    assert (toknum < sizeof input);
-    *yylval = (toknum + 1) * 10;
-    return input[toknum++];
-  }
-
-  static void
-  yyerror (const char *msg)
-  {
-    fprintf (stderr, "%s\n", msg);
-  }
-
-  int
-  main (void)
-  {
-    yydebug = !!getenv("YYDEBUG");
-    return yyparse ();
-  }
-
 ** yychar == yyempty_
 The code in yyerrlab reads:
 
 ** yychar == yyempty_
 The code in yyerrlab reads:
 
index 1866a66acef45b0da5ca52568a3f913f9866233a..b6137c2b91079db860af187bdb4d8d10712b6f22 100644 (file)
@@ -646,11 +646,12 @@ static const ]b4_int_type_for([b4_toknum])[ yytoknum[] =
 
 #define YYBACKUP(Token, Value)                                  \
 do                                                              \
 
 #define YYBACKUP(Token, Value)                                  \
 do                                                              \
-  if (yychar == YYEMPTY && yylen == 1)                          \
+  if (yychar == YYEMPTY)                                        \
     {                                                           \
       yychar = (Token);                                         \
       yylval = (Value);                                         \
     {                                                           \
       yychar = (Token);                                         \
       yylval = (Value);                                         \
-      YYPOPSTACK (1);                                           \]b4_lac_if([[
+      YYPOPSTACK (yylen);                                       \
+      yystate = *yyssp;                                         \]b4_lac_if([[
       YY_LAC_DISCARD ("YYBACKUP");                              \]])[
       goto yybackup;                                            \
     }                                                           \
       YY_LAC_DISCARD ("YYBACKUP");                              \]])[
       goto yybackup;                                            \
     }                                                           \
index 4e2e61070d62ea19c5d356f75dfed74fcc5f7c26..4199a3efbf42179e98e4640087696e0a10a3a8a3 100644 (file)
@@ -1525,3 +1525,68 @@ AT_PARSER_CHECK([[./input]], [[0]], [],
 ]])
 
 AT_CLEANUP
 ]])
 
 AT_CLEANUP
+
+## ---------- ##
+## YYBACKUP.  ##
+## ---------- ##
+
+AT_SETUP([[YYBACKUP]])
+
+AT_DATA_GRAMMAR([input.y],
+[[
+%error-verbose
+%debug
+%pure-parser
+%code {
+# include <stdio.h>
+# include <stdlib.h>
+# include <assert.h>
+
+  static void yyerror (const char *msg);
+  static int yylex (YYSTYPE *yylval);
+}
+%%
+input:
+  exp exp {}
+;
+
+exp:
+  'a'     { printf ("a: %d\n", $1); }
+| 'b'     { YYBACKUP('a', 123); }
+| 'c' 'd' { YYBACKUP('a', 456); }
+;
+
+%%
+static int
+yylex (YYSTYPE *yylval)
+{
+  static char const input[] = "bcd";
+  static size_t toknum;
+  assert (toknum < sizeof input);
+  *yylval = (toknum + 1) * 10;
+  return input[toknum++];
+}
+
+static void
+yyerror (const char *msg)
+{
+  fprintf (stderr, "%s\n", msg);
+}
+
+int
+main (void)
+{
+  yydebug = !!getenv("YYDEBUG");
+  return yyparse ();
+}
+]])
+
+AT_BISON_CHECK([[-o input.c input.y]])
+AT_COMPILE([[input]])
+AT_PARSER_CHECK([[./input]], [[0]],
+[[a: 123
+a: 456
+a: 789
+]])
+
+AT_CLEANUP