At FOR '(' expr1 ';' L1 expr2 ';' L2 expr3 N1 ')' L3 stmt N2
we will have this scenario:
backpatch( $14 , $8 - $14 );
backpatch( $10 , $5 - $10 );
backpatchlist( $6.truelist , $12 );
backpatchlist( $6.falselist , pc );
- First line: When we are at end of LOOP (
N2
), we must jump to first of Increment Section of the loop (L2
) to compute expr3
- Second line: After computing
expr3
, must jump to first of Test Expression section expr2
- Third line: if evaluation of
expr2
is true, jump to first of LOOP's Body (L3
) to compute stmt
.
- Fourth line: if evaluation of
expr2
is false, processing the loop has been finished and we must jump the first instruction after LOOP which is accessible by pc
.
In this condition the markers must be defined as this:
L1,L2,L3 : {
$$ = pc;
}
N1 : {
emit(pop);
$$ = pc;
emit3(goto_, 0);
}
N2 : {
$$ = pc;
emit3(goto_, 0);
}