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

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

ID:32641149

大小:61.07 KB

页数:6页

时间:2019-02-14

编译原理与实践第四章答案_第1页
编译原理与实践第四章答案_第2页
编译原理与实践第四章答案_第3页
编译原理与实践第四章答案_第4页
编译原理与实践第四章答案_第5页
资源描述:

《编译原理与实践第四章答案》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、TheexercisesofChapterFour4.2Grammar:A(A)A

2、eAssumewehavelookaheadofonetokenasintheexampleonp.144inthetextbook.ProcedureA()if(LookAhcad()丘{'('})thenCallExpectCC)CallA()CallExpect(')')CallA()elseif(LookAhead()w$})thenreturn()else/*error*/fiflend4.3Giventhegrammarstatement-^assign-stm

3、t

4、call-stmt

5、otherassign-stmtidentifier:=expcall-stmt-^identifier(exp-list)[Solution]First,convertthegrammarintofollowingforms:statementidentifier:=cxp

6、identifier(exp-list)

7、otherThen,thepseudocodetoparsethisgrammar:ProcedurestatementBeginCasetokenof(identifer:match(identifer);caset

8、okenof(:=:match(:=);exp;((:match(();exp-list;match());elseeiTor;endcase(other:match(other);elseerror;endcase;endstatement4.7aGrammar:A—>(A)A

9、cFirst(A)={(,£}Follow(A)={$,)}4.7bSeetheoremonP.178inthetextbook1.First{(}nFirst{E}=0>2.£WFist(A),First(A)AFollow(A)=(I)bothconditionsofthet

10、heoremaresatisfied,hencegrammarisLL(1)4.9Considerthefollowinggrammar:lexpfatom卩istatom-^numbcrlidcntificrlist—(lexp-seq)lexp-seq-^lexp,lexp-seq

11、lexpa.Leftfactorthisgrammar.b.ConstructFirstandFollowsetsforthenontenninalsoftheresultinggrammar.c.ShowthattheresultinggrammarisLL(1).d.C

12、onstructtheLL(1)parsingtablefortheresultinggramma匚e.ShowtheactionsofthecorrespondingLL(1)parser,giventheinputstring(a,(b,(2)),(c))・[Solution]a.lexpfatom卩istatom-*number

13、identifierlist—(lcxp・scq)lexp-seq-^lexplexp-seq^lexp-seqJ,lexp-seq

14、£b.First(lexp)={number,identifier,(}First(ato

15、m)={number,identifier}First(list)={(}First(lcxp-scq)={number,identifier,(}First(1exp-seq5)={,,£}Follow(lexp)={,$,}}Fol1ow(atom)={,$,}}Follow(list)={,$,}}Follow(lexp-seq)={$,}}Follow(lexp-seq')={SJ}c.AccordingtothedefinationofLL(1)grammar(Page155),theresultinggrammarisLL(1)aseachta

16、bleentryhasatmostoneproductionasshownin(d).d.TheLL(1)parsingtablefbrtheresultinggrammarM[N,T]numberidentifer()$Lexplexpfatomlexpatomlexp-*listAtomatom—numberatom—identifierListlist(lexp-seq)Lexp-seqlexp-seq—lexplexp-seq5lexp-seq—lexplexp-seq'lexp-seq—lexplexp-seq'Lexp-seq5lexp-seq

17、'->elexp-seq?—,lexp-seqlexp-seq5—

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。