编译原理课件PPT 第4章.pptCHAPTER4SyntaxANALYSISSection0ApproachestoimplementaSyntaxanalyzer1、ThesyntaxdescriptionofprogramminglanguageconstructsContext-freegrammarsBNF(BackusNaurForm)notationNotes:pilerwritersCHAPTER4SyntaxANALYSISSection0ApproachestoimplementaSyntaxanalyzer2、Whyagrammarisusuallyusedtodescribethesyntaxofaprogramminglanguage?Agrammargivesaprecise,yeteasy-to-understand,syntacticspecificationofaprogramminglanguageFromcertainclassesofgrammarwecanautomaticallyconstructanefficientparserthatdeterminesifasourceprogramissyntacticallywellformedCHAPTER4SyntaxANALYSISSection0ApproachestoimplementaSyntaxanalyzer2、Whyagrammarisusuallyusedtodescribethesyntaxofaprogramminglanguage?AproperlydesignedgrammarimpartsastructuretoaprogramminglanguagethatisusefulforthetranslationofsourceprogramsintocorrectobjectcodeandforthedetectionoferrorsTheevolvedconstructscanbeaddedtoalanguagemoreeasilyCHAPTER4SyntaxANALYSISSection0ApproachestoimplementaSyntaxanalyzer3、ApproachedtoimplementasyntaxanalyzerManualconstructionConstructionbytoolsCHAPTER4SyntaxANALYSISSection1TheRoleoftheParser1、urringerrorssothatitcancontinueprocessingtheremainderofitsinputCHAPTER4SyntaxANALYSISSection1TheRoleoftheParser2、pilermodelNotes:pilerLexicalanalyzerParserSymboltableSourceprogramtokenGetnexttokenParsetreeRestoffrontendIntermediaterepresentationCHAPTER4SyntaxANALYSISSection1TheRoleoftheParser3、pilersTOP-DOWNmethodBuildparsetreesfromthetop(root)tothebottom(leaves)TheinputisscannedfromlefttorightLL(1)grammars(oftenimplementedbyhand)BOTTOM-UPmethodStartfromtheleavesandworkuptotherootTheinputisscannedfromlefttorightLRgrammars(oftenconstructedbyautomatedtools)CHAPTER4SyntaxANALYSISSection1TheRoleoftheParser4、SyntaxErrorhandling1)ErrorlevelsLexical,suchasmisspellinganidentifier,keyword,oroperatorSyntactic,suchasanarithmeticexpressionwithunbalancedparenthesesSemantic,patibleoperandLogical,suchasaninfinitelyrecursivecallCHAPTER4SyntaxANALYSISSection1TheRoleoftheParser4、SyntaxErrorhandling2)Simple-to-uratelyItshouldrecoverf
编译原理课件PPT 第4章 来自淘豆网www.taodocs.com转载请标明出处.