Commit Graph

1668 Commits

Author SHA1 Message Date
Akim Demaille
650b253843 m4: fix b4_token_format
We used to emit:

    /** Token number,to be returned by the scanner.  */
    static final int NUM = 258;
    /** Token number,to be returned by the scanner.  */
    static final int NEG = 259;

with no space after the comma.  Fix that.

* data/skeletons/bison.m4 (b4_token_format): Quote where appropriate.
2020-02-08 11:24:53 +01:00
Akim Demaille
ebab1ffca8 java: style: avoid useless initializers
Instead of

      /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
       STATE-NUM.  */
      private static final byte yypact_[] = yypact_init ();
      private static final byte[] yypact_init ()
      {
        return new byte[]
        {
          25,    -7,    -8,    37,    -8,    40,    -8,    20,    -8,    61,
          -8,    -8,     3,     9,    51,    -8,    -8,    -2,    -2,    -2,
          -2,    -2,    -2,    -8,    -8,    -8,     1,    66,    66,     3,
           3,     3
        };
      }

generate

    /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
       STATE-NUM.  */
      private static final byte[] yypact_ =
      {
          25,    -7,    -8,    37,    -8,    40,    -8,    20,    -8,    61,
          -8,    -8,     3,     9,    51,    -8,    -8,    -2,    -2,    -2,
          -2,    -2,    -2,    -8,    -8,    -8,     1,    66,    66,     3,
           3,     3
      };

I have no idea what motivated the previous approach.

* data/skeletons/java.m4 (b4_typed_parser_table_define): Here.
2020-02-05 13:17:00 +01:00
Akim Demaille
f705e9abdb java: style: prefer putting the square brackets on the type
* examples/java/calc/Calc.y, examples/java/simple/Calc.y,
* tests/calc.at, tests/local.at: here.
2020-02-05 13:17:00 +01:00
Akim Demaille
d727e0ff23 traces: don't print the stack before the gotos
The C, C++ and D skeletons used to show the stack right after popping
the stack during the reduction.  Now that the stack is printed after
reaching a new state, that has become useless:

    Entering state 1
    Stack now 0 1
    Reducing stack by rule 5 (line 83):
       $1 = token "number" (1)
    -> $$ = nterm exp (1)
    Stack now 0
    Entering state 8
    Stack now 0 8

Remove the "Stack now 0" line.

* data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java, data/skeletons/yacc.c:
Here.
2020-02-05 07:40:07 +01:00
Akim Demaille
37aeda6fb3 traces: show the stack after reading a token
Currently, if we have long rules and series of shift, we stack states
without showing stack.  Let's be more incremental, and do how the Java
skeleton does.

* data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/yacc.c:
Here.
Adjust test cases.
* tests/torture.at (AT_DATA_STACK_TORTURE): Disable stack traces: this
test produces a very large stack, and showing the stack each time we
shift a token goes quadatric.
2020-02-05 06:48:42 +01:00
Akim Demaille
bba2f0a3a0 traces: write the "Reading a token" alone on its line
The Java skeleton displays

    Reading a token:
    Next token is token "number" (1)

while the other display

    Reading a token: Next token is token "number" (1)

When generating logs in the scanner, the first part is separated from
the second, and the end of the scanner logs have the second part
pasted in.  So let's propagate the Java way, but with the colon.

* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/lalr1.d,
* data/skeletons/lalr1.java, data/skeletons/yacc.c: Do it.
Adjust test cases and doc.
2020-02-04 07:02:24 +01:00
Akim Demaille
fe14fb1c40 java: use the same calc tests as the other skeletons
* tests/local.at (AT_LANG_MATCH): New.
(AT_YYERROR_DECLARE(java), AT_YYERROR_DECLARE_EXTERN(java)): New.
* tests/calc.at: The grammar file for Java is quite different for the
others, and continuing to assemble it from pieces makes the grammar
file hard to understand.  Let's also dispatch on the language to
assemble it, and isolate Java from the others.
Most of this comes from java.at.
2020-02-02 11:33:16 +01:00
Akim Demaille
88d1ab421a java: add access to the number of errors
* data/skeletons/lalr1.java (yynewrrs, getNumberOfErrors): New.
Formatting changes.
2020-02-02 11:33:16 +01:00
Akim Demaille
edf495b38e java: formatting changes
* data/skeletons/java.m4, data/skeletons/lalr1.java: here.
2020-02-02 11:33:16 +01:00
Akim Demaille
ba69beafac java: avoid trailing white spaces
* data/skeletons/java.m4 (b4_maybe_throws): Issue a space before when needed.
* data/skeletons/lalr1.java: Avoid trailing spaces.
2020-02-02 11:33:16 +01:00
Akim Demaille
0774b2c6e3 skeletons: add support for %code epilogue
When building the test cases, emitting code in the epilogue is very
constraining.  Let's make it simpler thanks to %code epilogue.

However, I don't want to document this: it is bad style to use it (we
should avoid having too many ways to write the same thing,
TI!MTOWTDI), just put your code in the true epilogue section.

* data/skeletons/glr.c, data/skeletons/lalr1.d, data/skeletons/lalr1.java,
* data/skeletons/yacc.c: Implement support for %code epilogue.
Remove useless comments.
* tests/calc.at, tests/java.at: Simplify.
2020-02-02 11:28:45 +01:00
Akim Demaille
792fc34016 glr.c: add support for parse.error=custom
* data/skeletons/glr.c (yyreportSyntaxError): Call the user's
yyreport_syntax_error in custom mode.
* tests/calc.at: Check it.
2020-01-29 19:48:16 +01:00
Akim Demaille
c4a08d1899 glr.c: add support for parse.error=detailed
* data/skeletons/glr.c (yystrlen, yysymbol_name): New.
Implement parse.error detailed.
* tests/calc.at: Check it.
2020-01-29 19:48:12 +01:00
Akim Demaille
50fb1e6e0c glr.c: introduce yyexpected_tokens and yysyntax_error_arguments
Modeled after what was done in yacc.c, yet somewhat different since
yyGLRStack play the role of the full yyparse_context_t.  It will
probably be defined as a alias, to make interfaces compatible.

LAC is not supported here.  And is somewhat tricky.

* data/skeletons/glr.c (yyexpected_tokens, yysyntax_error_arguments): New.
2020-01-29 19:27:42 +01:00
Akim Demaille
6bd0527a50 glr.c: move code around
* data/skeletons/glr.c: Move the handling of error messages after the
definition of types.  Especially after yyGLRStack, which we will need
in forthcoming patches.
Simplify: yyGLRStack is defined at this point.
2020-01-29 19:27:24 +01:00
Akim Demaille
1aa9d40b24 glr.c: rename yyStateNum as yy_state_t
* data/skeletons/glr.c: here.
For consistency with yacc.c.
2020-01-29 07:15:19 +01:00
Akim Demaille
a1da9b9fe8 yacc.c: fix misleading indentation
* data/skeletons/yacc.c: here.
2020-01-29 07:15:19 +01:00
Akim Demaille
0f792833c2 style: formatting changes
* data/skeletons/lalr1.java: here.
2020-01-26 13:29:19 +01:00
Akim Demaille
46ab1d0cbe diagnostics: report syntax errors in color
* src/parse-gram.y (parse.error): Set to 'custom'.
(yyreport_syntax_error): New.
* data/bison-default.css (.expected, .unexpected): New.
* tests/diagnostics.at: Adjust.
2020-01-23 08:26:33 +01:00
Akim Demaille
16c77b4ba2 yacc.c: fixes
* data/skeletons/yacc.c: Avoid warnings about unused functions.
Fix typo.
2020-01-22 22:31:07 +01:00
Adrian Vogelsgesang
4ab2cf7450 larlr1.cc: Reject unsupported values for parse.lac
Just as the yacc.c skeleton, the lalr1.cc skeleton should reject
invalid values for parse.lac.

* data/skeletons/lalr1.cc: check validity of parse.lac
* tests/input.at: new test cases
2020-01-21 06:57:21 +01:00
Adrian Vogelsgesang
172f103c1e larlr1.cc: Reject unsupported values for parse.lac
Just as the yacc.c skeleton, the lalr1.cc skeleton should reject
invalid values for parse.lac.

* data/skeletons/lalr1.cc: check validity of parse.lac
* tests/input.at: new test cases
2020-01-21 06:22:27 +01:00
Akim Demaille
9096955fba parsers: support translatable token aliases
In addition to

    %token NUM "number"

accept

    %token NUM _("number")

in which case the token will be translated in error messages.
Do not use _() in the output if there are no translatable tokens.

* src/symtab.h, src/symtab.c (symbol): Add a 'translatable' member.
* src/parse-gram.y (TSTRING): New token.
(string_as_id.opt): Replace with...
(alias): this.
Use it.
* src/scan-gram.l (SC_ESCAPED_TSTRING): New start conditions, to match
TSTRINGs.
* src/output.c (prepare_symbols): Define b4_translatable if there are
translatable strings.

* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c (yytnamerr): Receive b4_translatable, and use it.
2020-01-19 21:23:11 +01:00
Akim Demaille
f443673450 yacc.c: add support for parse.error detailed
"detailed" error messages are almost like "verbose", except that we
don't double escape them, they don't get inner quotes, we don't use
yytnamerr, and we hide the table.

"custom" is exposed with the "detailed" tokens, not the "verbose"
ones: they are not double-quoted.

Because there's a risk that some people use yytname even without
"verbose", let's keep yytname (instead of yys_name) in "simple"
parse.error.

* src/output.c (prepare_symbol_names): Be ready to output symbol names
unquoted.
(prepare_symbol_names): Output both the old tname table, and the new
symbol_names one.
* data/skeletons/bison.m4: Accept 'detailed'.
* data/skeletons/yacc.c: When parse.error is 'detailed', don't emit
yytname and yytnamerr, just yysymbol_name with the table inside.
* tests/calc.at: Adjust.
2020-01-19 14:51:14 +01:00
Akim Demaille
8e6233353f c: use yysymbol_name in traces
Only parse.error verbose and simple will get the original yytname: the
other options will rely on a different table.  So let's move on top of
the yysymbol_name function.

* data/skeletons/c.m4 (yy_symbol_print): Use yysymbol_name.
* data/skeletons/glr.c (yytokenName): Rename as...
(yysymbol_name): this.
The change of naming scheme is unfortunate, but it's definitely glr.c
which is "wrong".
2020-01-19 14:51:14 +01:00
Akim Demaille
e5a5da16ed glr.c: move some functions after the definition of types
Currently yy_symbol_print is defined before yytokenName, although it
should use it instead of read yytname directly.  Move blocks around to
avoid this.

* data/skeletons/glr.c (yy_symbol_print): Move its definition after
that of yytokenName.
2020-01-19 14:51:14 +01:00
Akim Demaille
ebe427bbf3 Merge branch 'maint'
* maint:
  maint: post-release administrivia
  version 3.5.1
  news: update
  CI: use ICC again
  warnings: pacify ICC in lalr1.cc
  test: report.at: avoid tiny new failure
  git: update ignores
2020-01-19 14:50:09 +01:00
Akim Demaille
6990c5bde9 warnings: pacify ICC in lalr1.cc
See 139d065594.

* data/skeletons/yacc.c: If I might be a char, write a[+I] instead of
a[I], so that ICC does not complain.
2020-01-19 11:35:26 +01:00
Akim Demaille
e1197fcc3d yacc.c: portability to G++ 4.8
Currently we get warnings with GCC 4.8 when running the
maintainer-check-g++ tests:

    143. skeletons.at:85: testing Installed skeleton file names ...
    ../../tests/skeletons.at:120: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret --skeleton=yacc.c -o input-cmd-line.c input-cmd-line.y
    ../../tests/skeletons.at:121: $CC $CFLAGS $CPPFLAGS  $LDFLAGS -o input-cmd-line input-cmd-line.c $LIBS
    stderr:
    input-cmd-line.c: In function 'int yysyntax_error(long int*, char**, const yyparse_context_t*)':
    input-cmd-line.c:977:52: error: conversion to 'int' from 'long int' may alter its value [-Werror=conversion]
                                       YYSIZEOF (yyarg) / YYSIZEOF (*yyarg));
                                                        ^
    cc1plus: all warnings being treated as errors
    stdout:
    ../../tests/skeletons.at:121: exit code was 1, expected 0

and

    429. calc.at:823: testing Calculator parse.error=custom %locations api.prefix={calc}  ...
    ../../tests/calc.at:823: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret -Wno-deprecated -o calc.c calc.y
    ../../tests/calc.at:823: $CC $CFLAGS $CPPFLAGS  $LDFLAGS -o calc calc.c $LIBS
    stderr:
    calc.y: In function 'int yyreport_syntax_error(const yyparse_context_t*)':
    calc.y:157:58: error: conversion to 'int' from 'long unsigned int' may alter its value [-Werror=conversion]
       int n = yysyntax_error_arguments (ctx, arg, sizeof arg / sizeof *arg);
                                                              ^
    cc1plus: all warnings being treated as errors
    stdout:
    ../../tests/calc.at:823: exit code was 1, expected 0

We could use a cast to avoid the warning, but it becomes too
cluttered.  We can also use YYPTRDIFF_T, but that forces the user to
use YYPTRDIFF_T too, although this is an array of tokens, which is
limited by YYNTOKENS, an int.  So let's completely avoid this warning.

* data/skeletons/yacc.c, tests/local.at (yyreport_syntax_error): Avoid
relying on sizeof to compute the array capacity.
2020-01-17 06:49:59 +01:00
Akim Demaille
1854429e40 yacc.c: pass the parse-params to yyreport_syntax_error
Enhance the calculator tests: show that passing arguments to yyerror
works.

* tests/calc.at: Add a new parse-param, nerrs, which counts the number
of syntax errors in a run.
* tests/local.at: Adjust to handle the new 'nerrs' argument, when
present.

The custom error reporting function show sees the user's additional
arguments.  Let's experiment with passing them as arguments to
yyreport_syntax_error, but maybe storing them in the context would be
a bettter alternative.

* data/skeletons/yacc.c (yyreport_syntax_error): Handle the
parse-params.
* tests/calc.at, tests/local.at: Adjust.
2020-01-17 06:49:59 +01:00
Akim Demaille
fd33cc9c8b yacc.c: let custom error messages see the location
* data/skeletons/yacc.c (yyparse_context_t): Add yylloc when
applicable.
(yyparse_context_location): New.
* tests/local.at (AT_YYERROR_DEFINE(c)): Handle the location.
* tests/calc.at: Check it.
2020-01-17 06:49:59 +01:00
Akim Demaille
8637438cee yacc.c: isolate yyexpected_tokens
Provide users with a means to query for the currently allowed tokens.
Could be used for autocompletion for instance.

* data/skeletons/yacc.c (yyexpected_tokens): New, extracted from
yysyntax_error_arguments.
* examples/c/calc/calc.y (PRINT_EXPECTED_TOKENS): New.
Use it.
2020-01-17 06:49:59 +01:00
Akim Demaille
cda1934606 yacc.c: add custom error message generation
When parse.error is custom, let users define a yyreport_syntax_error
function, and use it.

* data/skeletons/bison.m4 (b4_error_verbose_if): Accept 'custom'.
* data/skeletons/yacc.c: Implement it.
* examples/c/calc/calc.y: Experiment with it.
2020-01-17 06:49:59 +01:00
Akim Demaille
5b883180e6 yacc.c: style: avoid macros
* data/skeletons/yacc.c (YYSYNTAX_ERROR): Remove, the call is now
sufficiently small so that we can afford to duplicate it.
2020-01-17 06:49:59 +01:00
Akim Demaille
135d0336d5 yacc.c: store token numbers, not token strings
That allows users to cover more cases, such as easily filtering some
arguments they don't want to expose.  But they now have to call
yysymbol_name explicitly.

* data/skeletons/yacc.c (yysyntax_error_arguments, yysyntax_error):
Deal with symbol numbers instead of symbol names.
2020-01-17 06:49:59 +01:00
Akim Demaille
cc6c647f00 yacc.c: extract yyerror_message_arguments
Isolate a function that returns the list of expected and unexpected
tokens.  It will be exposed to users willing to customize their error
messages.

* data/skeletons/yacc.c (yyparse_context_t): New.
(yyerror_message_arguments): New, extracted from yysyntax_error.
2020-01-17 06:49:59 +01:00
Akim Demaille
c894a6e2ce d, java: use traces more alike that of C
Same order, same places, same content.

* data/skeletons/lalr1.d, data/skeletons/lalr1.java: here.
2020-01-15 06:23:46 +01:00
Akim Demaille
187c2ac344 c++: report the stack at the same places as in C
Let's have C be the reference, and match it elsewhere.  Maybe C is too
verbose and some adjustments are needed, but then that would be done
in another batch of patches.

* data/skeletons/lalr1.cc: Print the stack once we popped after
YYERROR, and before emptying the stack at the end of parsing.
2020-01-15 06:22:42 +01:00
Akim Demaille
f06c0d2c05 c++: display the stack in the same order as in C
Currently the C and C++ parse traces differ in the order in which the
stack is displayed: bottom up in C, top down in C++.  Let's stick to
the C order.

* data/skeletons/stack.hh (stack::iterator, stack::const_iterator)
(begin, end): Be forward, not backward.
2020-01-15 06:22:31 +01:00
Akim Demaille
1c0adb410d yacc.c: comment changes
In particular, import Adrian Vogelsgesang's comments about LAC from
lalr1.cc.

* data/skeletons/yacc.c: here.
2020-01-11 18:01:39 +01:00
Akim Demaille
32b529f038 yacc.c: style: double-quote the argument of b4_percent_define_get
* data/skeletons/yacc.c: Here, for consistency.
2020-01-11 17:35:24 +01:00
Akim Demaille
46cce832fd yacc.c: introduce yysymbol_name
Provide the users with a public API to get the name of the tokens.  A
thin wrapper around yytname.

* data/skeletons/yacc.c (yysymbol_name): New.
Use it.
2020-01-11 16:14:06 +01:00
Akim Demaille
a0675d707f Merge branch 'maint' into HEAD
* maint:
  gnulib: update
  lalr1.cc: avoid static_cast
  glr.c: add missing cast
  regen
  package: bump copyrights to 2020
  gitignore: update
2020-01-11 07:38:39 +01:00
Akim Demaille
3dec8a4caf lalr1.cc: avoid static_cast
Reported by donmac703.
Fixes https://github.com/akimd/bison/issues/20.

* data/skeletons/lalr1.cc: here.
2020-01-10 19:31:00 +01:00
Akim Demaille
2cb52c5a91 glr.c: add missing cast
Reported by psjo.
Fixes https://github.com/akimd/bison/issues/19.

* data/skeletons/glr.c (yyprocessOneStack): Here.
2020-01-10 19:30:54 +01:00
Akim Demaille
c67daa9a97 package: bump copyrights to 2020
Run 'make update-copyright'.
2020-01-10 19:16:23 +01:00
Akim Demaille
2116af766a yacc.c: simplify use of YYDPRINTF
* data/skeletons/yacc.c (YYDPRINTF): Expand to no-op (instead of
nothing) when disabled.
Simplify callers.
2020-01-09 09:02:55 +01:00
Akim Demaille
8036635251 package: bump copyrights to 2020
Run 'make update-copyright'.
2020-01-05 10:26:35 +01:00
Akim Demaille
86a3ec0f8d glr.c: no longer support YYERROR_VERBOSE
* data/skeletons/glr.c: Rather, dispatch directly on parse.error's
value.
2020-01-04 09:14:19 +01:00
Akim Demaille
7122d747cf yacc.c: no longer support YYERROR_VERBOSE
Supporting YYERROR_VERBOSE via cpp is a nuisance: m4 is in charge of
handling alternatives.  When adding more options for %define
parse.error, supporting both CPP and M4 is too complex.  Anyway,
YYERROR_VERBOSE was deprecated long ago.

* data/skeletons/yacc.c: Use m4 only to handle verbose/simple error
messages.
2020-01-04 09:12:43 +01:00