欢迎来到天天文库
浏览记录
ID:51965772
大小:397.00 KB
页数:108页
时间:2020-03-26
《编译原理2E全套配套课件龙书 Chapter_three(1).ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、COMPILERCONSTRUCTIONPrinciplesandPracticeKennethC.Louden3.Context-FreeGrammarsandParsingPARTONEContentsPARTONE3.1TheParsingProcess[More]3.2Context-FreeGrammars[More]3.3ParseTreesandAbstract[More]3.4Ambiguity[More]PARTTWO3.5ExtendedNotations:EBNFandSyntaxDiagrams3.6
2、FormalPropertiesofContext-FreeLanguages3.7SyntaxoftheTINYLanguageIntroductionParsingisthetaskofSyntaxAnalysisDeterminingthesyntax,orstructure,ofaprogram.ThesyntaxisdefinedbythegrammarrulesofaContext-FreeGrammarTherulesofacontext-freegrammararerecursiveThebasicdatas
3、tructureofSyntaxAnalysisisparsetreeorsyntaxtreeThesyntacticstructureofalanguagemustalsoberecursive3.1TheParsingProcessFunctionofaParserTakesthesequenceoftokensproducedbythescannerasitsinputandproducesthesyntaxtreeasitsoutput.ParserSequenceoftokensSyntax-TreeIssueso
4、ftheParsingThesequenceoftokensisnotanexplicitinputparameterTheparsercallsascannerproceduregetTokentofetchthenexttokenfromtheinputasitisneededduringtheparsingprocess.Theparsingstepofthecompilerreducestoacalltotheparserasfollows:SyntaxTree=parse()IssuesoftheParsingTh
5、eparserincorporatealltheotherphasesofacompilerinasingle-passcompilerNoexplicitsyntaxtreeneedstobeconstructedTheparserstepsthemselveswillrepresentthesyntaxtreeimplicitlybyacallParse()IssuesoftheParsingInMulti-Pass,thefurtherpasseswillusethesyntaxtreeastheirinputThes
6、tructureofthesyntaxtreeisheavilydependentontheparticularsyntacticstructureofthelanguageThistreeisusuallydefinedasadynamicdatastructureEachnodeconsistsofarecordwhosefieldsincludetheattributesneededfortheremainderofthecompilationprocess(i.e.,notjustthosecomputedbythe
7、parser).IssuesoftheParsingWhatismoredifficultfortheparserthanthescanneristhetreatmentoferrors.ErrorinthescannerGenerateanerrortokenandconsumetheoffendingcharacter.IssuesoftheParsingErrorintheparserTheparsermustnotonlyreportanerrormessagebutitmustrecoverfromtheerror
8、andcontinueparsing(tofindasmanyerrorsaspossible)AparsermayperformerrorrepairErrorrecoveryisthereportingofmeaningfulerrormessagesandtheresumptiono
此文档下载收益归作者所有