https://github.com/vahor/interpreter-in-rust
Based on "Writing an interpreter in Go" https://interpreterbook.com/
https://github.com/vahor/interpreter-in-rust
ast interpreter lexer parser rust
Last synced: over 1 year ago
JSON representation
Based on "Writing an interpreter in Go" https://interpreterbook.com/
- Host: GitHub
- URL: https://github.com/vahor/interpreter-in-rust
- Owner: Vahor
- License: mit
- Created: 2023-03-17T21:22:32.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-18T18:51:49.000Z (over 2 years ago)
- Last Synced: 2025-01-22T17:29:00.330Z (over 1 year ago)
- Topics: ast, interpreter, lexer, parser, rust
- Language: Rust
- Homepage:
- Size: 173 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Writing an interpreter in _~~Go~~_ **Rust**
https://interpreterbook.com/

## Why?
I wanted to read this book and I was learning Rust. So I decided to write the interpreter in Rust.
My knowledge of Rust is very limited, so I'm sure there are many things that could be done better. I'm open to suggestions and pull requests.
- In `evaluator.rs` many clones are made, causing multiple issues (push, closure, etc). I'm not sure how to get around this.
- I should use refs, but with lifetime etc it's painful.
## How to run
- `cargo test` to run the tests
- `cargo build --release` to build a release version
- The output will be `target/release/interpreter`
Once built:
- `interpreter -h` to see the help
- `interpreter -f ` to run a file
- You can fine some files in the `examples` folder
- `interpreter -e ` to run an expression
- You can run multiple expressions by separating them with a semicolon
## Builtins
You can find the implementation of the builtins in `evaluator/src/builtins`.
- `len` - returns the length of a string
- `first` - returns the first element of a list
- `last` - returns the last element of a list
- `rest` - returns all elements of a list except the first
- `push` - adds an element to the end of a list
- `pop` - removes the last element of a list
- `print` - prints a value to the console
- `println` - prints a value to the console with a newline