diagnostics: yacc reserves %type to nonterminals

On

    %token TOKEN1
    %type  <ival> TOKEN1 TOKEN2 't'
    %token TOKEN2
    %%
    expr:

bison -Wyacc gives

    input.y:2.15-20: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
        2 | %type  <ival> TOKEN1 TOKEN2 't'
          |               ^~~~~~
    input.y:2.29-31: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
        2 | %type  <ival> TOKEN1 TOKEN2 't'
          |                             ^~~
    input.y:2.22-27: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
        2 | %type  <ival> TOKEN1 TOKEN2 't'
          |                      ^~~~~~

The messages appear to be out of order, but they are emitted when the
error is found.

* src/symtab.h (symbol_class): Add pct_type_sym, used to denote
symbols appearing in %type.
* src/symtab.c (complain_pct_type_on_token): New.
(symbol_class_set): Check that %type is not applied to tokens.
(symbol_check_defined): pct_type_sym also means undefined.
* src/parse-gram.y (symbol_decl.1): Set the class to pct_type_sym.
* src/reader.c (grammar_current_rule_begin): pct_type_sym also means
undefined.
* tests/input.at (Yacc's %type): New.
This commit is contained in:
Akim Demaille
2019-11-16 17:26:51 +01:00
parent 1817b475a6
commit 28d1ca8f48
7 changed files with 141 additions and 28 deletions

View File

@@ -592,11 +592,11 @@ token_decl_for_prec:
;
/*-----------------------.
| symbol_decls (%type). |
`-----------------------*/
/*-----------------------------------.
| symbol_decls (argument of %type). |
`-----------------------------------*/
// A non empty list of typed symbols.
// A non empty list of typed symbols (for %type).
symbol_decls:
symbol_decl.1[syms]
{
@@ -612,10 +612,18 @@ symbol_decls:
}
;
// One or more token declarations.
// One or more token declarations (for %type).
symbol_decl.1:
symbol { $$ = symbol_list_sym_new ($1, @1); }
| symbol_decl.1 symbol { $$ = symbol_list_append ($1, symbol_list_sym_new ($2, @2)); }
symbol
{
symbol_class_set ($symbol, pct_type_sym, @symbol, false);
$$ = symbol_list_sym_new ($symbol, @symbol);
}
| symbol_decl.1 symbol
{
symbol_class_set ($symbol, pct_type_sym, @symbol, false);
$$ = symbol_list_append ($1, symbol_list_sym_new ($symbol, @symbol));
}
;
/*------------------------------------------.