电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

编译原理与实践 第四章 答案

编译原理与实践 第四章 答案_第1页
1/6
编译原理与实践 第四章 答案_第2页
2/6
编译原理与实践 第四章 答案_第3页
3/6
The exercises of Chapter Four4、2 Grammar: A → ( A ) A | ε Assume we have lookahead of one token as in the example on p、 144 in the text book、 Procedure A() if (LookAhead() ∈ {‘(‘}) then Call Expect(‘(‘) Call A() Call Expect (‘)’) Call A() else if (LookAhead() ∈ {‘)‘, $}) then return() else /* error */ fi fi end 4、3 Given the grammar statement→ assign-stmt|call-stmt|otherassign-stmt→identifier:=expcall-stmt→identifier(exp-list)[Solution]First, convert the grammar into following forms:statement→ identifier:=exp | identifier(exp-list)|otherThen, the pseudocode to parse this grammar:Procedure statementBeginCase token of( identifer : match(identifer);case token of( := : match(:=); exp;( (: match((); exp-list;match());else error;endcase(other: match(other);else error;endcase;end statement4、7 a Grammar: A → ( A ) A | ε First(A)={(,ε } Follow(A)={$,)}4、7 bSee theorem on P、178 in the text book1.First{(}∩First{ε}=Φ2.ε∈Fist(A), First(A) ∩Follow(A)= Φboth conditions of the theorem are satisfied, hence grammar is LL(1)4、9 Consider the following grammar:lexp→atom|listatom→number|identifierlist→(lexp-seq)lexp-seq→lexp, lexp-seq|lexpa、 Left factor this grammar、b、 Construct First and Follow sets for the nonterminals of the resulting grammar、c、 Show that the resulting grammar is LL(1)、d、 Construct the LL(1) parsing table for the resulting grammar、e、 Show the actions of the corresponding LL(1) parser, given the input string (a,(b,(2)),(c))、[Solution]a、lexp→atom|listatom→number|identifierlist→(lexp-seq)lexp-seq→lexp lexp-seq’lexp-seq’→, lexp-seq|εb、First(lexp)={number, identifier, ( }First(atom)={number, identifier}First(list)={( }First(lexp-seq)={ number, identifier, ( }First(lexp-seq’)={, , ε}Follow(lexp)={, $, } }Follow(at...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

编译原理与实践 第四章 答案

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部