Introduce a symbol table phase for URM to make "programming" a little less messy:
- Map every label
<LBL>
to the matching line number (output:{<LBL1>: <NO1>, <LBL2>: <NO2>}, ...}
).- A label is defined as
LBL: \<[A-Z0-9_]+\>;
- Advantage: "Normal" line numbers can still be used with the expression defined above.
- A label is defined as
- Replace evert
<LBL>
with the actual line number using the output of 1.
For the given while V1 != V2 do begin α end
a transformation to URM could look as follows:
in(V1, V2);
loc(T1, T2);
<COP1>: COPY(V1, T1);
<COP2>: COPY(V2, T2);
<TEST_T1>: if T1 == 0 goto <TEST_T2>;
<ELSE>: if T2 == 0 goto <WHILEBODY>;
<T1>: T1--;
<T2>: T2--;
<GO_BACK>: goto <TEST_T1>;
<TEST_T2>: if T2 == 0 goto <ABORT>;
<WHILEBODY>: α
<LOOP>: goto <COP1>;
<ABORT>: ...
- Temp variables
T1, T2
are needed becauseα
could have dependent calculations onV1
orV2
. That is why we cannot work on them directly. - For the same reason described above,
V1
andV2
are consequently copied in each iteration/loop.