正在加载图片...
Or the even snazzier while loop(for loops are left an exercise for the reader) while (a!=10)( Print(a)i a main BeginFuncWithParamsi Var to to Var t1 Ifz t3 Goto L1 LCall PrintInt(a)i aG Endfunc Using tAc with other languages(下面的不做要求) The TAC generation that we have been looking at is fairly generic. Although we have talked about it in the context of Decaf, a tac generator for any programming language would generate the similar sequence of statements. For example, in the dragon book, the following format is used to define the tac generation for a while loop (P. 469 Aho/Sethi/Ullman) s. after newlabel s code gen(s begin :'Or the even snazzier while loop (for loops are left an exercise for the reader): void main() { int a; a = 0; while (a != 10) { Print(a); a = a + 1; } } main: BeginFuncWithParams; Var a; Var _t0; _t0 = 0; a = _t0; _L0: Var _t1; _t1 = 10; Var _t2; _t2 = a == _t1; Var _t3; _t3 = ! _t2; IfZ _t3 Goto _L1; LCall _PrintInt(a); Var _t4; _t4 = 1; Var _t5; _t5 = a + _t4; a = _t5; Goto _L0; _L1: EndFunc; Using TAC with other languages(下面的不做要求) The TAC generation that we have been looking at is fairly generic. Although we have talked about it in the context of Decaf, a TAC generator for any programming language would generate the similar sequence of statements. For example, in the dragon book, the following format is used to define the TAC generation for a while loop. (P. 469 Aho/Sethi/Ullman) S -> while E do S1 { S.begin = newlabel; S.after = newlabel; S.code = gen(S.begin ':')
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有