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

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

ID:8917986

大小:75.50 KB

页数:5页

时间:2018-04-12

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

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

1、TheexercisesofChapterThree3.2GiventhegrammarA→AA

2、(A)

3、εa.Describethelanguageitgenerates;b.Showthatitisambiguous.[Solution]:a.Generatesastringofbalancedparenthesis,includingtheemptystring.b.parsetreesof():AAAA()εεA()εA3.3Giventhegrammarexp®expaddopterm

4、

5、termaddop®+

6、-term®termmulopfactor

7、factormulop®*factor®(exp)

8、numberWritedownleftmostderivations,parsetrees,andabstractsyntaxtreesforthefollowingexpression:a.3+4*5-6b.3*(4-5+6)c.3-(4+5*6)[Solution]:a.Theleftmostderivationsfortheexpression3+4*5-6:Exp=>ex

9、paddopterm=>expaddoptermaddopterm=>termaddoptermaddopterm=>factoraddoptermaddopterm=>3addoptermaddopterm=>3+termaddopterm=>3+termmulopfactoraddopterm=>3+factormulopfactoraddopterm=>3+4mulopfactoraddopterm=>3+4*factoraddopterm=>3+4*5addopterm=>3+4*5-te

10、rm=>3+4*5-factor=>3+4*5-63.5WriteagrammarforBooleanexpressionsthatincludestheconstantstrueandfalse,theoperatorsand,orandnot,andparentheses.Besuretogiveoralowerprecedencethanandandandalowerprecedencethatnotandtoallowrepeatednot’s,asintheBooleanexpressi

11、onnotnottrue.Alsobesreyourgrammarisnotambiguous.[solution]bexp→bexporA

12、AA→AandB

13、BB→notB

14、CC→(bexp)

15、true

16、falseEx:notnottrueboolExp→A→B→notB→notnotB→notnotC→notnottrue3.8Giventhefollowinggrammarstatement→if-stmt

17、other

18、εif-stmt→if(exp)statementelse-partel

19、se-part→elsestatement

20、εexp→0

21、1a.Drawaparsetreeforthestringif(0)if(1)otherelseelseotherb.whatisthepurposeofthetwoelse’s?Thetwoelse’sallowtheprogrammertoassociateanelseclausewiththeoutmostelse,whentwoifstatementsarenestedandthefirstdoesnothaveanelseclau

22、se.c.IssimilarcodepermissibleinC?Explain.ThegrammarinClookslike:if-stmt→if(exp)statement

23、if(exp)statementelsestatementthewaytooverride“danglingelse”problemistoenclosetheinnerifstatementin{}s.e.g.if(0){if(1)other}elseother.3.10a.Translatethegrammarofex

24、ercise3.6intoEBNF.b.DrawsyntaxdiagrammsfortheEBNFofpart(a).[Solution]a.Theoriginalgrammarlexp→atom

25、listatom→number

26、identifierlist→(lexp-seq)lexp-seq→lexp-seqlexp

27、lexpTheEBNFoftheabovegrammar:lexp→atom

28、listatom→number

29、identifierlist→(lexp-seq)l

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

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

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