Commit Graph

1554 Commits

Author SHA1 Message Date
Akim Demaille
8dcc25a1e4 style: rename YYNOMEM as YYENOMEM
This is clearer.

* data/skeletons/glr.c, data/skeletons/yacc.c (YYNOMEM): Rename as...
(YYENOMEM): here.
2020-04-10 18:35:29 +02:00
Akim Demaille
00a654c8ad c++: improvements on symbol kinds
Instead of

    /// (Internal) symbol kind.
    enum symbol_kind_type
    {
      YYNTOKENS = 5, ///< Number of tokens.
      YYSYMBOL_YYEMPTY = -2,
      YYSYMBOL_YYEOF = 0,                      // END_OF_FILE
      YYSYMBOL_YYERROR = 1,                    // error
      YYSYMBOL_YYUNDEF = 2,                    // $undefined
      YYSYMBOL_TEXT = 3,                       // TEXT
      YYSYMBOL_NUMBER = 4,                     // NUMBER
      YYSYMBOL_YYACCEPT = 5,                   // $accept
      YYSYMBOL_result = 6,                     // result
      YYSYMBOL_list = 7,                       // list
      YYSYMBOL_item = 8                        // item
    };

generate

    /// Symbol kinds.
    struct symbol_kind
    {
      enum symbol_kind_type
      {
        YYNTOKENS = 5, ///< Number of tokens.
        S_YYEMPTY = -2,
        S_YYEOF = 0,                             // END_OF_FILE
        S_YYERROR = 1,                           // error
        S_YYUNDEF = 2,                           // $undefined
        S_TEXT = 3,                              // TEXT
        S_NUMBER = 4,                            // NUMBER
        S_YYACCEPT = 5,                          // $accept
        S_result = 6,                            // result
        S_list = 7,                              // list
        S_item = 8                               // item
      };
    };

* data/skeletons/c++.m4 (api.symbol.prefix): Define to S_.
Adjust all the uses.
(b4_public_types_declare): Nest the enum inside 'struct symbol_kind'.
* data/skeletons/glr.cc, data/skeletons/lalr1.cc,
* tests/headers.at, tests/local.at: Adjust.
2020-04-10 18:35:29 +02:00
Akim Demaille
6c5f690da4 d: improvements on symbol kinds
public enum SymbolKind
    {
      S_YYEMPTY = -2,    /* No symbol.  */
      S_YYEOF = 0,       /* $end  */
      S_YYERROR = 1,     /* error  */
      S_YYUNDEF = 2,     /* $undefined  */
      S_EQ = 3,          /* "="  */

* data/skeletons/d.m4 (api.symbol.prefix): Default to S_.
Output the symbol kind definitions with a comment.
2020-04-10 18:35:29 +02:00
Akim Demaille
007e1b5f0a symbols: minor fixes
* data/skeletons/bison.m4 (b4_symbol_kind): Series of _ are useless,
one is enough.
* data/skeletons/c.m4 (b4_token_enum): Fix overquoting.
2020-04-10 18:33:02 +02:00
Akim Demaille
bbb9750b3e skeletons: introduce api.symbol.prefix
* data/skeletons/bison.m4 (b4_symbol_prefix): New.
(b4_symbol_kind): Use it.
* data/skeletons/c++.m4, data/skeletons/c.m4, data/skeletons/d.m4
* data/skeletons/java.m4 (api.symbol.prefix): Provide a default value.

* data/skeletons/glr.c, data/skeletons/glr.cc, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java, data/skeletons/yacc.c:
Adjust: use b4_symbol_prefix instead of YYSYMBOL_.
2020-04-07 08:40:16 +02:00
Akim Demaille
52d0e77c2c java: also emit documenting comments for symbol kinds
* data/skeletons/java.m4 (b4_symbol_enum): here.
And stop defined YYSYMBOL_YYEMPTY, we no longer use it.
2020-04-07 08:39:54 +02:00
Akim Demaille
87579e03e0 skeletons: beware not to use yyarg when it's null
Reported by Adrian Vogelsgesang.

* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.java, data/skeletons/yacc.c: Here.
2020-04-06 19:14:11 +02:00
Akim Demaille
11225a5d2f java: document new features
* data/skeletons/lalr1.java: More comments.
(Context.EMPTY): Remove.
* doc/bison.texi (Java Parser Context Interface): New.
2020-04-06 19:14:11 +02:00
Akim Demaille
3dcfb4fd88 java: prefer null to YYSYMBOL_YYEMPTY
That's one nice benefit from using enums.

* data/skeletons/lalr1.java (YYSYMBOL_YYEMPTY): No longer define it.
Use 'null' instead.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-06 19:14:11 +02:00
Akim Demaille
c0ccb8e5b4 java: rename Lexer.yyreportSyntaxError as reportSyntaxError
* data/skeletons/lalr1.java: here.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-06 19:14:06 +02:00
Akim Demaille
79f967ac0d java: use getExpectedTokens, not yyexpectedTokens
* data/skeletons/lalr1.java, examples/java/calc/Calc.y, tests/local.at:
here.
2020-04-06 18:43:34 +02:00
Akim Demaille
0f6ab8e692 java: style: fix coding style
* data/skeletons/java.m4: Indent by two.
* data/skeletons/lalr1.java (yynnts_): Remove.
(yyfinal_, yyntokens_, yylast_, yyempty_): Rename as...
(YYFINAL_, YYNTOKENS_, YYLAST_, YYEMPTY_): these, they are constants.
2020-04-06 18:43:34 +02:00
Akim Demaille
e657f04b62 c: make the symbol kind definition nicer to read
From

    enum yysymbol_kind_t
    {
      YYSYMBOL_YYEMPTY = -2,
      YYSYMBOL_YYEOF = 0,
      YYSYMBOL_YYERROR = 1,
      YYSYMBOL_YYUNDEF = 2,

to

    enum yysymbol_kind_t
    {
      YYSYMBOL_YYEMPTY = -2,
      YYSYMBOL_YYEOF = 0,                      /* "end of file"  */
      YYSYMBOL_YYERROR = 1,                    /* error  */
      YYSYMBOL_YYUNDEF = 2,                    /* $undefined  */

* data/skeletons/bison.m4 (b4_last_symbol): New.
(b4_symbol_enum, b4_symbol_enums): Reformat the output.
* data/skeletons/c.m4
2020-04-06 18:43:34 +02:00
Akim Demaille
10e61eec6d c: make the token kind definition nicer to read
From

    enum gram_tokentype
    {
      GRAM_EOF = 0,
      STRING = 3,
      TSTRING = 4,
      PERCENT_TOKEN = 5,

To

    enum gram_tokentype
    {
      GRAM_EOF = 0,                  /* "end of file"  */
      STRING = 3,                    /* "string"  */
      TSTRING = 4,                   /* "translatable string"  */
      PERCENT_TOKEN = 5,             /* "%token"  */

* data/skeletons/bison.m4 (b4_last_enum_token): New.
* data/skeletons/c.m4 (b4_token_enum, b4_token_enums): Show the
corresponding symbol.
2020-04-06 18:43:34 +02:00
Akim Demaille
149e280aab c: make the generated YYSTYPE nicer to read
From

    union GRAM_STYPE
    {
      /* precedence_declarator  */
      assoc precedence_declarator;
      /* "string"  */
      char* STRING;
      /* "translatable string"  */
      char* TSTRING;
      /* "{...}"  */
      char* BRACED_CODE;
      /* "%?{...}"  */

to

    union GRAM_STYPE
    {
      assoc precedence_declarator;             /* precedence_declarator  */
      char* STRING;                            /* "string"  */
      char* TSTRING;                           /* "translatable string"  */
      char* BRACED_CODE;                       /* "{...}"  */

* data/skeletons/c.m4 (b4_symbol_type_register): Use m4_format to
align the comments.
* src/parse-gram.h: Regen.
2020-04-06 18:43:34 +02:00
Akim Demaille
f0bb82ae9e skeletons: use consistently "kind" instead of "type" in the code
* data/skeletons/bison.m4, data/skeletons/c++.m4, data/skeletons/c.m4,
* data/skeletons/glr.cc, data/skeletons/lalr1.cc,
* data/skeletons/lalr1.d, data/skeletons/lalr1.java:
Refer to the "kind" of a symbol, not its "type", where appropriate.
2020-04-05 19:14:39 +02:00
Akim Demaille
2b7bde9d13 m4: rename b4_symbol_sid as b4_symbol_kind
* data/skeletons/bison.m4, data/skeletons/c++.m4, data/skeletons/c.m4,
* data/skeletons/d.m4, data/skeletons/java.m4
(b4_symbol_sid): Rename as...
(b4_symbol_kind): this.
Adjust dependencies.
* data/README.md: Document the kind.
2020-04-05 14:56:19 +02:00
Akim Demaille
ff2fc62138 d, java: rename SymbolType as SymbolKind
See https://lists.gnu.org/r/bison-patches/2020-04/msg00031.html.

* data/skeletons/d.m4, data/skeletons/lalr1.d,
* data/skeletons/java.m4, data/skeletons/lalr1.java
(SymbolType): Rename as...
(SymbolKind): this.
Adjust dependencies.
2020-04-05 14:56:19 +02:00
Akim Demaille
2c05fc750a c, c++: rename yysymbol_type_t as yysymbol_kind_t
See https://lists.gnu.org/r/bison-patches/2020-04/msg00031.html

* data/skeletons/c.m4, data/skeletons/glr.c, data/skeletons/yacc.c
(yysymbol_type_t): Rename as...
(yysymbol_kind_t): this.
Adjust dependencies.
* data/skeletons/c++.m4, data/skeletons/glr.cc, data/skeletons/lalr1.cc
(symbol_type_type): Rename as...
(symbol_kind_type): this.
Adjust dependencies.
2020-04-05 14:56:18 +02:00
Akim Demaille
7aee4586ca Merge branch 'maint'
* maint:
  maint: post-release administrivia
  version 3.5.4
  examples: reccalc: really compile cleanly in C99
  news: announce that Bison 3.6 drops YYERROR_VERBOSE
  news: update for 3.5.4
  style: fix spellos
  typo: succesful -> successful
  package: improve the readme
  java: check and fix support for api.token.raw
  java: style: prefer 'int[] foo' to 'int foo[]'
  build: fix syntax-check issues
  tests: recheck: work properly when the test suite was interrupted
  doc: c++: promote api.token.raw
  build: fix compatibility with old compilers
  examples: reccalc: compile cleanly in C99
2020-04-05 09:38:15 +02:00
Akim Demaille
4e26809ab9 style: rename yysyntax_error_arguments as yy_syntax_error_arguments
It's a private implementation detail.

* NEWS, data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c, doc/bison.texi: here.
2020-04-05 08:56:21 +02:00
Akim Demaille
76e11b5a3e c: rename yyparse_context_t as yypcontext_t
The first name is too long.  We already have `yypstate`, so
`yypcontext` is ok.  We are also migrating to using `*_t` for our
types.

* NEWS, data/skeletons/glr.c, data/skeletons/yacc.c, doc/bison.texi,
* examples/c/bistromathic/parse.y, src/parse-gram.y, tests/local.at:
(yyparse_context_t, yyparse_context_location, yyparse_context_token):
Rename as...
(yypcontext_t, yypcontext_location, yypcontext_token): these.
2020-04-04 19:20:29 +02:00
Akim Demaille
f6dcecb287 java: fixes in SymbolType
Reported by Paolo Bonzini.
https://github.com/akimd/bison/pull/34#issuecomment-609029634

* data/skeletons/java.m4 (SymbolType): Use 'final' where possible.
(get): Rewrite on top of an array instead of a switch.
2020-04-04 17:11:02 +02:00
Akim Demaille
ad31c3cdf4 java: use SymbolType
The Java enums are very different from the C model.  As a consequence,
one cannot "build" an enum directly from an integer, we must retrieve
it.  That's the purpose of the SymbolType.get class method.

* data/skeletons/java.m4 (b4_symbol_enum, b4_case_code_symbol)
(b4_declare_symbol_enum): New.
* data/skeletons/lalr1.java: Use SymbolType,
SymbolType.YYSYMBOL_YYEMPTY, etc.
* examples/java/calc/Calc.y, tests/local.at: Adjust.
2020-04-04 16:42:33 +02:00
Akim Demaille
72f04ca80f java: check and fix support for api.token.raw
* tests/local.at (AT_LANG_MATCH, AT_YYERROR_DECLARE(java))
(AT_YYERROR_DECLARE_EXTERN(java), AT_PARSER_CLASS): New.
(AT_MAIN_DEFINE(java)): Use AT_PARSER_CLASS.
* tests/scanner.at: Add a test for Java.
* data/skeletons/lalr1.java (yytranslate_): Cast the result.
2020-04-04 10:34:53 +02:00
Akim Demaille
fd98afaf10 d: use the SymbolType enum for symbol kinds
* data/skeletons/d.m4 (b4_symbol_enum, b4_declare_symbol_enum): New.
* data/skeletons/lalr1.d: Use them.
Use SymbolType, SymbolType.YYSYMBOL_YYEMPTY etc. where appropriate.
(undef_token_, token_number_type, yy_error_token_): Remove.
2020-04-04 10:31:50 +02:00
Akim Demaille
cca8c73431 java: style: prefer 'int[] foo' to 'int foo[]'
* data/skeletons/java.m4 (b4_typed_parser_table_define): Here.
2020-04-04 08:08:07 +02:00
Akim Demaille
a0ee2a7543 c++: replace symbol_number_type with symbol_type_type
* data/skeletons/c++.m4, data/skeletons/glr.cc,
* data/skeletons/lalr1.cc: here.
2020-04-01 08:32:58 +02:00
Akim Demaille
7e28dbea11 c++: also use symbol_type_type
Because of the insane current implementation of glr.cc, things are a
bit nasty.  We will rename symbol_number_type as symbol_type_type
later, to keep this commit small.

* data/skeletons/c++.m4 (b4_declare_symbol_enum): New.
Also define YYNTOKENS to avoid type clashes when yyntokens_ was
actually defined in another enum.
Use it.
(symbol_number_type): Be an alias of symbol_type_type.
Use YYSYMBOL_YYEMPTY and the like.
Use symbol_number_type where appropriate.
(empty_symbol): Remove.
(yytranslate_): Use symbol_number_type, not token_number_type.
* data/skeletons/lalr1.cc: Use symbol_number_type where appropriate.
Adjust to the replacement of empty_symbol by YYSYMBOL_YYEMPTY.
(yy_error_token_, yy_undef_token_, yyeof_, yyntokens_): Remove.
Adjust dependencies.

* data/skeletons/glr.cc: Use symbol_number_type where appropriate.
Forward definitions of YYSYMBOL_YYEMPTY, etc. to glr.c.

* tests/headers.at: Accept YYNTOKENS and other YYSYMBOL_*.
* tests/local.at (AT_YYERROR_DEFINE(c++)): Use symbol_number_type.
2020-04-01 08:32:50 +02:00
Akim Demaille
65df8d6747 glr.c: remove the yySymbol alias
* data/skeletons/glr.c: Use yysymbol_type_t only.
2020-04-01 08:31:48 +02:00
Akim Demaille
086506bf23 glr.c, yacc.c: propagate yysymbol_type_t
Now that yacc.c and glr.c both know yysymbol_type_t, convert the
common routines.

* data/skeletons/c.m4 (yydestruct, yy_symbol_value_print)
(yy_symbol_print): Use yysymbol_type_t instead of int.
* data/skeletons/glr.c: Use yySymbol where appropriate.
* data/skeletons/yacc.c (YY_ACCESSING_SYMBOL): New wrapper around
yystos.
Use it.
* tests/local.at (yyreport_syntax_error): Use yysymbol_type_t where
appropriate.
2020-04-01 08:31:48 +02:00
Akim Demaille
39792f57fb glr.c: use yysymbol_type_t, YYSYMBOL_YYEOF etc.
Apply the same changes as in yacc.c.  Now yySymbol and yysymbol_type_t
are aliases.  We will remove the former later, to avoid cluttering
this commit.

* data/skeletons/glr.c: Use b4_declare_symbol_enum.
Use YYSYMBOL_YYEOF etc. where appropriate.
(YYUNDEFTOK, YYTERROR): Remove.
(YYTRANSLATE, yySymbol, yyexpected_tokens, yysyntax_error_arguments):
Adjust.
(yy_accessing_symbol): New.
Use it where appropriate.
2020-04-01 08:31:48 +02:00
Akim Demaille
9039c571f4 yacc.c: fix more errors from make maintainer-check-g++
* data/skeletons/yacc.c (yyexpected_tokens): Use casts where needed.
2020-04-01 08:31:48 +02:00
Akim Demaille
9434571f95 yacc.c: revert to not using yysymbol_type_t in the yytranslate table
This triggers warnings with several compilers.  For instance ICC fills
the logs with pages and pages of

    input.c(477): error: a value of type "int" cannot be used to initialize an entity of type "const yysymbol_type_t={yysymbol_type_t}"
             0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
             ^

    input.c(477): error: a value of type "int" cannot be used to initialize an entity of type "const yysymbol_type_t={yysymbol_type_t}"
             0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
                    ^

And so does G++9 when compiling yacc.c's (C) output

    input.c:545:8: error: invalid conversion from 'int' to 'yysymbol_type_t' [-fpermissive]
      545 |        0,     5,     9,     2,     2,     2,     2,     2,     2,     2,
          |        ^
          |        |
          |        int
    input.c:545:15: error: invalid conversion from 'int' to 'yysymbol_type_t' [-fpermissive]
      545 |        0,     5,     9,     2,     2,     2,     2,     2,     2,     2,
          |               ^
          |               |
          |               int

Clang++ is no exception

    input.c:545:8: error: cannot initialize an array element of type 'const yysymbol_type_t' with an rvalue of type 'int'
           0,     5,     9,     2,     2,     2,     2,     2,     2,     2,
           ^
    input.c:545:15: error: cannot initialize an array element of type 'const yysymbol_type_t' with an rvalue of type 'int'
           0,     5,     9,     2,     2,     2,     2,     2,     2,     2,
                  ^

At some point we could use yysymbol_type_t's enumerators to define
yytranslate.  Meanwhile...

* data/skeletons/yacc.c (yytranslate): Use the original integral type
to define it.
(YYTRANSLATE): Cast the result into yysymbol_type_t.
2020-04-01 08:31:48 +02:00
Akim Demaille
fd37eb057e yysymbol_type_t: always assign an enumerator
Currently we define enumerators only for symbols that have an
identifier.  That rules out tokens such as '+', and nonterminals such
as foo-bar and foo.bar.  As a consequence we are taking chances: the
compiler might compile yysymbol_type_t as too small an integral type
for some symbol codes.

* data/skeletons/bison.m4 (b4_symbol_sid): Forge a unique symbol
identifier for symbols that don't have an ID.
2020-04-01 08:31:48 +02:00
Akim Demaille
75a605454d yacc.c: prefer YYSYMBOL_YYERROR to YYSYMBOL_error
* data/skeletons/bison.m4 (b4_symbol_sid): Map "error" to YYSYMBOL_YYERROR.
* data/skeletons/yacc.c: Adjust.
2020-04-01 08:31:48 +02:00
Akim Demaille
f3c18c8e80 yacc.c: also define a symbol number for the empty token
This is not only cleaner, it also protects us from mixing signed
values (YYEMPTY is #defined as -2) with unsigned types (the
yysymbol_type_t enum is typically compiled as a small unsigned).
For instance GCC 9:

    input.c: In function 'yyparse':
    input.c:1107:7: error: conversion to 'unsigned int' from 'int'
                           may change the sign of the result
                           [-Werror=sign-conversion]
     1107 |   yyn += yytoken;
          |       ^~
    input.c:1107:10: error: conversion to 'int' from 'unsigned int'
                            may change the sign of the result
                            [-Werror=sign-conversion]
     1107 |   yyn += yytoken;
          |          ^~~~~~~
    input.c:1108:47: error: comparison of integer expressions of
                            different signedness:
                            'yytype_int8' {aka 'const signed char'} and
                            'yysymbol_type_t' {aka 'enum yysymbol_type_t'}
                            [-Werror=sign-compare]
     1108 |   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
          |                                               ^~
    input.c:702:25: error: operand of ?: changes signedness from 'int'
                           to 'unsigned int' due to unsignedness of
                           other operand [-Werror=sign-compare]
      702 | #define YYEMPTY         (-2)
          |                         ^~~~
    input.c:1220:33: note: in expansion of macro 'YYEMPTY'
     1220 |   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
          |                                 ^~~~~~~
    input.c:1220:41: error: unsigned conversion from 'int' to
                            'unsigned int' changes value
                            from '-2' to '4294967294'
                            [-Werror=sign-conversion]
     1220 |   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
          |                                         ^

Eventually, it might be interesting to move away from -2 (which is the
only possible negative symbol number) and use the next available
number, to save bits.  We could actually even simply use "0" and shift
the rest, which would allow to write "!yytoken" to mean really
"yytoken != YYEMPTY".

* data/skeletons/c.m4 (b4_declare_symbol_enum): Define YYSYMBOL_YYEMPTY.
* data/skeletons/yacc.c: Use it.

* src/parse-gram.y (yyreport_syntax_error): Use YYSYMBOL_YYEMPTY, not
YYEMPTY, when dealing with a symbol.

* tests/regression.at: Adjust.
2020-04-01 08:31:48 +02:00
Akim Demaille
00c80bc96c yacc.c: use yysymbol_type_t instead of int for yytoken
Now that we have a proper type for internal symbol numbers, let's use
it.  More code needs conversion, e.g., printers and destructors, but
they are shared with glr.c, which is not ready yet for this change.

It will also help us deal with warnings such as (GCC9 on GNU/Linux):

    input.c: In function 'int yyparse()':
    input.c:475:37: error: enumeral and non-enumeral type in conditional expression [-Werror=extra]
      475 |   (0 <= (YYX) && (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYSYMBOL_YYUNDEF)
          |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    input.c:1024:17: note: in expansion of macro 'YYTRANSLATE'
     1024 |       yytoken = YYTRANSLATE (yychar);
          |                 ^~~~~~~~~~~

* data/skeletons/yacc.c (yytranslate, yysymbol_name)
(yyparse_context_t, yyexpected_tokens, yypstate_expected_tokens)
(yysyntax_error_arguments):
Use yysymbol_type_t instead of int.
2020-04-01 08:31:48 +02:00
Akim Demaille
3ba001baac yacc.c: introduce an enum that defines the symbol's number
There's a number of advantage in exposing the symbol (internal)
numbers:

- custom error messages can use them to decide how to represent a
  given symbol, or a set of symbols.

- we need something similar in uses of yyexpected_tokens.  For
  instance, currently, bistromathic's completion() reads:

    int ntokens = expected_tokens (line, tokens, YYNTOKENS);
    [...]
    for (int i = 0; i < ntokens; ++i)
      if (tokens[i] == YYTRANSLATE (TOK_VAR))
      [...]
      else if (tokens[i] == YYTRANSLATE (TOK_FUN))
      [...]
      else
      [...]

- now that it's a compile-time expression, we can easily build static
  tables, switch, etc.

- some users depended on the ability to get the token number from a
  symbol to write test cases for their scanners.  But Bison 3.5
  removed the table this feature depended upon (a reverse
  yytranslate).  Now they can check against the actual symbol number,
  without having pay (space and time) a conversion.
  See https://lists.gnu.org/r/bug-bison/2020-01/msg00001.html, and
  https://lists.gnu.org/archive/html/bug-bison/2020-03/msg00015.html.

- it helps us clearly separate the internal symbol numbers from the
  external token numbers, whose difference is sometimes blurred in the
  code when values coincide (e.g. "yychar = yytoken = YYEOF").

- it allows us to get rid of ugly macros with inconsistent names such
  as YYUNDEFTOK and YYTERROR, and to group related definitions
  together.

- similarly it provides a clean access to the $accept symbol (which
  proves convenient in a current experimentation of mine with several
  %start symbols).

Let's declare this type as a private type (in the *.c file, not
the *.h one).  So it does not need to be influenced by the api prefix.

* data/skeletons/bison.m4 (b4_symbol_sid): New.
(b4_symbol): Use it.
* data/skeletons/c.m4 (b4_symbol_enum, b4_declare_symbol_enum): New.
* data/skeletons/yacc.c: Use b4_declare_symbol_enum.
(YYUNDEFTOK, YYTERROR): Remove.
Use the corresponding symbol enum instead.
2020-04-01 08:31:33 +02:00
Akim Demaille
4140320a0a style: comment changes about token numbers
* data/skeletons/bison.m4, data/skeletons/c.m4: here.
2020-03-30 08:41:12 +02:00
Akim Demaille
2c74872991 java: move away from _ for internationalization
The "_" is becoming a keyword in Java, which causes tons of warnings
currently in our test suite.  GNU Gettext is now using "i18n" instead
of "_"
(https://git.savannah.gnu.org/gitweb/?p=gettext.git;a=commitdiff;h=e89fea36545f27487d9652a13e6a0adbea1117d0).

* data/skeletons/java.m4: Use "i18n", not "_".
* examples/java/calc/Calc.y, tests/calc.at: Adjust.
2020-03-30 08:03:10 +02:00
Akim Demaille
59d820d1ef c: use YYNOMEM instead of -2
See 84b1972c96.

* data/skeletons/glr.c, data/skeletons/yacc.c (YYNOMEM): New.
Use it.
2020-03-28 15:13:27 +01:00
Akim Demaille
b7045aa706 java: make yysyntaxErrorArguments a private detail
* data/skeletons/lalr1.java (yysyntaxErrorArguments): Move it from the
context, to the parser object.
Generate only for detailed and verbose error messages.
* tests/local.at (AT_YYERROR_DEFINE(java)): Use yyexpectedTokens
instead.
2020-03-28 15:13:27 +01:00
Akim Demaille
ee56b6e0f2 skeletons: make yysyntax_error_arguments a private detail
We could just "inline yysyntax_error_arguments back" in the routines
it was originally extracted from, but I think the code is nicer to
read this way.

* data/skeletons/glr.c (yysyntax_error_arguments): Generate only for
detailed and verbose error messages.
* data/skeletons/yacc.c: Likewise.
* data/skeletons/lalr1.cc (parser::context::yysyntax_error_arguments):
Move as...
(parser::yysyntax_error_arguments_): this.
And only for detailed and verbose error messages.
2020-03-28 15:13:27 +01:00
Akim Demaille
1edc98f793 lalr1.cc: avoid using yysyntax_error_arguments
* data/skeletons/lalr1.cc (context::token): New.
* tests/local.at (yyreport_syntax_error): Don't use
yysyntax_error_arguments.
2020-03-28 15:13:27 +01:00
Akim Demaille
00b0d02955 tests: yacc.c: avoid yysyntax_error_arguments
Because glr.c shares the same testing routines, we also need to
convert it.

* data/skeletons/glr.c (yyparse_context_token): New.
* tests/local.at (yyreport_syntax_error): here.
2020-03-28 15:13:27 +01:00
Akim Demaille
1045c8d0ef examples: don't use yysyntax_error_arguments
Suggested by Adrian Vogelsgesang.
https://lists.gnu.org/archive/html/bison-patches/2020-02/msg00069.html

* data/skeletons/lalr1.java (Context.EMPTY, Context.getToken): New.
(Context.yyntokens): Rename as...
(Context.NTOKENS): this.
Because (i) all the Java coding styles recommend upper case for
constants, and (ii) the Java Skeleton exposes Lexer.EOF, not
Lexer.YYEOF.
* data/skeletons/yacc.c (yyparse_context_token): New.
* examples/c/bistromathic/parse.y (yyreport_syntax_error): Don't use
yysyntax_error_arguments.
* examples/java/calc/Calc.y (yyreportSyntaxError): Likewise.
2020-03-28 15:13:27 +01:00
Akim Demaille
ef8965b5f5 skeletons: fix incorrect type for translatable tokens
* data/skeletons/glr.c, data/skeletons/lalr1.c, data/skeletons/yacc.c:
Fix confusion between the "translatable" and the "translate" tables.
2020-03-28 15:13:27 +01:00
Akim Demaille
84b1972c96 yacc.c: use negative numbers for errors in auxiliary functions
yyparse returns 0, 1, 2 since ages (accept, reject, memory exhausted).
Some of our auxiliary functions such as yy_lac and
yyreport_syntax_error also need to return error codes and also use 0,
1, 2.  Because it uses yy_lac, yyexpected_tokens also needs to return
"problem", "memory exhausted", but in case of success, it needs to
return the number of tokens, so it cannot use 1 and 2 as error code.
Currently it uses -1 and -2, which is later converted into 1 and 2 as
yacc.c expects it.

Let's simplify this and use consistently -1 and -2 for auxiliary
functions that are not exposed (or not yet exposed) to the user.  In
particular this will save the user from having to convert
yyexpected_tokens's -2 into yyreport_syntax_error's 2: both return -1
or -2.

* data/skeletons/yacc.c (yy_lac, yyreport_syntax_error)
(yy_lac_stack_realloc): Return -1, -2 for errors instead of 1, 2.
Adjust callers.
* examples/c/bistromathic/parse.y (yyreport_syntax_error): Do take
error codes into account.
Issue a syntax error message even if we ran out of memory.
* src/parse-gram.y, tests/local.at (yyreport_syntax_error): Adjust.
2020-03-23 07:02:36 +01:00
Akim Demaille
1079595b2a style: reduce length of private constant
* data/skeletons/glr.c, data/skeletons/lalr1.cc, data/skeletons/yacc.c
(YYERROR_VERBOSE_ARGS_MAXIMUM): Rename as...
(YYARGS_MAX): this.
* src/parse-gram.y (YYERROR_VERBOSE_ARGS_MAXIMUM): Rename as...
(ARGS_MAX): this.
2020-03-23 07:02:34 +01:00