资源描述:
《龙书第二章答案snooz_1》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、CS431,Assignment3,BookQuestionsonChapter2PlusOneOtherQuestionQuestionsthatyouneedtoanswerarelistedbelow,andsomesolutionsorpartialsolutionsarealsogiven.Thesolutionsarenotpresentedastheonlypossibleanswers,andwhatisgivenmaynotbecomplete.Itmayonlybeastartingpointforthinkingab
2、outacomplete,correctanswer.Yourgoalinworkingtheproblemsshouldbetocomeupwithasolution,andifindoubtaboutyouranswer,comparewithwhat’sgivenhere.Intheory,evenifyouranswerisnotexactlythesame,youshouldseethesenseorunderstandthedirectionofthesuggestions.Ifyouranswerisatoddswithwh
3、atIhavesuggestedyoumightwanttocheckwithme.ItispossiblethatIamoffbase.Itisalsopossiblethatyouneedsomethingsclarified.Bookproblems:2.1,a-c;2.2,a-e;2.3;2.4,a-e,and2.8.Suggestedanswerstothesequestionsaregivenafterthefollowingquestion.Lastproblem:Thereisanadditionalproblemthat
4、isnotfromthebook.Itisstatedhere.ImplementJavacodethatwillcorrectlytranslateinfixexpressionswith+and–(noparenthesesandnootheroperators)topostfixexpressions.AproblemsolutionisgiveninthebookinCcode,soyourtaskismainlyoneofadaptation.AstartingpointforthisproblemispostedontheWe
5、bpage.YoumayusethefileInfixToPostfixCut.javaasgivenandsimplyaddtheneededmethods.Youcanalsodotheproblemfromscratchifyouwantto.Ithinkitwouldbepreferableifyouleftyourimplementationrecursiveratherthanchangingittoaloop,butthatisyourchoice.Handinaprintoutofthemethodsyouaddedalo
6、ngwithyouranswerstotheproblemslistedabove.Startingpointsforthinkingaboutsolutions:2.1.Considerthefollowingcontext-freegrammarSàSS+(1)SàSS*(2)Sàa(3)a)Showhowthestringaa+a*canbegeneratedbythisgrammar.Production(3)allowsyoutogenerateastringS0whichconsistsofa.UsingS0asastarti
7、ngpoint,production(1)allowsyoutogenerateastringS1whichconsistsofaa+.Production(3)againallowsyoutogenerateastringS2whichconsistsofa.Thenproduction(2)allowsyoutogenerateastringS3=S1S2*=aa+a*.b)Constructaparsetreeforthisstring.SSSSS*+aaac)Whatlanguageisgeneratedbythisgrammar
8、?Justifyyouranswer.Assumingaisanidentifierforanumericvalue,forexample,thenthegrammargeneratesala