diff options
author | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2025-05-21 07:45:30 +0200 |
---|---|---|
committer | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2025-05-21 07:45:30 +0200 |
commit | 5a90102b20d18966b69496d85361d14c085479db (patch) | |
tree | c44f7c89f84841131f248fbaf2f85bca13517c2f /README.md | |
parent | 40cccdb7cc472ee6300c25e1774a8489e9107f6a (diff) | |
download | imp-5a90102b20d18966b69496d85361d14c085479db.tar.gz imp-5a90102b20d18966b69496d85361d14c085479db.zip |
syntax doc
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 44 |
1 files changed, 43 insertions, 1 deletions
@@ -13,4 +13,46 @@ A small interpreter of the IMP programming language. - [flex](https://github.com/westes/flex) - [bison](https://www.gnu.org/software/bison) -- [readline](https://tiswww.case.edu/php/chet/readline/rltop.html)
\ No newline at end of file +- [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]+` |