欢迎来到天天文库
浏览记录
ID:17336398
大小:213.50 KB
页数:51页
时间:2018-08-30
《cs416 compiler design - ankith m s:cs416编译器设计ankith m s》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Syntax-DirectedTranslationGrammarsymbolsareassociatedwithattributestoassociateinformationwiththeprogramminglanguageconstructsthattheyrepresent.Valuesoftheseattributesareevaluatedbythesemanticrulesassociatedwiththeproductionrules.Evaluationofthesesemanticrules:maygenerateinterme
2、diatecodesmayputinformationintothesymboltablemayperformtypecheckingmayissueerrormessagesmayperformsomeotheractivitiesinfact,theymayperformalmostanyactivities.Anattributemayholdalmostanything.astring,anumber,amemorylocation,acomplexrecord.1CS416CompilerDesignSyntax-DirectedDefin
3、itionsandTranslationSchemesWhenweassociatesemanticruleswithproductions,weusetwonotations:Syntax-DirectedDefinitionsTranslationSchemesSyntax-DirectedDefinitions:givehigh-levelspecificationsfortranslationshidemanyimplementationdetailssuchasorderofevaluationofsemanticactions.Weass
4、ociateaproductionrulewithasetofsemanticactions,andwedonotsaywhentheywillbeevaluated.TranslationSchemes:indicatetheorderofevaluationofsemanticactionsassociatedwithaproductionrule.Inotherwords,translationschemesgivealittlebitinformationaboutimplementationdetails.2CS416CompilerDes
5、ignSyntax-DirectedDefinitionsAsyntax-directeddefinitionisageneralizationofacontext-freegrammarinwhich:Eachgrammarsymbolisassociatedwithasetofattributes.Thissetofattributesforagrammarsymbolispartitionedintotwosubsetscalledsynthesizedandinheritedattributesofthatgrammarsymbol.Each
6、productionruleisassociatedwithasetofsemanticrules.Semanticrulessetupdependenciesbetweenattributeswhichcanberepresentedbyadependencygraph.Thisdependencygraphdeterminestheevaluationorderofthesesemanticrules.Evaluationofasemanticruledefinesthevalueofanattribute.Butasemanticrulemay
7、alsohavesomesideeffectssuchasprintingavalue.3CS416CompilerDesignAnnotatedParseTreeAparsetreeshowingthevaluesofattributesateachnodeiscalledanannotatedparsetree.Theprocessofcomputingtheattributesvaluesatthenodesiscalledannotating(ordecorating)oftheparsetree.Ofcourse,theorderofthe
8、secomputationsdependsonthedependencygraphinducedbythes
此文档下载收益归作者所有