简体   繁体   English

左递归语法中先发现后跟随的混淆

[英]confusion in finding first and follow in left recursive grammar

Recently I faced the problem for finding first and follow最近我遇到了先查找再关注的问题

S->cAd
A->Ab|a

Here I am confused with first of A which one is correct {a} , {empty,a} as there is left recursion in A's production .在这里,我对 A 中的第一个感到困惑,哪个是正确的 {a} , {empty,a} ,因为 A 的产生式中存在左递归。 I am confused whether to include empty string in first of A or not Any help would be appreciated.我很困惑是否在 A 的第一个中包含空字符串 任何帮助将不胜感激。 -------------edited--------------- -------------编辑--------------

what wil be the first and follow of this ,,This is so confusing grammar i have ever seen这个的第一个和后续是什么,这是我见过的如此令人困惑的语法

S->SA|A
A->a

I need to prove this grammar is not in LL(1) using parsing table but unable to do because i didnot get 2 entry in single cell.我需要使用解析表证明此语法不在 LL(1) 中,但无法执行,因为我没有在单个单元格中获得 2 个条目。

Firstly,you'll need to remove left-recursion leading to首先,您需要删除导致

S -> cAd
A -> aA'
A' -> bA' | epsilon

Then, you can calculate然后,你可以计算

FIRST(A) = a         // as a is the only terminal nderived first from A.

EDIT :-

For your second question,对于你的第二个问题,

S -> AS'
S' -> AS' | epsilon
A -> a

FIRST(A) = a
FIRST(S) = a
FIRST(S') = {a,epsilon}.

The idea of removing left-recursion before calculating FIRST() and FOLLOW() can be learnt here .在计算FIRST()FOLLOW()之前去除左递归的想法可以在这里学习。

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

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