简体   繁体   中英

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 . I am confused whether to include empty string in first of A or not Any help would be appreciated. -------------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.

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 .

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