简体   繁体   English

将语法简化为LL1

[英]Reducing grammar to LL1

I have the following grammar: 我有以下语法:

A-> AB|CA
B-> Bd | ef
C-> e|f

I removed left recursion as follows and my grammar looks as below: 我按如下所示删除了左递归,语法如下:

A->CAA'
A'-> BA'
A'-> epsilon
B-> efB'
B'->dB'
B'-> epsilon
C->e
C->f

The problem I'm having after this is ambiguity when constructing parse table for this. 为此,我遇到的问题是为此构造解析表时存在歧义。 Can someone point to me in the right direction for this? 有人可以为此指出正确的方向吗? Or I think I'm making mistakes in calculating First and Follow Sets for Parse Table. 或者,我认为我在计算“解析表”的“第一和第二”集时出错。

Edit 编辑

Woops. Woops。 The original grammar does not derive any string of terminals, so trying to make it LL(1) is pointless. 原始语法不会派生任何终端字符串,因此尝试使其为LL(1)是没有意义的。 The first production always produces a form with an A in it, and there is no other derivation from A . 第一次生产总是产生其中带有A的形式,并且没有其他衍生自A Did you skip something or have a typo in your post? 您是否跳过了某些内容或帖子中有错字?

To be fixed: 等待修复:

Your left recursion removal is good. 您的左递归移除效果很好。 Now you need the prediction sets for each production: 现在,您需要每个产品的预测集:

A->CAA'            first(CAA') = { e, f }
A'-> BA'           first(BA') = { e }
A'-> epsilon       follow(A') = follow(A) = { end of input }
B-> efB'           first(efB') = { e }
B'->dB'            first(dB') = { d }
B'-> epsilon       follow(B') = { end of input }
C->e               first(e) = { e }
C->f               first(f) = { f }

There are no ambiguities here because the predict sets of each right hand side corresponding to any given left hand side have null pairwise intersections. 这里没有歧义,因为对应于任何给定左侧的每个右侧的预测集具有空的成对相交。

What ambiguity were you seeing? 您看到了什么歧义?

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

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