《编译原理》中文版 (李建中 编) 课后习题答案 机械工业出版社
P1774.14 为练习4.3的文法构造一个预测语法分析器bexpr→bexpr or bterm|btermbterm→bterm and bfactor | bfactorbfactor→not bfactor|(bexpr)|true |false解1非递归方法1) 消除左递归①bexpr→bterm A ②A→or btermA ③A→ε④bterm→bfactor B ⑤B→and bfactor B ⑥B→ε⑦bfactor→not bfactor⑧bfactor→(bexpr)⑨bfactor→true ⑩bfactor→false2) 求first集 与 follow集针对以同一非总结符开头的产生式右部求first集如果该非终结符能产生ε则需要求其follow集 ①bexpr→bterm A first(btermA)= {not,(,true,false}②A→or btermA first(or btermA)={or}③A→ε follow(A)=follow(bexpr)= {$, )}④bterm→bfactor B first(bfactor B)={not,(,true,false} ⑤B→and bfactor B first(and bfactor B)={and}⑥B→ε follow(B)=follow(bterm)=first(A)因为first(A)= {or , ε} 包含ε 所以follow(B)=follow(bterm)=first(A) ∪follow(A)-{ε}={or, $, )}⑦bfactor→not bfactor first(not bfactor)={not}⑧bfactor→(bexpr) first((bexpr))={(}⑨bfactor→true first(true)={true}⑩bfactor→false first(false)={false}**** Hidden Message *****
页:
[1]