IMP: a simple imperative language We shall now consider a more realistic programming language, one where we can assign values to variables and execute control constructs such as "if" and "while". The syntax for this simple imperative language, called IMP, is as follows: expressions e in Expr = Aexp union Bexp arithmetic expressions a in Aexp a ::= x | n | a1 + a2 boolean expressions b in Bexp b ::= true | false | a1 < a2 commands c in Com c ::= skip | x := a | c1 ; c2 | if b then c1 else c2 | while b do c We'll first give a small-step operational model for IMP. The configurations in this language are of the form , , and , where s is a store. And the final configurations are , , , and . We need to define the one-step evaluation relations for commands and expressions: -> , -> , -> . The evaluation rules for arithmetic and boolean expressions are similar to the ones we've seen before. For commands, the rules are: -> --------------------- --------------------- -> -> s[x -> n] -> ----------------------- ------------------- -> -> For if commands, we gradually reduce the test until we get either true or false; then, we execute the appropriate branch: -> ------------------------------------------------------- -> -------------------------------------- -> -------------------------------------- -> For while loops, the above strategy doesn't work (why?). Instead, we can use the following rule: ----------------------------------------------------------------- -> We can now take a concrete program and see how it executes under the above rules. Consider we start with state s = {x=0} and we execute the program: x := 3; while (x < 4) do x := x + 5 The execution works as follows: -> -> (where s'=s[x->3]) -> -> -> -> -> -> -> -> (where s'' = s'[x->8]) -> -> -> -> (where W is an abbreviation for the while loop "while (x < 4) do x := x + 5").