1
votes

I'm trying to build a grammar for a subset of the C language. In some of my rules I have the following (pNode being a pointer defined in the union):

rule : { $<pNode>$ = $<pNode>0; } the rest

However, after reading the Bison docs, it seems that the action could be omitted, because $<pNode>0 already refers to the previous symbol in the stack. Am I right?

It would be great to be able to omit the action, because it's causing some shift/reduce conflicts that would otherwise not appear.

1

1 Answers

1
votes

This code duplicates the top value on the value stack (making the duplicate $1 for this rule), so it is possible that it is unneccessary -- if all the code that uses either of the duplicated values can be changed to instead use the unduplicated value, and if none of the code attempts to modify the value on the stack (possible, but rare and considered very poor style).

The problem likely comes in the actions for the rest -- if they refer to $0 and $-1 then you may have a problem. If they only refer to $0 (and don't modify it) you're probably fine with removing the action.