Commit Graph

7737 Commits

Author SHA1 Message Date
Akim Demaille
8b424b865e lalr1.cc: YY_ASSERT should use api.prefix
Working on the previous commit I realized that YY_ASSERT was used in
the generated headers, so must follow api.prefix to avoid clashes when
multiple C++ parser with variants are used.

Actually many more macros should obey api.prefix (YY_CPLUSPLUS,
YY_COPY, etc.).  There was no complaint so far, so it's not urgent
enough for 3.7.4, but it should be addressed in 3.8.

* data/skeletons/variant.hh (b4_assert): New.
Use it.
* tests/local.at (AT_YYLEX_RETURN): Fix.
* tests/headers.at: Make sure variant-based C++ parsers are checked
too.
This test did find that YY_ASSERT escaped renaming (before the fix in
this commit).
2020-11-13 06:17:52 +01:00
Akim Demaille
f4431ea115 c++: don't use YY_ASSERT at all if parse.assert is disabled
In some extreme situations (about 800 tokens), we generate a
single-line assertion long enough for Visual C++ to discard the end of
the line, thus falling into parse ends for the missing `);`.  On a
shorter example:

    YY_ASSERT (tok == token::TOK_YYEOF || tok == token::TOK_YYerror || tok == token::TOK_YYUNDEF || tok == token::TOK_ASSIGN || tok == token::TOK_MINUS || tok == token::TOK_PLUS || tok == token::TOK_STAR || tok == token::TOK_SLASH || tok == token::TOK_LPAREN || tok == token::TOK_RPAREN);

Whether NDEBUG is used or not is irrelevant, the parser dies anyway.

Reported by Jot Dot <jotdot@shaw.ca>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00002.html

We should avoid emitting lines so long.

We probably should also use a range-based assertion (with extraneous
parens to pacify fascist compilers):

    YY_ASSERT ((token::TOK_YYEOF <= tok && tok <= token::TOK_YYUNDEF)
               || (token::TOK_ASSIGN <= tok && ...)

But anyway, we should simply not emit this assertion at all when not
asked for.

* data/skeletons/variant.hh: Do not define, nor use, YY_ASSERT when it
is not enabled.
2020-11-13 06:17:52 +01:00
Akim Demaille
fe8c36ddca c++: style: follow the Bison m4 quoting pattern
* data/skeletons/variant.hh: here.
2020-11-13 06:17:24 +01:00
Akim Demaille
d0ea78ca47 todo: more 2020-11-11 16:57:10 +01:00
Akim Demaille
21c147b6e5 yacc.c: provide the Bison version as an integral macro
Suggested by Balazs Scheidler.
https://github.com/akimd/bison/issues/55

* src/muscle-tab.c (muscle_init): Move/rename `b4_version` to/as...
* src/output.c (prepare): `b4_version_string`.
Also define `b4_version`.
* data/skeletons/bison.m4, data/skeletons/c.m4, data/skeletons/d.m4,
* data/skeletons/java.m4: Adjust.
* doc/bison.texi: Document it.
2020-11-11 09:08:57 +01:00
Akim Demaille
d3c575a6c6 regen 2020-11-11 08:47:23 +01:00
Akim Demaille
d8b49e2b73 style: make conversion of version string to int public
* src/parse-gram.y (str_to_version): Rename as/move to...
* src/strversion.h, src/strversion.c (strversion_to_int): these new
files.
2020-11-11 08:47:23 +01:00
Akim Demaille
14c65a35f0 %require: accept version numbers with three parts ("3.7.4")
* src/parse-gram.y (str_to_version): Support three parts.
* data/skeletons/location.cc, data/skeletons/stack.hh:
Adjust.
2020-11-11 08:47:23 +01:00
Todd C. Miller
c47bb87f9f yacc.c: fix #definition of YYEMPTY
When generating a C parser, YYEMPTY is present in enum yytokentype but
there is no corresponding #define like there is for the other values.
There is a special case for YYEMPTY in b4_token_enums but no
corresponding case in b4_token_defines.

* data/skeletons/c.m4 (b4_token_defines): Do define YYEMPTY.
2020-11-11 08:47:21 +01:00
Akim Demaille
98c35e0025 gnulib: update 2020-11-10 07:56:13 +01:00
Akim Demaille
7cc9107053 style: enforce java coding style
* tests/scanner.at: here.
2020-11-10 07:55:36 +01:00
Akim Demaille
25ded505a3 ielr: fix incorrect function call
* src/ielr.c: s/rule_is_accepting/rule_is_initial/.
2020-11-10 07:15:43 +01:00
Akim Demaille
6c0ba6089a ielr: more comments and logs
* src/ielr.c: More comments.
(state_list_print): New.
2020-11-10 07:08:07 +01:00
Akim Demaille
70ee8c77a8 multistart: fix IELR computations
IELR needs to rule out the successors of the kernel items of the
initial state (`$accept: input • $end`).  In the case of multistart,
this condition must be expressed differently: the mere item index does
not suffice.

* src/ielr.c (ielr_item_has_lookahead, ielr_compute_lookaheads): Don't
rely on the item index to check whether is_successor_of_initial_item.
It is certainly more costly than just checking the item index, but (i)
we need to compute the rule anyway, so it's not very much more costly,
and (ii) in ielr_item_has_lookahead, this situation is actually
impossible, so an optimizing compiler reading the assertions should
actually avoid this computation.
2020-11-10 07:08:07 +01:00
Akim Demaille
e9a43ed4ae ielr: make some conditions about items easier to understand
Checking that an item index is > 1 means ruling out `$accept: • input
$end` and `$accept: input • $end`.  But actually only the latter is
possible there, i.e., we're checking whether this item is about a
successor of a (kernel) item of the initial state ($accept: input •
$end).

* src/ielr.c (is_successor_of_initial_item): Use a variable to name
this condition.
2020-11-10 07:08:07 +01:00
Akim Demaille
a38d0b9145 multistart: introduce and use rule_is_initial
* src/gram.h (rule_is_initial): New.
* src/graphviz.c, src/print-xml.c, src/print.c, src/lalr.c: Use it.
Some of these occurrences were incorrect (checking whether this is
rule 0), and not behaving properly in the case of multistart.
2020-11-10 07:08:03 +01:00
Akim Demaille
4b0cd01fb7 style: comment and formatting changes, and fixes
* examples/c/lexcalc/parse.y: Fix option handling.
* src/gram.h: Clarify comments.
* src/ielr.c: Fix indentation.
* src/print.c, src/state.h: More comments.
2020-11-08 13:42:15 +01:00
Akim Demaille
0328cbad64 lalr: add assertions
* src/lalr.c: Remove incorrect comment (subsumed anyway by the
(correct) one in the header.
(set_goto_map): More debug traces.
(map_goto): Add an assertion.
2020-11-08 08:25:20 +01:00
Akim Demaille
3b80811cfa glr2.cc: remove scaffolding for glr.c
* data/skeletons/glr2.cc (b4_glr_cc_setup, b4_glr_cc_cleanup): Remove.
2020-11-07 17:28:25 +01:00
Akim Demaille
10eb13007e d: remove dead comment
* data/skeletons/lalr1.d (reportSyntaxError): here.
2020-11-07 17:12:21 +01:00
Adela Vais
dc15b62a7c d: add the custom error message feature
Parser.Context class returns a const YYLocation, so Lexer's method
yyerror() needs to receive the location as a const parameter.

Internal error reporting flow is changed to be similar to that of
the other skeletons. Before, case YYERRLAB was calling yyerror()
with the result of yysyntax_error() as the string parameter. As the
custom error message lets the user decide if they want to use
yyerror() or not, this flow needed to be changed. Now, case YYERRLAB
calls yyreportSyntaxError(), that builds the error message using
yysyntaxErrorArguments(). Then yyreportSyntaxError() passes the
error message to the user defined syntax_error() in case of a custom
message, or to yyerror() otherwise.

In the tests in tests/calc.at, the order of the tokens needs to be
changed in order of precedence, so that the D program outputs the
expected tokens in the same order as the other parsers.

* data/skeletons/lalr1.d: Add the custom error message feature.
* doc/bison.texi: Document it.
* examples/d/calc/calc.y: Adjust.
* tests/calc.at, tests/local.at: Test it.
2020-11-07 17:03:23 +01:00
Adela Vais
4252134ba4 d: examples: fix coding style
* examples/d/calc/calc.y, examples/d/simple/calc.y: Fix whitespace issues
and remove the @property attribute.
2020-11-07 17:03:04 +01:00
Akim Demaille
5a31cda4c3 style: avoid explicit symbol numbers
This should have been part of commit "symbols: stop dealing with YYEMPTY
as b4_symbol(-2, ...)" (cd40ec9526).
Give names to all the special symbols: "eof", "error" and "undef".

* data/skeletons/bison.m4 (b4_symbol): Let `b4_symbol(eof, ...)` mean
`b4_symbol(0, ...)`, `b4_symbol(error, ...)` mean `b4_symbol(1, ...)`,
and , `b4_symbol(undef, ...)` mean `b4_symbol(2, ...)`..

* data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/glr.cc,
* data/skeletons/glr2.cc, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/yacc.c:
Prefer symbols to numbers.
2020-11-07 16:58:47 +01:00
Adela Vais
34e6e8815a d: fix Context class
All methods are now declared as const. Method getExpectedTokens() has now the
functionality of reporting only the number of expected tokens.

* data/skeletons/lalr1.d: Fix Context class.
2020-11-07 07:55:12 +01:00
Akim Demaille
b5aee13b82 doc: fix typo
Reported by Kaz Kylheku.
https://lists.gnu.org/r/bison-patches/2020-11/msg00019.html

* doc/bison.texi (Versioning): here.
2020-11-07 07:55:12 +01:00
Adela Vais
660f3d4732 d: doc: add D Action Features section
* doc/bison.texi (D Action Features section): New.
2020-11-07 07:55:12 +01:00
Adela Vais
abf5f7f90e d: add yyerrok
In D's case, yyerrok() is a private method of the Parser class.
It can be called directly as `yyerrok()` from the grammar rules section.

* data/skeletons/lalr1.d: Add yyerrok().
* examples/d/calc/calc.y, examples/d/simple/calc.y: Demonstrate yyerrok().
* tests/calc.at: Update D tests to use yyerrok().
2020-11-07 07:14:52 +01:00
Akim Demaille
d49da0101a java: lac: a stronger test for the exploratory stack
* tests/local.at (AT_YYLEX_DEFINE(java)): Fix overquoting issue.
Style changes.
* tests/regression.at (LAC: Exploratory stack): Run for lalr1.java too.
2020-11-06 07:37:15 +01:00
Kaz Kylheku
fa8aca1ed4 doc: document best deployment practices.
* doc/bison.texi (Versioning): New node about practices
regarding dealing with multiple versions of Bison.
2020-11-05 06:04:23 +01:00
Akim Demaille
829ac9caed java: lac: more tests, and some doc
* doc/bison.texi: C++ and Java support LAC.
* tests/input.at (LAC: Errors for %define): Generalize the test, and
apply it to Java.
2020-11-04 07:28:13 +01:00
Akim Demaille
f7a7310433 java: avoid Integer(String), use parseInt
examples/java/calc/Calc.java:1531: warning: [deprecation] Integer(String) in Integer has been deprecated
          yylval = new Integer(st.sval);
                   ^

* examples/java/calc/Calc.y, examples/java/simple/Calc.y,
* tests/calc.at, tests/scanner.at: Use Integer.parseInt.
2020-11-03 08:46:54 +01:00
Akim Demaille
d156910453 java: prefer ArrayList to Vector
Vector is synchronized, which is completely useless in our case (and
not even relevant when concurrency matters).  No seasoned Java
programmer would use it.
Reported by Uxio Prego.

* data/skeletons/lalr1.java: Replace Vector with ArrayList.
Unfortunately its API is not as rich, and lacks lastElement and
setSize.
2020-11-03 08:46:54 +01:00
Akim Demaille
1995d9e2f2 java: lac: check it
* tests/calc.at: Add tests for LAC in pull and push parsers.
Skip LAC: line from the logs.
* tests/local.at (reportSyntaxError): Output the error message in a
single call, to avoid having the error message on stderr be
interrupted by the debug traces of LAC in getExpectedTokens.
2020-11-03 08:46:54 +01:00
Akim Demaille
c223baee63 java: add support for lookahead correction
Shamelessly stolen from Adrian Vogelsgesang's implementation in
lalr1.cc.

* data/skeletons/lalr1.java (yycdebugNnl, yyLacCheck, yyLacEstablish)
(yyLacDiscard, yylacStack, yylacEstablished): New.
(Context): Use it.
* examples/java/calc/Calc.y: Enable LAC.
2020-11-03 08:46:54 +01:00
Akim Demaille
787052f074 style: java: more style fixes
* data/skeletons/lalr1.java, tests/java.at: Avoid space before paren.
And use braces as is customary in the Java.
2020-11-03 08:46:54 +01:00
Akim Demaille
042b916c0e style: comment changes in the skeletons
* data/skeletons/lalr1.cc: Prepare for Java's LAC.
* data/skeletons/lalr1.java: Style fixes.
2020-11-03 08:46:54 +01:00
Akim Demaille
57848d9262 doc: fix incorrect section title
Reported by Gaurav Singh <gaurav.singh199709@yahoo.com>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00000.html

* doc/bison.texi (Rpcalc Expr): Rename as...
(Rpcalc Exp): this, as the nterm is named 'exp'.
2020-11-01 09:15:24 +01:00
Akim Demaille
bd6b046ce7 doc: fix incorrect section title
Reported by Gaurav Singh <gaurav.singh199709@yahoo.com>.
https://lists.gnu.org/r/bug-bison/2020-11/msg00000.html

* doc/bison.texi (Rpcalc Expr): Rename as...
(Rpcalc Exp): this, as the nterm is named 'exp'.
2020-11-01 09:12:27 +01:00
Nick Gasson
7c6e7bd300 doc: minor grammar fixes in counterexamples section
* doc/bison.texi: Minor fixes in counterexamples section.
2020-10-28 06:36:43 +01:00
Nick Gasson
8d7cd5e84d doc: minor grammar fixes in counterexamples section
* doc/bison.texi: Minor fixes in counterexamples section.
2020-10-28 06:33:40 +01:00
Adela Vais
0cd16ae964 d: create the Parser.Context class
This will provide the user an interface for creating custom error messages.

* data/skeletons/lalr1.d: Add the Context class.
* doc/bison.texi: Document it.
2020-10-27 07:39:00 +01:00
Akim Demaille
98691fcd2d Merge branch 'maint'
* upstream/maint:
  doc: fix typo
  maint: post-release administrivia
  version 3.7.3
  build: don't link bison against libreadline
  gnulib: update
  glr.cc: fix: use symbol_name
  build: fix a concurrent build issue in examples
2020-10-14 21:12:45 +02:00
Akim Demaille
3cba59dd7f doc: fix typo
* README: here.
2020-10-14 21:12:04 +02:00
Akim Demaille
a15879c623 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-10-13 07:23:28 +02:00
Akim Demaille
5d501ee728 version 3.7.3
* NEWS: Record release date.
v3.7.3
2020-10-13 07:01:24 +02:00
Akim Demaille
bc5e4541da build: don't link bison against libreadline
Reported by Paul Smith <psmith@gnu.org>.
https://lists.gnu.org/r/bug-bison/2020-10/msg00001.html

* src/local.mk (src_bison_LDADD): here.
2020-10-13 06:57:33 +02:00
Akim Demaille
567d1eaa19 gnulib: update 2020-10-13 06:46:06 +02:00
Akim Demaille
2347e959d4 doc: D comes before Java in alphabetical order
* doc/bison.texi: Keep languages sorted.
2020-10-07 06:29:24 +02:00
Akim Demaille
36143b5ecc report: put the dot after %empty in items
When printing items, it is clearer to put the dot after %emtpy rather
than before:

     0 $accept: . unit "end of file"
     1 unit: . assignments exp
-    2 assignments: . %empty
+    2 assignments: %empty .
     3            | . assignments assignment

Also, use the Unicode characters if they are supported.

* src/gram.c (item_print): Put the dot after %emtpy.
* tests/conflicts.at, tests/reduce.at, tests/report.at: Adjust.
2020-10-07 06:28:52 +02:00
Adela Vais
7cd195b30a d: change api.token.raw default value to true
Generate consecutive values for enum TokenKind, as D's yylex()
returns TokenKind and collisions can't happen.

* data/skeletons/d.m4: Change default value.
* tests/scanner.at, tests/d.at: Check it.
2020-10-03 17:17:32 +02:00