Hello, i was wondering if someone could help me understand this code
by adding comments explaining each step what happens ?
//answer from lecture
Test := get Label L
End := get Label (L+1)
compile (G,L+2)
emit Test
env1 := compile (G, L+2) exp
emit ifeq END
env2 := compile env1 stm
emit goto Test
emit END
return env2
statements A
while(exp)
{
statements B
}
statements C
is equivalent to pseudo-assembler:
execute statements A
test: execute exp
if exp is false, goto end
execute statements B
goto test
end: execute statements C
perhaps that makes it clearer?