开发者

Bison: Give left precedence to a rule?

With bison i have many %left's (+,*, etc) and开发者_运维百科 a few %right's (=, +=, etc). These are all tokens. Now i have a rule. Its

| rval
| AttrData rval

The problem is, AttrData rval returns an rval so AttrData 1+1 could either be (AttrData 1) +1 or AttrData (1+1). What i like to do is apply the left rule to AttrData BUT that doesnt work cause it isnt a token. I tried %prec and i get an error about it too.

I can fix it by writing | AttrData '(' rval ')' BUT i dont want to do and i rather have the users write AttrData (1+1) since most of the time they'll actually mean (AttrData 1)+1.

How do i give the rule left precedence?

The only thing similar i have is else, which i solved by forcing braces for no confusion (if cond { if cond } else )


You can set explicit precedences will may be help you

IF ELSE example

%nonassoc LOWER_THAN_ELSE

%nonassoc ELSE

%%
stmt   :    IF expr stmt %prec LOWER_THAN_ELSE ;
       |    IF expr stmt ELSE stmt;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜