资源描述:
《算术表达式FOLLOW的推理(编译原理).ppt》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、算术表达式FOLLOW的推理文法:ETE’E’+TE’
2、εTFT’T’*FT’
3、εF(E)
4、idFOLLOW(E){$}FOLLOW(T){}FOLLOW(E’){}FOLLOW(T’){}FOLLOW(F){}推理步骤0.FIRST集合FIRST(F)={(,id};FIRST(E)=FIRST(T)={(,id}FIRST(E’)={+,ε};FIRST(T’)={*,ε}规则编号:a、如果存在产生式AαBβ,那么FIRST(β)中所有非ε的符号都在FOLLOW(B)中。b1、如果存在一个产生式AαB,那么FOLLOW(A)中
5、的所有符号都加入到FOLLOW(B)中.b2、或者AαBβ且FIRST(β)包含ε,那么FOLLOW(A)中的所有符号都加入到FOLLOW(B)中.最终答案:E:{$,)}E’:{$,)}T,T’:{+,),$}F:{+,*,),$}即初如化FOLLOW(E){$}FOLLOW(T){}FOLLOW(E’){}FOLLOW(T’){}FOLLOW(F){}1.由E->TE’=>规则a:FIRST(E’)∈FOLLOW(T)=>FOLLOW(T)={+}由E->TE’=>规则b1:FOLLOW(E)∈FOLLOW(E’)=>FOLLOW(E’)
6、={$}由E->TE’=>规则b2:FOLLOW(E)∈FOLLOW(T)=>FOLLOW(T)={+,$}FOLLOW(E){$}FOLLOW(T){+,$}FOLLOW(E’){$}FOLLOW(T’){}FOLLOW(F){}文法:ETE’E’+TE’
7、εTFT’T’*FT’
8、εF(E)
9、idFIRST集合FIRST(F)={(,id};FIRST(E)=FIRST(T)={(,id}FIRST(E’)={+,ε};FIRST(T’)={*,ε}最终答案:E:{$,)}E’:{$,)}T,T’:{+,),$}F:{+,*,),$
10、}1.FOLLOW(E){$}FOLLOW(T){+,$}FOLLOW(E’){$}FOLLOW(T’){}FOLLOW(F){}2.由E’->+TE’=>规则a:FIRST(E’)∈FOLLOW(T)=>FOLLOW(T)={+,$}由E’->+TE’=>规则b1:FOLLOW(E’)∈FOLLOW(E’)=>FOLLOW(E’)={$}由E’->+TE’=>规则b2:FOLLOW(E’)∈FOLLOW(T)=>FOLLOW(T)={+,$}FOLLOW(E){$}FOLLOW(T){+,$}FOLLOW(E’){$}FOLLOW(T’){}
11、FOLLOW(F){}文法:ETE’E’+TE’
12、εTFT’T’*FT’
13、εF(E)
14、idFIRST集合FIRST(F)={(,id};FIRST(E)=FIRST(T)={(,id}FIRST(E’)={+,ε};FIRST(T’)={*,ε}最终答案:E:{$,)}E’:{$,)}T,T’:{+,),$}F:{+,*,),$}FOLLOW(E){$}FOLLOW(T){+,$}FOLLOW(E’){$}FOLLOW(T’){}FOLLOW(F){}3.由T->FT’=>规则a:FIRST(T’)∈FOLLOW(F)=>FOLLOW
15、(F)={}∩{*}={*}由T->FT’=>规则b1:FOLLOW(T)∈FOLLOW(T’)=>FOLLOW(T’)={+,$}由T->FT’=>规则b2:FOLLOW(T)∈FOLLOW(F)=>FOLLOW(F)={+,$}FOLLOW(E){$}FOLLOW(T){+,$}FOLLOW(E’){$}FOLLOW(T’){+,$}FOLLOW(F){+,$}文法:ETE’E’+TE’
16、εTFT’T’*FT’
17、εF(E)
18、idFIRST集合FIRST(F)={(,id};FIRST(E)=FIRST(T)={(,id}FIRST
19、(E’)={+,ε};FIRST(T’)={*,ε}最终答案:E:{$,)}E’:{$,)}T,T’:{+,),$}F:{+,*,),$}FOLLOW(E){$}FOLLOW(T){+,$}FOLLOW(E’){$}FOLLOW(T’){+,$}FOLLOW(F){+,$}4.由T’*FT’=>规则a:FIRST(T’)∈FOLLOW(F)=>FOLLOW(F)={+,$}∩{*}={+,*,$}由T’*FT’=>规则b1:FOLLOW(T’)∈FOLLOW(T’)=>FOLLOW(T’)={+,$}由T’*FT’=>规则b2:FOLLO
20、W(T’)∈FOLLOW(F)=>FOLLOW(F)={+,*,$}FOLLOW(E){$}FOLLOW(T){+,$}FOLLOW(E’){$}FO