資源描述:
《原子語句的中間代碼.ppt》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、原子語句的中間代碼輸入輸出語句:S?Write(E)E.tuple(WRITE,E.Arg);S?Read(V)V.tuple(READ,V.Arg)語法制導(dǎo):S?Read(V)#READS?Write(E)#WRITE賦值語句:賦值語句形式:V:=EVptr:=V1ptrf:=EVstr:=V1str賦值語句的中間代碼形式:(ASSIGN,Arg1,Arg2,n)或(FLOAT,Arg1,Arg2)S?L:=RL.tupleR.tuple(ASSIGN,R,Arg,L.Arg,size)或(FLOAT,R.Arg,L.Arg)語法制導(dǎo):S?L:=R#ASSIGN過函調(diào)用語句S?
2、id(E1,E2,…,En)E1.tuple…En.tuple(ACT,E1.Arg)…(ACT,En.Arg)(CALL,,result)或(CALL,)傳給形參形參實參結(jié)合中間代碼:(VALACT,Ei.Arg,offseti,sizei)……值參(VARACT,Ei.Arg,offseti,sizei)……變參(FUNCACT,Ei.Arg,offseti,sizei)……函數(shù)參數(shù)(PROACT,Ei.Arg,offseti,sizei)……過程參數(shù)過/函調(diào)用代碼:(call,,true,result)靜態(tài)轉(zhuǎn)向地址(call,,false,resul
3、t)動態(tài)轉(zhuǎn)向地址GOTO語句和標號語句的中間代碼LABELL1,L2,...,Ln空S?GOTOLi(JUMP,ARG(Li))S?Li:S(LABEL,ARG(Li))S.tuple結(jié)構(gòu)語句的中間代碼條件語句的中間代碼While語句的中間代碼Repeat語句的中間代碼For語句的中間代碼Case語句的中間代碼條件語句的中間代碼IFETHENS1ELSES2E.Tuple(JUMP0,E.Arg,S.ElseL)S1.Tuple(JUMP,S.OutL)(LABEL,S.ElseL)S2.Tuple(LABEL,S.OutL)IFETHENSE.Tuple(JUMP0,E.Arg
4、,S.OutL)S1.Tuple(LABEL,S.OutL)條件語句代碼生成原理在if處:產(chǎn)生標號S.ElseL和S.OutL;在then處:產(chǎn)生中間代碼(JUMP0,E.Arg,S.ElseL);在else處:產(chǎn)生中間代碼(JUMP,S.OutL)(LABEL,S.ElseL)在S出口處:(LABEL,S.OutL).條件語句代碼生成的LL文法S→if#StartIFEthen#TestIFS1ElsePartElsePart→else#GenJump#GenElseLS2#GenOutLElsePart→?#GenElseL#StartIF:生成兩個標號S.ElseL,S.O
5、utL#TestIF:Generate(JUMP0,E.Arg,S.ElseL)#GenJump:Generate(JUMP,ElsePart.OutL)#GenElseL:Generate(LABEL,ElsePart.ElseL)#GenOutL:Generate(LABEL,ElsePart.OutL)While語句的中間代碼S?WHILEEDOS1E.Tuple(JUMP0,E.Arg,S.OutL)S1.Tuple(JUMP,S.StartL)(LABEL,S.OutL)(LABEL,S.StartL)While語句代碼生成原理當遇While時:產(chǎn)生新標號S.Start
6、L和S.OutL,產(chǎn)生代碼(LABEL,S.StartL)當遇Do時:產(chǎn)生代碼(JUMP0,E.Arg,S.OutL)當遇結(jié)束符時:產(chǎn)生代碼(JUMP,S.StartL)(LABEL,S.OutL)While語句代碼生成的LL文法S→while#StartWhileEdo#WhileTestS1#FinishWhile#StartWhile:產(chǎn)生新標號S.StartL,S.OutL#WhileTest:Generate(JUMP0,E.Arg,S.OutL)#FinishWhile:Generate(JUMP,S.StartL)Generate(LABEL,S.OutL)Repe
7、at語句的中間代碼S?repeatSLuntilESL.Tuple(JUMP0,E.Arg,S.StartL)E.Tuple(LABEL,S.StartL)代碼生成原理和LL動作文法循環(huán)入口處:(LABEL,S.StartL)循環(huán)出口處:(JUMP0,E.Arg,S.StartL)S→repeat#StartRepeatSLdoE#FinishRepeat#StartRepeat:生成S.StartLGenerate(LABEL,S.StartL)#FinishRepeat:Ge