开发者

What does it mean when yacc {code} are in the middle?

开发者 https://www.devze.com 2023-02-17 08:56 出处:网络
extdefs: {$<ttype>$ = NULL_TREE; } extdef extdefs {$<ttype>$ = NULL_T开发者_开发技巧REE; } extdef
extdefs:
    {$<ttype>$ = NULL_TREE; } extdef
    | extdefs {$<ttype>$ = NULL_T开发者_开发技巧REE; } extdef
    ;

Why is it in the middle?


It could be everywhere. Sometimes it's useful to have something done in between the tokens, especially in this kind of or expressions.

In the standard description of the yacc utility it's said that:

Actions can occur anywhere in a rule (not just at the end); an action can access values returned by actions to its left, and in turn the value it returns can be accessed by actions to its right. An action appearing in the middle of a rule shall be equivalent to replacing the action with a new non-terminal symbol and adding an empty rule with that non-terminal symbol on the left-hand side. The semantic action associated with the new rule shall be equivalent to the original action. The use of actions within rules might introduce conflicts that would not otherwise exist.

0

精彩评论

暂无评论...
验证码 换一张
取 消