简体   繁体   中英

Semantic actions on Menhir

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.

在读取整个作品后将触发该事件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM