I am trying to implement a compiler from the book “The Unix Programming Environment” by Brian Kernighan and Rob Pike, 1984. The book assumes yacc, however I am using a Mac which has bison version 2.3. The code question is described on page 276 in the book.
I am getting warnings from a piece of the grammar/actions that make use of embedded actions (yacc lingo), which I think is the same as mid-rule actions in bison.
Below, is the piece of grammar that generates warnings (line numbers are from listing):
158: defn: FUNC procname { $2->type=FUNCTION; indef=1; }
159: '(' ')' stmt { code(procret); define($2); indef=0; }
160: | PROC procname { $2->type=PROCEDURE; indef=1; }
161: '(' ')' stmt { code(procret); define($2); indef=0; }
162: ;
163:
164:
165: procname: VAR
166: | FUNCTION
167: | PROCEDURE
168: ;
Below are the warnings from Bison:
7 rules never reduced
hoc.y: warning: 4 useless nonterminals and 7 useless rules
hoc.y:158.1-4: warning: useless nonterminal: defn
hoc.y:158.29-59: warning: useless nonterminal: @1
hoc.y:160.29-60: warning: useless nonterminal: @2
hoc.y:47.17-24: warning: useless nonterminal: procname
hoc.y:158.29-59: warning: useless rule: @1: /* empty */
hoc.y:158.7-159.67: warning: useless rule: defn: FUNC procname @1 '(' ')' stmt
hoc.y:160.29-60: warning: useless rule: @2: /* empty */
hoc.y:160.7-161.67: warning: useless rule: defn: PROC procname @2 '(' ')' stmt
hoc.y:165.11-13: warning: useless rule: procname: VAR
hoc.y:166.7-14: warning: useless rule: procname: FUNCTION
hoc.y:167.7-15: warning: useless rule: procname: PROCEDURE
Is it possible that the grammar/actions are acceptable to yacc and not bison? If so, does bison have a ‘yacc mode’? If not, how should the grammar/actions be rewritten to be acceptable to bison? Thanks
defnactually used elsewhere? If you do add something using it and related to the top-level symbol, do any warnings remain? - ascheplerprocnameis odd. I don't think we can help much without an MCVE (Minimal, Complete, Verifiable Example — or MRE or whatever name SO now uses) or an SSCCE (Short, Self-Contained, Correct Example). That means removing most of the lines from line 1 through 157 — but leaving enough that your problem still occurs, albeit with different line numbers. Given theuseless rulewarnings, though, it is fairly clear that you don't havedefnin use on the RHS of a definition —some_non_terminal: … defn …- Jonathan Leffler