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

@@ -38,9 +38,15 @@
/** Symbol classes. */
typedef enum
{
unknown_sym, /**< Undefined. */
token_sym, /**< Terminal. */
nterm_sym /**< Nonterminal. */
/** Undefined. */
unknown_sym,
/** Declared with %type: same as Undefined, but triggered a Wyacc if
applied to a terminal. */
pct_type_sym,
/** Terminal. */
token_sym,
/** Nonterminal. */
nterm_sym
} symbol_class;
@@ -219,7 +225,7 @@ void symbol_precedence_set (symbol *sym, int prec, assoc a, location loc);
/** Set the \c class associated with \c sym.
Whether \c declaring means whether this class definition comes
from %nterm or %token. */
from %nterm or %token (but not %type, prec/assoc, etc.). */
void symbol_class_set (symbol *sym, symbol_class class, location loc,
bool declaring);