tags:

views:

29

answers:

1

I have a Bison rule

block: LBRACE  { some code } decls stmts RBRACE {more code } 
     ;

The issue is in the "more code" section, I have

$$ = $3 ;

Basically, I want the return value of block to be stmts. When I do this, Bison says "$3 of block has no type." If I remove the code block containing some code and stick it into the latter block, bison does not complain. I have stmts and all of its derivatives declared as types. So is this not allowed by Bison? I can make changes to the grammar to accommodate this, but it will be tedious and much easier to just use the above.

+2  A: 

Use $4 to refer to stmts. Since you have a mid-rule action, all proceeding symbol numbers are offset as the action itself can have a value.

The corresponding component numbers are:
$1 LBRACE
$2 { some code }
$3 decls
$4 stmts
$5 RBRACE
$6 { more code }

Jeff M