编译原理与实践 第六 七章 答案

编译原理与实践 第六 七章 答案

ID:47466733

大小:154.51 KB

页数:11页

时间:2020-01-11

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

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

1、TheExercisesofChapterSix6.2应该在num→digit产生式中再加一条语义规则:numd.count=1用来进行初始化。6.46.7ConsiderthefollowinggrammarforsimplePascal-styledeclarations:delc→var-list:typevar-list→var-list,id

2、idtype→integer

3、realWriteanattributegrammarforthetypeofavariable.[Solution]GrammarRuleSemanticRulesdelc→var-list:typev

4、ar-list.type=type.typevar-list1→var-list2,idval-list2.type=var-list1.typeid.type=var-list1.typevar-list→idid.type=var-list.typetype→integertype.type=INTERGERtype→realtype.type=REAL6.10a.DrawdependencygraphscorrespondingtoeachgrammarruleofExample6.14(Page283),andfortheexpression5/2/2.0.b.Describ

5、ethetwopassesrequiredtocomputetheattributesonthesyntaxtreeof5/2/2.0,includingapossibleorderinwhichthenodescouldbevisitedandtheattributevaluescomputedateachpoint.c.Writepseudcodeforproceduresthatwouldperformthecomputationsdescribedinpart(b).[Solution]a.ThegrammarrulesofExample6.14S→expexp→exp/ex

6、p

7、num

8、num.numThedependencygraphsforeachgrammarrule:S→expvalSisFloatetypevalexpexp→exp/expisFloatetypevalexpisFloatetypevalexp/isFloatetypevalexpexp→numisFloatetypevalexpvalnumexp→num.numisFloatetypevalexpvalnum.numThedependencygraphsfortheexpression:5/2/2.0valSIsFloatetypevalexpisFloatetypevale

9、xp/isFloatetypevalexpisFloatetypevalexp/isFloatetypevalexpvalnum.num(2.0)valnumvalnum(5)(2)b.ThefirstpassistocomputetheetypefromisFloat.Thesecondpassistocomputethevalfrometype.Thepossibleorderisasfollows:valS122IsFloatetype3val11exp1isFloat4etypeval9exp/isFloatetypeval10expisFloat5etypeval6exp/

10、isFloat7etypeval8expvalnum.num(2.0)valnumvalnum(5)(2)c.ThepseudcodeprocedureforthecomputationoftheisFloat.FunctionEvalisFloat(T:treenode):BooleanVartemp1,temp2:BooleanBeginCasenodekindofTofexp:temp1=EvalisFloat(leftchildofT);ifrightchildofTisnotnilthentemp2=EvalisFloat(rightchildofT)returntemp1

11、ortemp2elsereturntemp1;num:returnfalse;num.num:returntrue;endFunctionEvalval(T:treenode,etype:integer):VALUEVartemp1,temp2:VALUEBeginCasenodekindofTofS:Return(Evalval(leftchildofT,etype));Exp:Ifetype=EMPTYthenIfEvalisFloat(T)thene

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

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

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