简体   繁体   中英

Can an LR(1) parser parse this grammar?

I have the following CFG that I'd like to parse with an LR(1) parser:

S → A | B

A → ε | A

B → ε |B

Can an LR(1) parser parse this grammar? If so, can you show me the parse table? If not, why not and how can you tell?

No, an LR(1) parser cannot parse this grammar. LR(k) parsers can only parse unambiguous grammars, and this grammar is ambiguous (you can derive ε in infinitely many ways).

You can check this by building the configurating sets for the grammar, though that's going to be pretty boring. :-)

Hope this helps!

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