资源描述:
《编译原理与实践(中英双语版)下ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、编译原理与实践CompilerPrincipleandImplementation中英双语版张菁著/黄维通Baikunthnath审1zhangjing@hrbeu.edu.cnChapter6SymbolTableManagerandTypeCheckingZhangJing,WangHaiLingCollegeofComputerScience&TechnologyHarbinEngineeringUniversitysomesymbolsmustbecollectedandbeputtogetherintotables—
2、SymbolTable.Therearetwofunctionsinsymboltable,thefirstoneistohelpcheckifthesemanticiscorrect,thesecondoneistoassistgeneratingthecode.Tosumup,thischapterwouldintroducethefunctions,content,structureandoperationofsymboltable.3zhangjing@hrbeu.edu.cn6.1TheFunctionsofSymbol
3、TablesThefunctionsofsymboltableare:(1)Storeinformation(2)TypesChecking(3)DataAddress4zhangjing@hrbeu.edu.cnStoreinformation:Beforestoreinformation,wefirstlyshoulddividedthedataintodifferenttypes,thenputthemintothecorrespondedtables.Sometimesinformationisstoredintabled
4、uringlexicalanalysis,sometimesitisdoneinsemanticanalysis..Ifthedataisanidentifier,itwouldbestoredinanidentifiertable,elseifthedataisaconstant,itwillbeputintoaconstanttable.5zhangjing@hrbeu.edu.cnTypesCheckingAcompilerusesasymboltabletokeeptrackofthetypeandbindinginfor
5、mationaboutnames.Thesymboltableissearchedeverytimebyanamethatisencounteredinthesourcetext.Ifanewnameornewinformationaboutanexistingnameisdiscovered,thetableischanged.6zhangjing@hrbeu.edu.cnDataAddress:Whenadatawasstored,thedata’saddressinthetablewasalsorecordedasanatt
6、ributeofthetable.Intheperiodofcodegenerationincompiler,thedataaddresscanbeobtainedfromthesymboltableandcanbeuseddirectly..7zhangjing@hrbeu.edu.cn6.2TheAttributeofSymbolTableSymboltableiscreatedaccordingtosymbol’sname,sothekeywordofthesymboltableissymbol’sname.Exceptna
7、meattribute,therearealsosixattributesofasymbolinsymboltableusingforsemanticchecking..8zhangjing@hrbeu.edu.cnThesixattributesofasymbolasfollow:AttributeofkindAttributeofdimensionorsizeAttributeofparameterAttributeofaddressAttributeoflevelinprogramAttributeoflinepositio
8、ninsourceprogram9zhangjing@hrbeu.edu.cnAttributeofkindKindcandescribethecharacteristicsofasymbol.Everysymbolhasitsowntype,su