Commit Graph

7563 Commits

Author SHA1 Message Date
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
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
Akim Demaille
e66673aa64 m4: have b4_percent_define_if_define apply default values lazily
Currently `b4_percent_define_ifdef([foo])` assigns a default value to
`foo` when invoked.  As a consequence, skeletons such as lalr1.d
cannot specify their specific default values: `foo` was defined in
bison.m4.

Instead, provide `foo` with a default value when `b4_foo_if` is
invoked.

I could not measure a runtime difference between both cases.

* data/skeletons/bison.m4 (_b4_percent_define_define): New.
Helps getting rid of spurious indentation that resulted in spurious
white space in the output.
(b4_percent_define_if_define): Move the definition to...
(_b4_percent_define_if_define): when the defined macros is called.
2020-10-03 09:17:53 +02:00
Adela Vais
3829bd6262 d: don't trigger GC in void toString
* data/skeletons/d.m4 (b4_declare_symbol_enum): Here.
2020-10-02 06:48:11 +02:00
Adela Vais
72360b51a5 d: document support
* doc/bison.texi: Various fixes.
(D Parsers): New section.
2020-10-02 06:46:32 +02:00
Adela Vais
4bbda69f1e d: remove the default prefix for SymbolKind's enum elements
This is not needed in D, since the kinds are "scoped".

* data/skeletons/d.m4: Remove the default prefix.
* doc/bison.text: Document it.
2020-10-02 06:46:32 +02:00
Adela Vais
4855b98554 d: remove the @property attribute from interface Lexer
D best practices is to not use it.

* data/skeletons/lalr1.d: Remove attribute.
2020-10-02 06:35:17 +02:00
Akim Demaille
cd40ec9526 symbols: stop dealing with YYEMPTY as b4_symbol(-2, ...)
* data/skeletons/bison.m4 (b4_symbol): Redirect `b4_symbol(empty,
...)` to `b4_symbol(-2, ...)`.
Change all uses of the latter to the former.
2020-09-29 06:49:31 +02:00
Akim Demaille
a7daa63cb7 tests: remove useless prefix for EOF in D
* tests/calc.at (CALC_EOF): Rename as...
(EOF): this.
Since there is no risk of a clash with #define EOF here...
2020-09-29 06:49:31 +02:00
Adela Vais
2e5592b3ab d: support api.symbol.prefix and api.token.prefix
The D skeleton was not properly supporting them.

* data/skeletons/d.m4, data/skeletons/lalr1.d: Fix it.
* tests/calc.at: Check it.
2020-09-28 19:27:19 +02:00
Akim Demaille
9b18cac96b multistart: start more thorough testing
* tests/local.at (AT_MULTISTART_IF): New.
* tests/calc.at: Adjust to check multiple start symbols.
* data/skeletons/yacc.c (yy_parse_impl): Fix.
2020-09-28 19:26:53 +02:00
Akim Demaille
c19c1e7ec5 tests: style: reorder the calculator test macros
* tests/local.at (AT_TOKEN_TRANSLATE_IF): New, moved from...
* tests/calc.at: here.
Instead of sorting per feature (main, yylex, calc.y) and then by
language, do the converse, so that C bits are together, etc.
2020-09-27 19:29:29 +02:00
Akim Demaille
15cf0095d3 tests: shorten the generated file
* tests/synclines.at (_AT_SYNCLINES_COMPILE): Pull the comments out.
2020-09-27 19:29:29 +02:00
Akim Demaille
3ff7db34a2 gnulib: update 2020-09-27 11:58:28 +02:00
Akim Demaille
d441a34791 multistart: also give access to yynerrs
This is something that has always bothered me: with pure parsers (and
they all should be) the user does not have an (easy) access to yynerrs
at the end of the parse.  In the case of error recovery, that's the
only direct means to know if there were errors.  The usual approach
being having the user maintain a counter incremented each time yyerror
is called.

So here, also capture yynerrs in the return value of the start-symbol
parsing functions.

* data/skeletons/yacc.c (yy_parse_impl_t): New.
(yy_parse_impl): Use it.
(b4_accept): Fill it.
* examples/c/lexcalc/parse.y, examples/c/lexcalc/scan.l: No longer
pass nerrs as lex- and parse-param, just use the resulting yynerrs.
bistromathic and reccalc both demonstrate %param.
2020-09-27 11:58:28 +02:00
Akim Demaille
f4d33ff4b4 yacc.c: also count calls to YYERROR in yynerrs
* data/skeletons/yacc.c: here.
2020-09-27 11:58:27 +02:00
Akim Demaille
683040b324 multistart: allow tokens as start symbols
After all, why not?

* src/reader.c (switching_token): Use symbol_id_get.
(check_start_symbols): Require that the start symbol is a token only
if it's the only one.
* examples/c/lexcalc/parse.y: Let NUM be a start symbol.
2020-09-27 09:44:23 +02:00
Akim Demaille
d9cf99b6a5 multistart: use b4_accept instead of action post-processing
For each start symbol, generate a parsing function with a richer
return value than the usual of yyparse.  Reserve a place for the
returned semantic value, in order to avoid having to pass a pointer as
argument to "return" that value.  This also makes the call to the
parsing function independent of whether a given start-symbol is typed.

For instance, if the grammar file contains:

    %type <int> expression
    %start input expression

(so "input" is valueless) we get

    typedef struct
    {
      int yystatus;
    } yyparse_input_t;

    yyparse_input_t yyparse_input (void);

    typedef struct
    {
      int yyvalue;
      int yystatus;
    } yyparse_expression_t;

    yyparse_expression_t yyparse_expression (void);

This commit also changes the implementation of the parser termination:
when there are multiple start symbols, it is the initial rules that
explicitly YYACCEPT.  They do that after having exported the
start-symbol's value (if it is typed):

  switch (yyn)
    {
  case 1: /* $accept: YY_EXPRESSION expression $end  */
  { ((*yyvalue).TOK_expression) = (yyvsp[-1].TOK_expression); YYACCEPT; }
    break;

  case 2: /* $accept: YY_INPUT input $end  */
  { YYACCEPT; }
    break;

I have tried several ways to deal with termination, and this is the
one that appears the best one to me.  It is also the most natural.

* src/scan-code.h, src/scan-code.l (obstack_for_actions): New.
* src/reader.c (grammar_rule_check_and_complete): Generate the actions
of the rules for each start symbol.

* data/skeletons/bison.m4 (b4_symbol_slot): New, with safer semantics
than type and type_tag.
* data/skeletons/yacc.c (b4_accept): New.
Generates the body of the action of the start rules.
(_b4_declare_sub_yyparse): For each start symbol define a dedicated
return type for its parsing function.
Adjust the declaration of its parsing function.
(_b4_define_sub_yyparse): Adjust the definition of the function.

* examples/c/lexcalc/parse.y: Check the case of valueless symbols.
* examples/c/lexcalc/lexcalc.test: Check start symbols.
2020-09-27 09:44:18 +02:00
Akim Demaille
a6805bb8d9 multistart: adjust reader checks for generated rules
So far we were not checking the generated rule 0 at all.  Now there
can be several of them.  Instead of not checking at all, let's be more
selective on the check to run on them.

* src/reader.c (grammar_rule_check_and_complete): Don't check for
value usage for generated rules, it is ok to have a valued start
symbol, in which case it is ok for the generated rule ("accept: start
$end {}") to not use $1.
(packgram): Call grammar_rule_check_and_complete for all the rules.
2020-09-27 09:23:51 +02:00
Akim Demaille
a0b044186b todo: more 2020-09-27 09:23:51 +02:00
Akim Demaille
01af4ad9c3 multistart: toy with it in lexcalc
* examples/c/lexcalc/parse.y: Define several start symbols.
* examples/c/lexcalc/lexcalc.test: Check support.
2020-09-27 09:23:51 +02:00
Akim Demaille
ed324578a2 multistart: equip yacc.c
* data/skeletons/yacc.c: Add support for multiple start symbols.
2020-09-27 09:23:51 +02:00
Akim Demaille
05d6b54703 multistart: pass the list of start symbols to the backend
* src/output.c (start_symbols_output): New.
(muscles_output): Use it.
2020-09-27 09:23:51 +02:00
Akim Demaille
78d0e5e671 multistart: also check the HTML report
We don't actually have checks for HTML, so let's do it for multistart.

* tests/report.at: here.
2020-09-27 09:23:51 +02:00
Akim Demaille
85ccc1bab3 multistart: adjust computation of initial core and adjust reports
Currently the core of the initial state is limited to the single rule
on $accept.

* src/lr0.c (generate_states): There may now be several rules on
$accept.

* src/graphviz.c (conclude_red): Recognize "final" transitions by the
fact that we reduce to "$accept".
* src/print.c (print_reduction): Likewise.
* src/print-xml.c (print_reduction): Likewise.
2020-09-27 09:23:51 +02:00
Akim Demaille
4646be7db4 regen 2020-09-27 09:23:51 +02:00