aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: bbab9ef88822c76d9d26c404322ae07f3ae7ab72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# IMP Interpreter

A small interpreter of the IMP programming language.

## Build

- `make all` to build interpreter.
- `make repl` to run repl.
- `make example` to interpret "example/example.imp".
- `make clean` to remove build folder.

## Dependencies

- [flex](https://github.com/westes/flex)
- [bison](https://www.gnu.org/software/bison)
- [readline](https://tiswww.case.edu/php/chet/readline/rltop.html)

## IMP

[Syntax](/res/syntax.ebnf)

**Statement `<stm>`**
Variable assignment:
- `<var> := <aexp>` any variable not assigned, has the value 0.

Local variable:
- `var <var> := <aexp> in <stm> end`

Control flow:
- `if <bexp> then <stm> else <stm> end`
- `while <bexp> do <stm> end`
- `(<stm>; <stm>)` sequential composition, the first statement runs before the second
- `skip`, nop

**Expression**
Arithmetic Expression `<aexp>`:
- `<num>`
- `<var>`
- `(<aexp> + <aexp>)`
- `(<aexp> - <aexp>)`
- `(<aexp> + <aexp>)`

Boolean Expression `<bexp>`:
- `not <bexp>`
- `(<bexp> or <bexp>)`
- `(<bexp> and <bexp>)`
- `<aexp> = <aexp>`
- `<aexp> # <aexp>` not equals
- `<aexp> < <aexp>`
- `<aexp> <= <aexp>`
- `<aexp> > <aexp>`
- `<aexp> >= <aexp>`

**Variable `<var>`**
- `[a-zA-Z][A-Za-z0-9]*`

**Numeral `<num>`**
- `[0-9]+`