CSC448: Code Generation: Run-Time Environment I [2/14] Previous pageContentsNext page

Consider a small programming language of expressions and statements:

exp ::= <ID>
      | <INT>
      | exp "+" exp
      | exp "-" exp
      | exp "<=" exp
      | exp "=" exp

stat ::= <ID> ":=" exp
       | "label" <ID>
       | "if" exp "goto" <ID>
       | "print" exp

Suppose that integers represent booleans, e.g., an integer represents true if and only if it is non-zero.

For example, the following program prints numbers from 10 to 0:

x := 3;
goto l2;
label l1;
print (x);
x := x - 1;
label l2;
if (0 <= x) goto l1;

Previous pageContentsNext page