diff options
author | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2025-05-22 12:57:22 +0200 |
---|---|---|
committer | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2025-05-22 12:57:22 +0200 |
commit | 027fc783faa9a25b373099e0e0f86d3859b7235d (patch) | |
tree | 6cbd9265634c5ccc47d3c5b7bd00ede863affd20 | |
parent | be21cdaa9f408535379360b401089c8e2335e818 (diff) | |
download | imp-027fc783faa9a25b373099e0e0f86d3859b7235d.tar.gz imp-027fc783faa9a25b373099e0e0f86d3859b7235d.zip |
updated readme
-rw-r--r-- | README.md | 55 | ||||
-rw-r--r-- | example/example2.imp | 7 | ||||
-rw-r--r-- | examples/example.imp (renamed from example/example.imp) | 0 |
3 files changed, 29 insertions, 33 deletions
@@ -1,14 +1,17 @@ # IMP Interpreter -A small interpreter of the IMP programming language, written in *C* with *flex* for lexing and *bison* for parsing. -Currently the core functionality of IMP is implemented, additionally, the *local variable extension*, and the *procedure extension* also. Furthermore there are some syntactic enhancements, such as the boolean constants `true` and `false`, omitting parenthesis around expressions, and the ability to add arbitrary many semicolons after each statement. +A small interpreter of the IMP programming language, written in *C*, with *flex* for lexing, and *bison* for parsing. + +Currently, the core functionality of IMP is implemented, additionally, the *local variable extension*, and the *procedure extension* are also implemented. + +There are some syntactic enhancements, such as the boolean constants `true` and `false`, omitting parenthesis around expressions and sequential composition, omitting the else block of an if statment, and the ability to add arbitrary many semicolons after each statement. ## Dependencies -- [flex](https://github.com/westes/flex) -- [bison](https://www.gnu.org/software/bison) -- [readline](https://tiswww.case.edu/php/chet/readline/rltop.html) +- [flex](https://github.com/westes/flex) lexer generator +- [bison](https://www.gnu.org/software/bison) parser generator +- [readline](https://tiswww.case.edu/php/chet/readline/rltop.html) handling userinput for repl ## Resources @@ -20,7 +23,7 @@ Currently the core functionality of IMP is implemented, additionally, the *local - `make all` to build interpreter. - `make repl` to run repl. -- `make example` to interpret "example/example.imp". +- `make example` to interpret "examples/example.imp". - `make clean` to remove build folder. All build artifacts are created in the build folder `./build`, including the imp binary (`./build/imp`). @@ -36,7 +39,7 @@ Usage: imp [ARGS] -h print this message ``` -### REPL +REPL: ``` IMP REPL (type IMP statements or commands starting with '%') @@ -51,9 +54,26 @@ Commands: ## IMP +### Example + +``` +procedure factorial(n;r) begin + if n <= 0 then + r := 1; + else + m := n - 1; + factorial(m;r); + r := r * n; + end; +end; + +n := 5; +factorial(n;r); +``` + ### Syntax -[Syntax](/res/syntax.ebnf) + - [Syntax (Reference EBNF)](/res/syntax.ebnf) might not always accurately reflect all syntax rules. (See [parser.y](src/parser.y) for current implemented parsing). **Statement `<stm>`** @@ -115,21 +135,4 @@ Boolean Expression `<bexp>`: **Identifier `<ident>`** -- `[a-zA-Z][A-Za-z0-9]*` - -### Example - -``` -procedure factorial(n;r) begin - if n <= 0 then - r := 1; - else - m := n - 1; - factorial(m;r); - r := r * n; - end; -end; - -n := 5; -factorial(n;r); -```
\ No newline at end of file +- `[a-zA-Z][A-Za-z0-9]*`
\ No newline at end of file diff --git a/example/example2.imp b/example/example2.imp deleted file mode 100644 index 9db6655..0000000 --- a/example/example2.imp +++ /dev/null @@ -1,7 +0,0 @@ -(y := 0; -var x := 5 in - (while x < 10 do - x := (x + 1) - end; - y := x) -end)
\ No newline at end of file diff --git a/example/example.imp b/examples/example.imp index a5bc5dd..a5bc5dd 100644 --- a/example/example.imp +++ b/examples/example.imp |