When I compile the below grammar with bison test.y
, it warns that the nonterminals "header_stms" and "forward" are useless. Why? They are used in the "program" rule. The nonterminal "stm" is not reported useless.
%%
program: /* empty */
| stm
| header_stms
;
header_stms: header_stms forward
;
/* forward proc declaration */
forward: "forward" TK_ID ";"
;
stm: TK_ID "+" TK_ID
;
%%
The rules that use those nonterminals are also deemed useless.
That's because stm doesn't have how to reduce to the program rule, try this:
%%
program: /* empty */
| stm
| header_stms
;
header_stms: /* empty */
| forward
| header_stms forward
;
/* forward proc declaration */
forward: "forward" TK_ID ";"
;
stm: /* empty */
| TK_ID "+" TK_ID
;
%%
Also, I solved your reduce problem in the header_stms, through left recursion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With