[PATCH 0/3] {maint} trailing \n in %parse-param

View: New views
4 Messages — Rating Filter:   Alert me  

[PATCH 0/3] {maint} trailing \n in %parse-param

by Akim Demaille :: Rate this Message:

| View Threaded | Show Only this Message

I once fell on this issue: trailing \n in %parse-param generate
invalid C++ code (because we append a suffix to this argument it is
important the skip the trailing spaces).

Akim Demaille (3):
  tests: simplify
  c++: trailing end-of-lines in %parse-param
  regen

 NEWS                |   4 ++
 src/parse-gram.c    |  14 +++---
 src/parse-gram.h    |   2 +-
 src/parse-gram.y    |  10 +++--
 tests/regression.at | 124 +++++++++++++++++++++++++++++++++++++++++++---------
 5 files changed, 122 insertions(+), 32 deletions(-)

--
1.7.11.3



[PATCH 1/3] tests: simplify

by Akim Demaille :: Rate this Message:

| View Threaded | Show Only this Message

* tests/regression.at: Remove useless -o arguments passed to bison.
Remove useless compilations: AT_FULL_COMPILE includes the compilation
by bison.
---
 tests/regression.at | 40 +++++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/tests/regression.at b/tests/regression.at
index c2795f6..ad880c7 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -40,7 +40,7 @@ program: 'x';
 ]])
 AT_BISON_OPTION_POPDEFS
 
-AT_BISON_CHECK([-o input.c input.y])
+AT_BISON_CHECK([input.y])
 AT_COMPILE([input.o])
 AT_COMPILE([input.o], [-DYYDEBUG -c input.c])
 
@@ -70,7 +70,7 @@ program: { $$ = ""; };
 ]])
 AT_BISON_OPTION_POPDEFS
 
-AT_BISON_CHECK([-o input.c input.y])
+AT_BISON_CHECK([input.y])
 AT_COMPILE([input.o])
 
 AT_CLEANUP
@@ -155,7 +155,7 @@ exp: MY_TOKEN;
 ]])
 AT_BISON_OPTION_POPDEFS
 
-AT_BISON_CHECK([-o input.c input.y])
+AT_BISON_CHECK([input.y])
 AT_COMPILE([input.o])
 
 AT_CLEANUP
@@ -179,7 +179,7 @@ exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
 ]])
 AT_BISON_OPTION_POPDEFS
 
-AT_BISON_CHECK([-v -o input.c input.y])
+AT_BISON_CHECK([-v input.y])
 
 AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
 
@@ -208,7 +208,7 @@ exp: '(' exp ')' | NUM ;
 ]])
 AT_BISON_OPTION_POPDEFS
 
-AT_BISON_CHECK([-v -o input.c input.y], 0, [],
+AT_BISON_CHECK([-v input.y], 0, [],
 [[input.y:6.8-14: warning: symbol "<=" used more than once as a literal string
 ]])
 
@@ -255,7 +255,7 @@ expr:
 ]])
 AT_BISON_OPTION_POPDEFS
 
-AT_BISON_CHECK([-o input.c -v input.y])
+AT_BISON_CHECK([-v input.y])
 
 # Check the contents of the report.
 AT_CHECK([cat input.output], [],
@@ -377,7 +377,7 @@ exp: ;
 %%
 ]])
 
-AT_BISON_CHECK([-v -o input.c input.y])
+AT_BISON_CHECK([-v input.y])
 
 AT_CLEANUP
 
@@ -477,7 +477,7 @@ AT_BISON_OPTION_POPDEFS
 # unnecessarily escaped here even though it would need to be if encoded in a
 # C-string literal.  Also notice that unnecessary escaping, such as "\?", from
 # the user specification is eliminated.
-AT_BISON_CHECK([-o input.c input.y], [[0]], [[]],
+AT_BISON_CHECK([input.y], [[0]], [[]],
 [[input.y:22.8-14: warning: symbol SPECIAL redeclared
 input.y:22.8-63: warning: symbol "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!" used more than once as a literal string
 ]])
@@ -518,7 +518,7 @@ exp:
 
 AT_BISON_OPTION_POPDEFS
 
-AT_BISON_CHECK([-o input.c input.y])
+AT_BISON_CHECK([input.y])
 AT_COMPILE([input.o])
 AT_CLEANUP
 
@@ -723,7 +723,7 @@ else: "else" statement;
 %%
 ]])
 
-AT_BISON_CHECK([-v -o input.c input.y])
+AT_BISON_CHECK([-v input.y])
 
 # Check only the tables.
 [sed -n 's/  *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
@@ -917,7 +917,6 @@ m4_define([AT_CHECK_DANCER],
 [AT_SETUP([Dancer $1])
 AT_BISON_OPTION_PUSHDEFS([$1])
 _AT_DATA_DANCER_Y([$1])
-AT_BISON_CHECK([-o dancer.c dancer.y])
 AT_FULL_COMPILE([dancer])
 AT_PARSER_CHECK([./dancer], 1, [],
 [syntax error, unexpected ':'
@@ -1002,7 +1001,6 @@ m4_define([AT_CHECK_EXPECT2],
 [AT_SETUP([Expecting two tokens $1])
 AT_BISON_OPTION_PUSHDEFS([$1])
 _AT_DATA_EXPECT2_Y([$1])
-AT_BISON_CHECK([-o expect2.c expect2.y])
 AT_FULL_COMPILE([expect2])
 AT_PARSER_CHECK([./expect2], 1, [],
 [syntax error, unexpected '+', expecting A or B
@@ -1060,7 +1058,7 @@ main (void)
 ]])
 AT_BISON_OPTION_POPDEFS
 
-AT_BISON_CHECK([-t -o input.c input.y])
+AT_BISON_CHECK([-t input.y])
 AT_COMPILE([input])
 AT_PARSER_CHECK([./input], 0,
 [[Bison would once convert this action to a midrule because of the subsequent braced code.
@@ -1101,7 +1099,7 @@ start: 'a' "A" 'b';
 %token 'a' "A";
 ]])
 
-AT_BISON_CHECK([-t -o input.c input.y])
+AT_BISON_CHECK([-t input.y])
 
 AT_CLEANUP
 
@@ -1192,7 +1190,7 @@ main (void)
 ]])
 AT_BISON_OPTION_POPDEFS
 
-AT_BISON_CHECK([[-o input.c input.y]], [[0]],,
+AT_BISON_CHECK([[input.y]], [[0]],,
 [[input.y:23.5-19: warning: rule useless in parser due to conflicts: start: start
 input.y:27.5-19: warning: rule useless in parser due to conflicts: sr_conflict: TK2 "tok alias"
 ]])
@@ -1215,10 +1213,10 @@ AT_SETUP([[parse-gram.y: LALR = IELR]])
 # Avoid differences in synclines by telling bison that the output files
 # have the same name.
 [cp $abs_top_srcdir/src/parse-gram.y input.y]
-AT_BISON_CHECK([[-o input.c -Dlr.type=lalr input.y]])
+AT_BISON_CHECK([[-Dlr.type=lalr input.y]])
 [mv input.c lalr.c]
 AT_CAPTURE_FILE([lalr.c])
-AT_BISON_CHECK([[-o input.c -Dlr.type=ielr input.y]])
+AT_BISON_CHECK([[-Dlr.type=ielr input.y]])
 [mv input.c ielr.c]
 AT_CAPTURE_FILE([ielr.c])
 AT_CHECK([[diff lalr.c ielr.c]], [[0]])
@@ -1287,7 +1285,7 @@ main (void)
 ]])
 AT_BISON_OPTION_POPDEFS
 
-AT_BISON_CHECK([[-o input.c input.y]])
+AT_BISON_CHECK([[input.y]])
 AT_COMPILE([[input]])
 AT_PARSER_CHECK([[./input]], [[1]], [],
 [[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B
@@ -1397,7 +1395,7 @@ main (void)
 }
 ]])
 
-AT_BISON_CHECK([[-o input.c input.y]])
+AT_BISON_CHECK([[input.y]])
 
 # gcc warns about tautologies and fallacies involving comparisons for
 # unsigned char.  However, it doesn't produce these same warnings for
@@ -1469,7 +1467,7 @@ main (void)
 
 AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \
                  -Dparse.lac.memory-trace=full \
-                 -t -o input.c input.y]], [[0]], [],
+                 -t input.y]], [[0]], [],
 [[input.y: conflicts: 21 shift/reduce
 ]])
 AT_COMPILE([[input]])
@@ -1545,7 +1543,7 @@ main (void)
 ]])
 
 AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \
-                 -t -o input.c input.y]], [[0]], [],
+                 -t input.y]], [[0]], [],
 [[input.y: conflicts: 8 shift/reduce
 ]])
 AT_COMPILE([[input]])
--
1.7.11.3



[PATCH 2/3] c++: trailing end-of-lines in %parse-param

by Akim Demaille :: Rate this Message:

| View Threaded | Show Only this Message

* src/parse-gram.y (add_param): No only skip ' ' and '\t', skip all
leading and trailing spaces.
* tests/regression.at (Lex and parse params): Check it.
* NEWS: Document it.
---
 NEWS                |  4 +++
 src/parse-gram.y    | 10 ++++---
 tests/regression.at | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index f940d8e..316abb0 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ GNU Bison NEWS
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Spaces in %lex- and %parse-param (lalr1.cc, glr.cc)
+
+  Trailing end-of-lines in %parse-param or %lex-param would result in
+  invalid C++.  This is fixed.
 
 * Noteworthy changes in release 2.6.1 (2012-07-30) [stable]
 
diff --git a/src/parse-gram.y b/src/parse-gram.y
index e6a27c5..02af75e 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -734,11 +734,13 @@ add_param (char const *type, char *decl, location loc)
 
   /* Strip the surrounding '{' and '}', and any blanks just inside
      the braces.  */
-  while (*--p == ' ' || *p == '\t')
-    continue;
+  --p;
+  while (isspace ((unsigned char) *p))
+    --p;
   p[1] = '\0';
-  while (*++decl == ' ' || *decl == '\t')
-    continue;
+  ++decl;
+  while (isspace ((unsigned char) *decl))
+    ++decl;
 
   if (! name_start)
     complain_at (loc, _("missing identifier in parameter declaration"));
diff --git a/tests/regression.at b/tests/regression.at
index ad880c7..7211618 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -1583,3 +1583,87 @@ Stack now 0
 m4_popdef([AT_LAC_CHECK])
 
 AT_CLEANUP
+
+
+## ---------------------- ##
+## Lex and parse params.  ##
+## ---------------------- ##
+
+# AT_TEST(SKELETON)
+# -----------------
+# Check that the identifier of the params is properly fetched
+# even when there are trailing blanks.
+
+m4_pushdef([AT_TEST],
+[AT_SETUP([[Lex and parse params: $1]])
+
+AT_BISON_OPTION_PUSHDEFS([%locations %skeleton $1])
+
+## FIXME: Improve parsing of parse-param and use the generated
+## yyerror.
+AT_DATA_GRAMMAR([input.y],
+[[%defines
+%locations
+%skeleton $1
+%union { int ival; }
+%parse-param { int x }
+// Spaces, tabs, and new lines.
+%parse-param { @&t@
+ int y @&t@
+         @&t@
+ @&t@
+}
+
+%{
+#include <stdio.h>
+#include <stdlib.h>
+
+]AT_SKEL_CC_IF([], [[
+static
+void
+yyerror (int x, int y, const char *msg)
+{
+  fprintf (stderr, "x: %d, y: %d, %s\n", x, y, msg);
+}]])[
+
+  ]AT_YYLEX_DECLARE[
+%}
+
+%%
+exp: 'a' { fprintf (stdout, "x: %d, y: %d\n", x, y); };
+%%
+]AT_YYLEX_DEFINE(["a"])[
+
+]AT_SKEL_CC_IF(
+[AT_YYERROR_DEFINE
+
+int
+yyparse (int x, int y)
+{
+  yy::parser parser(x, y);
+  return parser.parse ();
+}
+])[
+
+int
+main (void)
+{
+  return !!yyparse(1, 2);
+}
+]])
+
+AT_FULL_COMPILE([input])
+AT_CHECK([./input], 0, [[x: 1, y: 2
+]])
+AT_BISON_OPTION_POPDEFS
+
+AT_CLEANUP
+])
+
+## FIXME: test Java, and iterate over skeletons.
+AT_TEST("yacc.c")
+AT_TEST("glr.c")
+AT_TEST("lalr1.cc")
+AT_TEST("glr.cc")
+
+m4_popdef([AT_TEST])
--
1.7.11.3



[PATCH 3/3] regen

by Akim Demaille :: Rate this Message:

| View Threaded | Show Only this Message

---
 src/parse-gram.c | 14 ++++++++------
 src/parse-gram.h |  2 +-
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/parse-gram.c b/src/parse-gram.c
index 3d0e0b8..207938d 100644
--- a/src/parse-gram.c
+++ b/src/parse-gram.c
@@ -1,4 +1,4 @@
-/* A Bison parser, made by GNU Bison 2.6.29-cd73-dirty.  */
+/* A Bison parser, made by GNU Bison 2.6.1.6-b045.  */
 
 /* Bison implementation for Yacc-like parsers in C
   
@@ -44,7 +44,7 @@
 #define YYBISON 1
 
 /* Bison version.  */
-#define YYBISON_VERSION "2.6.29-cd73-dirty"
+#define YYBISON_VERSION "2.6.1.6-b045"
 
 /* Skeleton name.  */
 #define YYSKELETON_NAME "yacc.c"
@@ -3169,11 +3169,13 @@ add_param (char const *type, char *decl, location loc)
 
   /* Strip the surrounding '{' and '}', and any blanks just inside
      the braces.  */
-  while (*--p == ' ' || *p == '\t')
-    continue;
+  --p;
+  while (isspace ((unsigned char) *p))
+    --p;
   p[1] = '\0';
-  while (*++decl == ' ' || *decl == '\t')
-    continue;
+  ++decl;
+  while (isspace ((unsigned char) *decl))
+    ++decl;
 
   if (! name_start)
     complain_at (loc, _("missing identifier in parameter declaration"));
diff --git a/src/parse-gram.h b/src/parse-gram.h
index 10de0a6..50cfe23 100644
--- a/src/parse-gram.h
+++ b/src/parse-gram.h
@@ -1,4 +1,4 @@
-/* A Bison parser, made by GNU Bison 2.6.29-cd73-dirty.  */
+/* A Bison parser, made by GNU Bison 2.6.1.6-b045.  */
 
 /* Bison interface for Yacc-like parsers in C
   
--
1.7.11.3