mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-10 12:53:03 +00:00
grammar: warn about unused precedence for symbols
Symbols with precedence but no associativity, and whose precedence is never used, can be declared with %token instead. The used precedence relationships are recorded and a warning about useless ones is issued. * src/conflicts.c (resolve_sr_conflict): Record precedence relation. * src/symtab.c, src/symtab.h (prec_nodes, init_prec_nodes) (symgraphlink_new, register_precedence_second_symbol) (print_precedence_warnings): New. Record relationships in a graph and warn about useless ones. * src/main.c (main): Print precedence warnings. * tests/conflicts.at: New.
This commit is contained in:
committed by
Akim Demaille
parent
fbecd2ab59
commit
284bc49c83
@@ -78,7 +78,15 @@ int main (void)
|
||||
}
|
||||
]])
|
||||
|
||||
AT_FULL_COMPILE([input])
|
||||
AT_BISON_CHECK([-o input.c input.y], [], [],
|
||||
[[input.y:24.13: warning: useless precedence for R [-Wother]
|
||||
input.y:24.15: warning: useless precedence for S [-Wother]
|
||||
input.y:24.17: warning: useless precedence for T [-Wother]
|
||||
input.y:24.19: warning: useless precedence for U [-Wother]
|
||||
input.y:25.13: warning: useless precedence for V [-Wother]
|
||||
input.y:25.15: warning: useless precedence for W [-Wother]
|
||||
]])
|
||||
AT_COMPILE([input])
|
||||
|
||||
AT_PARSER_CHECK([./input])
|
||||
|
||||
@@ -87,6 +95,49 @@ AT_BISON_OPTION_POPDEFS
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ---------------------------- ##
|
||||
## Useless precedence warning. ##
|
||||
## ---------------------------- ##
|
||||
|
||||
AT_SETUP([Useless precedence warning])
|
||||
|
||||
AT_DATA([[input.y]],
|
||||
[[%token A B
|
||||
%precedence Z
|
||||
%left X
|
||||
%precedence Y
|
||||
%left W
|
||||
%right V
|
||||
%nonassoc U
|
||||
%%
|
||||
a: b
|
||||
| a U b
|
||||
| f
|
||||
;
|
||||
b: c
|
||||
| b V c
|
||||
;
|
||||
c: d
|
||||
| c W d
|
||||
;
|
||||
d: A
|
||||
| d X d
|
||||
| d Y A
|
||||
;
|
||||
f: B
|
||||
| f Z B
|
||||
;
|
||||
]])
|
||||
|
||||
AT_BISON_CHECK([-fcaret -o input.c input.y], 0, [],
|
||||
[[input.y:2.13: warning: useless precedence for Z [-Wother]
|
||||
%precedence Z
|
||||
^
|
||||
]])
|
||||
|
||||
AT_CLEANUP
|
||||
|
||||
|
||||
## ---------------- ##
|
||||
## S/R in initial. ##
|
||||
## ---------------- ##
|
||||
|
||||
Reference in New Issue
Block a user