bison-patches
[Top][All Lists]
Advanced

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

Re: [PATCH 3/7] skel: better aliasing of identifiers


From: Théophile Ranquet
Subject: Re: [PATCH 3/7] skel: better aliasing of identifiers
Date: Fri, 11 Jan 2013 17:22:40 +0100

2013/1/11 Akim Demaille <address@hidden>:
>
> Le 11 janv. 2013 à 13:28, Theophile Ranquet <address@hidden> a écrit :
>
>> * data/glr.c, data/yacc.c: Avoid emitting useless defines.
>> * data/glr.cc: Restore prefixes for epilogue.
>
> This is nice, but it deserves a test, and a bit of NEWS.

Thanks. I will add this:

diff --git a/NEWS b/NEWS
index a44e1be..6e499ae 100644
--- a/NEWS
+++ b/NEWS
@@ -198,6 +198,18 @@ GNU Bison NEWS
   used by the scanner, or rejecting invalid combinations from a
   factory invoked by the user actions).

+*** The epilogue is no longer affected by internal #defines
+
+  The glr.c skeleton uses defines such as #define yylval (yystackp->yyval) in
+  generated code.  These weren't properly undefined before the inclusion of
+  the user epilogue, so functions such as the following were butchered by the
+  preprocessor expansion:
+
+    int yylex (yy::parser::semantic_type *yylval);
+
+  This is has been fixed: yylval, ynerrs, yychar, and yylloc are now valid
+  identifiers for user-provided variables.
+
 ** Renamed %define variables

   The following variables have been renamed for consistency.  Backward

diff --git a/tests/c++.at b/tests/c++.at
index 6b10f88..a5d41a9 100644
--- a/tests/c++.at
+++ b/tests/c++.at
@@ -752,3 +752,46 @@ AT_PARSER_CHECK([[./input aaaaR]], [[0]])
 AT_BISON_OPTION_POPDEFS

 AT_CLEANUP
+
+## ------------------------------------ ##
+## C++ GLR parser identifier shadowing  ##
+## ------------------------------------ ##
+
+AT_SETUP([[C++ GLR parser identifier shadowing]])
+
+AT_DATA_GRAMMAR([input.yy], [
+%skeleton "glr.cc"
+
+%union
+{
+  int ival;
+}
+
+%token <ival> ZERO;
+
+%code
+{
+  int yylex (yy::parser::semantic_type *yylval);
+}
+
+%%
+exp: ZERO
+
+%%
+
+int yylex (yy::parser::semantic_type *yylval)
+{
+  return yy::parser::token::ZERO;
+}
+
+void yy::parser::error (std::string const& msg)
+{}
+
+int main()
+{}
+])
+
+AT_BISON_CHECK([[-o input.cc input.yy]])
+AT_COMPILE_CXX([[input]])
+
+AT_CLEANUP

AFAICT, there was never any mention of this behavior in the
documentation. Actually, is was quite the opposite, as
http://www.gnu.org/software/bison/manual/bison.html#C_002b_002b-Scanner-Interface
gave "int yylex (semantic_type* yylval, (...)" as an example, which, I
am now led to believe, was broken on glr.cc skeletons. I have
reproduced it on the released bison 2.7.  Should I report in the NEWS
section that this is bugfix, considering I don't believe it has ever
been reported?

For the record, compiling the parser generated by the test above used
to result in the following errors:


input.tab.cc:1986:24: error: no matching function for call to 'yylex'
              yychar = YYLEX;
                       ^~~~~
input.tab.cc:475:15: note: expanded from macro 'YYLEX'
#define YYLEX yylex (&yylval, &yylloc)
              ^~~~~input.yy:29:39: warning: unused parameter
'yystackp' [-Wunused-parameter]
int yylex (yy::parser::semantic_type *yylval)
                                      ^
input.tab.cc:483:17: note: expanded from macro 'yylval'
#define yylval (yystackp->yyval)

input.yy:21:7: note: candidate function not viable: requires single
argument 'yylval', but 2 arguments were provided
  int yylex (yy::parser::semantic_type *yylval);
      ^
input.tab.cc:2197:18: error: no matching function for call to 'yylex'
        yychar = YYLEX;
                 ^~~~~
input.tab.cc:475:15: note: expanded from macro 'YYLEX'
#define YYLEX yylex (&yylval, &yylloc)
              ^~~~~
input.yy:21:7: note: candidate function not viable: requires single
argument 'yylval', but 2 arguments were provided
  int yylex (yy::parser::semantic_type *yylval);
      ^
input.tab.cc:2353:28: error: no matching function for call to 'yylex'
                  yychar = YYLEX;
                           ^~~~~
input.tab.cc:475:15: note: expanded from macro 'YYLEX'
#define YYLEX yylex (&yylval, &yylloc)
              ^~~~~
input.yy:21:7: note: candidate function not viable: requires single
argument 'yylval', but 2 arguments were provided
  int yylex (yy::parser::semantic_type *yylval);
      ^
input.yy:29:39: error: expected ')'
int yylex (yy::parser::semantic_type *yylval)
                                      ^
input.tab.cc:483:25: note: expanded from macro 'yylval'
#define yylval (yystackp->yyval)
                        ^
input.yy:29:39: note: to match this '('
int yylex (yy::parser::semantic_type *yylval)
                                      ^
input.tab.cc:483:16: note: expanded from macro 'yylval'
#define yylval (yystackp->yyval)
               ^
(Plus 1 warning and 1 error, both unrelated.)



reply via email to

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