I've spent 6 hours writing a compiler for the productions below with Lex and Yacc. The terminal report warning: empty rule for typed nonterminal, and no action
but I still can't find out what's wrong with my code.
P -> L | LP
L -> S
S -> ID = E | if C the S | if C then S else S
C -> E>E | E<E | E=E
E -> E T | E-T | T
T -> F | T*F | T/F
F -> (E)| ID
CodePudding user response:
The warning you get seems completely accurate:
F: | …
F
is a non-terminal; it has a type, and the first alternative is empty with no action. If a non-terminal has a production with no action, bison will automatically add the action $$ = $1
, but it can't do that for an empty production, so it complains.
I assume the |
in that line is a typo.