[英]First and follow in the following grammar
The following grammar is given:-给出了以下语法:-
E->E+T|T
T->T*F|F
F->id
I have tried to find the first and follow.我试图找到第一个并跟随。 Can anyone verify it whether its correct???
任何人都可以验证它是否正确???
First(E)={id}
First(T)={id}
First(F)={id}
Follow(E)={+,id}
Follow(T)={+}
Follow(F)={id,*}
FIRST sets are correct,第一组是正确的,
FOLLOW(A) of non-terminal A is the set of terminal symbols that can follow in the
derivation sequence
FOLLOW(E), check where it is there in the right-hand side of production. FOLLOW(E),检查它在生产右侧的位置。 It is there in
它在那里
E->E+T
what follows E when we consider this production for derivation is '+' and '$'(End of Input) is also added to the follow of start symbol当我们认为这个产生式用于推导时,E 后面的是'+'并且'$'(输入结束)也被添加到开始符号的后面
FOLLOW(E) ={+,$}
FOLLOW(T), it is there in right-hand side of three productions FOLLOW(T),在三个产生式的右边
E-> E+T E->T T->T*F
FOLLOW(T)={*} U FOLLOW(E)={*,+,$}
FOLLOW(F), it is there in right-hand side of two productions FOLLOW(F),它在两个产生式的右边
T->T*F T->F
FOLLOW(F)=FOLLOW(T)={*,+,$}
If you are doing this exercise for computing LL(1) parsing table then first eliminate left recursion and proceed.如果你正在做这个练习来计算 LL(1) 解析表,那么首先消除左递归并继续。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.