资源描述:
《编译原理龙书课后部分答案(英文版).doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1)Whatisthedifferencebetweenacompilerandaninterpreter?·Acompilerisaprogramthatcanreadaprograminonelanguage-thesourcelanguage-andtranslateitintoanequivalentprograminanotherlanguage–thetargetlanguageandreportanyerrorsinthesourceprogramthatitdetectsdurin
2、gthetranslationprocess.·Interpreterdirectlyexecutestheoperationsspecifiedinthesourceprogramoninputssuppliedbytheuser.2)Whataretheadvantagesof:(a)acompileroveraninterpretera.Themachine-languagetargetprogramproducedbyacompilerisusuallymuchfasterthananin
3、terpreteratmappinginputstooutputs.(b)aninterpreteroveracompiler?b.Aninterpretercanusuallygivebettererrordiagnosticsthanacompiler,becauseitexecutesthesourceprogramstatementbystatement.3)Whatadvantagesaretheretoalanguage-processingsysteminwhichthecompil
4、erproducesassemblylanguageratherthanmachinelanguage?Thecompilermayproduceanassembly-languageprogramasitsoutput,becauseassemblylanguageiseasiertoproduceasoutputandiseasiertodebug.4.2.3Designgrammarsforthefollowinglanguages:a)Thesetofallstringsof0sand1s
5、suchthatevery0isimmediatelyfollowedbyatleast1.S->SS
6、1
7、01
8、e4.3.1Thefollowingisagrammarfortheregularexpressionsoversymbolsaandbonly,using+inplaceof
9、forunions,toavoidconflictwiththeuseofverticalbarasmeta-symbolingrammars:rexpr->rexpr+rterm
10、rtermrterm->rt
11、ermrfactor
12、rfactorrfactor->rfactor*
13、rprimaryrprimary->a
14、ba)Leftfactorthisgrammar.rexpr->rexpr+rterm
15、rtermrterm->rtermrfactor
16、rfactorrfactor->rfactor*
17、rprimaryrprimary->a
18、bb)Doesleftfactoringmakethegrammarsuitablefortop-downparsing?No,leftrecursionisst
19、illinthegrammar.c)Inadditiontoleftfactoring,eliminateleftrecursionfromtheoriginalgrammar.rexpr->rtermrexpr’rexpr’->+rtermrexpr
20、erterm->rfactorrterm’rterm’->rfactorrterm
21、erfactor->rprimaryrfactor’rfactor’->*rfactor’
22、erprimary->a
23、bd)Istheresultinggramma
24、rsuitablefortop-downparsing?Yes.Exercise4.4.1Foreachofthefollowinggrammars,derivepredictiveparsersandshowtheparsingtables.Youmayleft-factorand/oreliminateleft-recursionfromyourgrammarsfirst.Apredictiveparsermaybederivedbyrecursivedecentorbythe