开发者

Reason for exactly the same symbols in yacc rules?

identifiers:
    IDENTIFIER
    | identifiers ',' IDENTIFIER
    ;

identifiers_or_typenames:
    identifier
    | identifiers_or_typenames ',' identif开发者_StackOverflowier
    ;

It seems to me that there's no difference between identifiers and identifiers_or_typenames since they evaluates to the same stuff?


I would expect there to be code attached to those cases in practice which distinguishes between the two semantically instead of syntactically. Specifically, the former declaration would dynamically reject <typename>s (yyerror("typename \"%s\" used as identifier", $1); or similar).


Note that yacc is case-sensitive, so IDENTIFIER and identifier are two different things that might have no relation to each other, or might be similar but slightly different in some subtle way. You have to look at how they are defined to tell. I would guess you might well have a rule of the form

identifier: IDENTIFIER | TYPENAME ;

which makes your two rules quite different.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜