I am building a small compiler for an assignment language.
Consider the following rule:
var_block :
| LPAREN var_decl+ RPAREN { var_scope := var_scope + 1 };
Is the semantic action triggered when var_block is first recognized or is it triggered once the end of the production is reached (in this case, RPAREN)?
Your question is exactly why you shouldn't do this.
Don't do side-effect which are order-sensitive in production rules. Productions rules should be used to build up a data structure that represent your program. Once this is done, you can analyze/execute/whatever it.