User Tools

Site Tools


ex-imp-interpreter

LiP assignment #6

1. Max

Extend IMP with the expression Max(e1,e2).

Then, extend the interpreter of IMP so to evaluate Max(e1,e2) to the maximum of the values of e1 and e2.


2. Variable initialization

Modify the syntax of IMP, so to allow declarations of the form var x=e, where e is an expression.

Change the interpreter of IMP to deal with it.


3. Exchange

Extend the syntax of IMP with the command Exchange(x,e0,e1), where x is an identifier, and e0,e1 are expressions.

If x is an array identifier, e0 evaluates to i and e1 evaluates to j, then the command Exchange(x,e0,e1) swaps the elements of x at positions i and j.


4. Array index out of bounds

Modify the interpreter of IMP to guarantee that arrays are always accessed within the proper bounds.


5. For loops

Extend the syntax of IMP with the command For(i,e0,e1,c).

If i is a variable, e0 evaluates to v0 and e1 evaluates to v1, then the command For(x,e0,e1,c) executes the command c exactly v1 - v0 times.

The value of i can be read during the loop, but it cannot be changed by the execution of c.


ex-imp-interpreter.txt · Last modified: 2015/10/08 15:20 (external edit)