简体   繁体   English

消除左递归,e,左分解?

[英]eliminating left-recursion, e, left-factoring?

I have a grammar 我有语法

S->a{b} S->一个{B}

and I'm trying to rewrite it to avoid using {} . 并且我正在尝试重写它以避免使用{}。 If I write 如果我写

S->a|aB B->b|bB 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 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 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. 到目前为止的愿望是制作不带(e)的语法,该语法适合于预测性分析而不是左递归。

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. 本质上,您可以在语法中删除a部分,然后删除b的第一个部分,它们与您的问题无关。 You have then enumerated all three styles of declaring an infinite number of b's. 然后,您列举了声明无限多个b的所有三种样式。 You'll have to choose one of them. 您必须选择其中之一。

I'd advise to just go with the empty symbol. 我建议只使用空符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM