欢迎来到天天文库
浏览记录
ID:41363064
大小:389.31 KB
页数:44页
时间:2019-08-23
《translation(直译)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chap7SemanticProcessingSyntax-directedtranslation(直譯)-analysis:variabledeclarations,typeerrors-synthesis:IR(instructionSet)oractualcodeThesemanticactionisattachedtotheproductions(orsub-treesofasyntaxtree).parsing:buildtheparsetreesemanticprocessing:buildanddecoratetheabs
2、tractsyntaxtree(AST)EX.Non-terminalsforoperatorprecedenceandassociativelyneednotbeincluded.EX.Non-terminalsusedforeaseofparsingmaybeomittedintheabstractsyntaxtree.Chap7SemanticProcessingEx.parsetree(翻譯內容以Tree呈現):=id+*<
3、factor>Constididabstractsyntaxtree(確認所使用的值):=id+*idconstidChap7SemanticProcessingSemanticroutinestraversetheAST,computingattributesofthenodesofAST.Initially,onlyleaves(i.e.terminals,e.g.const,id)haveattributes.Ex.Y:=3*X+I:=id(Y)+*id(I)const(3)id(X)Ex1.咖啡機請幫我泡2杯熱的
4、3杯冰的拿鐵咖啡機end<受詞><數量形容詞><飲料><祈使語><人><動詞>請幫我泡<數量形容詞><數量形容詞tail><數量形容詞><數量形容詞tail><數量><形容詞><數量><形容詞>λ<咖啡>拿鐵2杯熱的3杯冰的Ex2(includeEX1).咖啡機請幫我泡2杯熱的藍山3杯冰的拿鐵咖啡機end<受詞><數量形容詞>//<飲料>請幫我泡<數量形容詞><數量形容詞tail><數量形容詞><數量形容詞tail><數量><形容詞>
5、<飲料>λ<咖啡>藍山2杯熱的3杯冰的<數量><形容詞><飲料><咖啡>拿鐵Chap7SemanticProcessingWethenpropagatetheattributestoothernodes,usingsomefunctions,e.g.-buildsymboltable-attachattributesofnodes-checktypes,etc.bottom-up/top-downpropagationdeclaration:=id+*idconstidexp.typesymboltable
6、checktypes:integer*orfloating*Needtoconsultsymboltablefortypesofid’s.‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘Chap7SemanticProcessingAfterattributepropagationisdone,thetreeisdecoratedandreadyforcodegeneration.WemakeanotherpassoverthedecoratedASTtogeneratecode.Actually,buildingtheASTdecora
7、tingtheASTgeneratingcodethesecanbecombinedinasinglepass.Whatwehavedescribedisessentiallytheattributegrammars(AG).Detailsinchap.14.Chap7SemanticProcessingConceptually:=id+*idconstidAttributesflowintheAST.Chap7SemanticProcessing7.1.26compilerorganizations:<1>1-passanalysis
8、andsynthesisscanningparsingcheckingtranslationinterleavedinasinglepass.Ex.Microcompilerinchap.2.Sinceco
此文档下载收益归作者所有