标签:src follow psi nbsp alt eps strong upload loading
1.将以下文法消除左递归,分析符号串 i*i+i 。
并分别求FIRST集、FOLLOW集,和SELECT集
E -> E+T | T
T -> T*F | F
F -> (E) | i
解:消除左递归:
E -> TE’
E’ -> +TE’ | ε
T -> FT’
T’ -> *FT’ | ε
F -> (E) | i
分析符号串i*i+i:
first集:
FIRST(TE‘)={ (, i }
FIRST(+TE‘)={+}
FIRST(ε)={ε}
FIRST(FT‘)={ (, i }
FIRST(*FT‘)={*}
FIRST((E))={ ( }
FIRST(i)={i}
follow集:
FOLLOW(E)={ ),# }
FOLLOW(E‘)={ ),# }
FOLLOW(T)={+,),#}
FOLLOW(T‘)={+,),#}
FOLLOW(F)={*,+,),#}
select集:
SELECT(E->TE‘)=FIRST(TE‘)={ (, i }
SELECT(E‘->+TE‘)=FIRST(+TE‘)={+}
SELECT(E‘->ε)=FIRST(ε)-{ε}UFOLLOW(E‘)=FOLLOW(E‘)={ ),# }
SELECT(T->FT‘)=FIRST(FT‘)={ (,i }
SELECT(T‘->*FT‘)=FIRST(*FT‘)={*}
SELECT(T‘->ε)=FIRST(ε)-{ε}UFOLLOW(T‘)=FOLLOW(T‘)={ +,),# }
SELECT(F->(E))=FIRST((E))={ ( }
SELECT(F->i)=FIRST(i)={i}
2.P101练习7(2)(3)文法改写,并分别求FIRST集、FOLLOW集,和SELECT集
(2).
A-->aA‘
A‘-->ABe | ε
B-->bB‘ | d
B‘-->*b | ε
FIRST集:
FIRST(aA‘)={a}
FIRST(ABe)={a | A-->a}
FIRST(ε)={ε}
FIRST(bB‘)={b}
FIRST(d)={d}
FIRST(*b)={*}
FOLLOW集:
FOLLOW(A)=FIRST(B)={b}
FOLLOW(A‘)={#}
FOLLOW(B)={e}
FOLLOW(B‘)={#}
SELECT集:
SELECT(A-->aA‘)=FIRST(aA‘)={a}
SELECT(A‘-->ABe)=FIRST(ABe)={a | A-->a}
SELECT(A‘-->ε)=FOLLOW(A‘)={#}
SELECT(B-->bB‘ )=FIRST(bB‘)={b}
SELECT(B-->d)=FIRST(d)={d}
SELECT(B‘-->*b)=FIRST(*b)={*}
SELECT(B‘-->ε)=FOLLOW(B‘)={#}
(3).
课堂练习:
求以下文法的FIRST集、FOLLOW集和SELECT集。
S->Ap
A->a |ε
A->cA
A->aA
S->Ap
S->Bq
A->a
A->cA
B->b
B->dB
标签:src follow psi nbsp alt eps strong upload loading
原文地址:https://www.cnblogs.com/Gidupar/p/11869743.html