简体   繁体   中英

eliminating left-recursion, e, left-factoring?

I have a grammar

S->a{b}

and I'm trying to rewrite it to avoid using {} . If I write

S->a|aB B->b|bB

then I'm unable to parse predictively in the second rule. If I write

S->a|aB B->b|Bb

then I become left-recursive in the second rule.

Trying to do left-factoring,

B->bC C->(e)|B

I'm introducing empty symbols. The wish so far is to make grammar without (e), suitable for predictive parsing and not left-recursive.

Is it possible?

I don't think so. Essentially, you can drop the a part in your grammar and the first of the b's, they are not relevant to your problem. You have then enumerated all three styles of declaring an infinite number of b's. You'll have to choose one of them.

I'd advise to just go with the empty symbol.

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