Bison, action at the beginning of a rule -
i'm trying build grammar subset of c language. in of rules have following (pnode being pointer defined in union):
rule : { $<pnode>$ = $<pnode>0; } rest however, after reading bison docs, seems action omitted, because $<pnode>0 refers the previous symbol in stack. right? 
it great able omit action, because it's causing shift/reduce conflicts otherwise not appear.
this code duplicates top value on value stack (making duplicate $1 rule), possible unneccessary -- if code uses either of duplicated values can changed instead use unduplicated value, , if none of code attempts modify value on stack (possible, rare , considered poor style).
the problem comes in actions the rest -- if refer $0 , $-1 may have problem.  if refer $0 (and don't modify it) you're fine removing action.
Comments
Post a Comment