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

@@ -195,6 +195,55 @@ input.y:7.4-9: warning: POSIX Yacc does not support %empty [-Wyacc]
AT_CLEANUP
## -------------- ##
## Yacc's %type. ##
## -------------- ##
AT_SETUP([Yacc's %type])
AT_DATA([input.y],
[[%token TOKEN1
%nterm nterm1
%type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
%token TOKEN2
%nterm nterm2
%%
expr: nterm1 nterm2 nterm3
nterm1: TOKEN1
nterm2: TOKEN2
nterm3: "TOKEN3"
]])
AT_BISON_CHECK([-fcaret -Wyacc input.y], [0], [],
[[input.y:2.1-6: warning: POSIX Yacc does not support %nterm [-Wyacc]
2 | %nterm nterm1
| ^~~~~~
input.y:3.14-19: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
| ^~~~~~
input.y:3.28-35: warning: POSIX Yacc does not support string literals [-Wyacc]
3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
| ^~~~~~~~
input.y:3.28-35: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
| ^~~~~~~~
input.y:3.58-60: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
| ^~~
input.y:5.1-6: warning: POSIX Yacc does not support %nterm [-Wyacc]
5 | %nterm nterm2
| ^~~~~~
input.y:3.21-26: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
| ^~~~~~
input.y:10.9-16: warning: POSIX Yacc does not support string literals [-Wyacc]
10 | nterm3: "TOKEN3"
| ^~~~~~~~
]])
AT_CLEANUP
## ----------------------------- ##
## Invalid symbol declarations. ##
## ----------------------------- ##