开发者

Need help understanding precedence

Can someone give me a brief description of how to determine the precedence of one thing with respect to another in a grammar? I can't seem to find a good answer in my books or online even though 开发者_开发技巧i'm pretty sure its very simple. Example

S-> B
B-> B and T | T
T-> T or F | F
F-> not F| (B)|true|false

The question was "what is the precedence of "and" with respect to "or" in the above grammar?".

"and" has lower precedence than "or", but I'm not sure why.


The symbol B represents the and statement, and its definition contains T which is the or. You can get from and to or, but not the other way around. So if you think of the language statement as a stack, you'll keep doing replacements and adding to the top of the stack until you wind up evaluating the whole statement, and as you then pop items off you'll reverse direction and the or statement will always be above (and therefore evaluate before) the and. Hope that makes sense.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜