WHILE
InterpreterWHILE
?WHILE
is a simple imperative programming language. It is used to learn the basic concepts
of parsing, understanding, compiling verifying and executing programs.
WHILE
is very constrained. This allows a
simple machine like human brain to understand and analyze the programs. It consists of:
x
)x := 1
)x := 1 + 2
)x > 0
)while x > 0 do x := x - 1 end
)if x > 0 then x := x - 1 else x := x + 1 end
)(For full mathematical definition of the language, see here)
while
loop. We can't determine if your program will terminate,
so if your browser freezes, you were warned! If you know how to check if an arbitrary program
terminates, please let us know!x | y |
---|---|
1 | 6 |
6 Steps
Step | Instruction | PC | Stack | State |
---|---|---|---|---|
1 | PUSH( 1 ) | 1 | [1] | { x → 3 } |
2 | STO( y ) | 2 | [] | { x → 3; y → 1 } |
3 | LOAD( x ) | 3 | [3] | { x → 3; y → 1 } |
4 | PUSH( 1 ) | 4 | [3:1] | { x → 3; y → 1 } |
5 | EQ | 5 | [false] | { x → 3; y → 1 } |
6 | NOT | 6 | [true] | { x → 3; y → 1 } |
7 | JMPF( 17 ) | 7 | [] | { x → 3; y → 1 } |
8 | LOAD( y ) | 8 | [1] | { x → 3; y → 1 } |
9 | LOAD( x ) | 9 | [1:3] | { x → 3; y → 1 } |
10 | MULT | 10 | [3] | { x → 3; y → 1 } |
11 | STO( y ) | 11 | [] | { x → 3; y → 3 } |
12 | LOAD( x ) | 12 | [3] | { x → 3; y → 3 } |
13 | PUSH( 1 ) | 13 | [3:1] | { x → 3; y → 3 } |
14 | SUB | 14 | [2] | { x → 3; y → 3 } |
15 | STO( x ) | 15 | [] | { x → 2; y → 3 } |
16 | JMP( 3 ) | 2 | [] | { x → 2; y → 3 } |
17 | LOAD( x ) | 3 | [2] | { x → 2; y → 3 } |
18 | PUSH( 1 ) | 4 | [2:1] | { x → 2; y → 3 } |
19 | EQ | 5 | [false] | { x → 2; y → 3 } |
20 | NOT | 6 | [true] | { x → 2; y → 3 } |
21 | JMPF( 17 ) | 7 | [] | { x → 2; y → 3 } |
22 | LOAD( y ) | 8 | [3] | { x → 2; y → 3 } |
23 | LOAD( x ) | 9 | [3:2] | { x → 2; y → 3 } |
24 | MULT | 10 | [6] | { x → 2; y → 3 } |
25 | STO( y ) | 11 | [] | { x → 2; y → 6 } |
26 | LOAD( x ) | 12 | [2] | { x → 2; y → 6 } |
27 | PUSH( 1 ) | 13 | [2:1] | { x → 2; y → 6 } |
28 | SUB | 14 | [1] | { x → 2; y → 6 } |
29 | STO( x ) | 15 | [] | { x → 1; y → 6 } |
30 | JMP( 3 ) | 2 | [] | { x → 1; y → 6 } |
31 | LOAD( x ) | 3 | [1] | { x → 1; y → 6 } |
32 | PUSH( 1 ) | 4 | [1:1] | { x → 1; y → 6 } |
33 | EQ | 5 | [true] | { x → 1; y → 6 } |
34 | NOT | 6 | [false] | { x → 1; y → 6 } |
35 | JMPF( 17 ) | 16 | [] | { x → 1; y → 6 } |