https://github.com/bradford-hamilton/monkey-lang
Currently extending the Monkey programming language designed in the books "Writing An Interpreter In Go" and "Writing a Compiler in Go"
https://github.com/bradford-hamilton/monkey-lang
compilers go golang interpreters languages monkey-language parser
Last synced: 12 days ago
JSON representation
Currently extending the Monkey programming language designed in the books "Writing An Interpreter In Go" and "Writing a Compiler in Go"
- Host: GitHub
- URL: https://github.com/bradford-hamilton/monkey-lang
- Owner: bradford-hamilton
- License: mit
- Created: 2019-08-03T01:23:09.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-10-16T13:19:21.000Z (over 1 year ago)
- Last Synced: 2026-02-01T15:55:16.587Z (about 2 months ago)
- Topics: compilers, go, golang, interpreters, languages, monkey-language, parser
- Language: Go
- Homepage:
- Size: 214 KB
- Stars: 54
- Watchers: 4
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- programming-languages - Monkey in Go
README
[](https://travis-ci.org/bradford-hamilton/monkey-lang)
[](https://goreportcard.com/report/github.com/bradford-hamilton/monkey-lang)
[](https://codecov.io/gh/bradford-hamilton/monkey-lang)
[](https://godoc.org/github.com/bradford-hamilton/monkey-lang)
[](https://golang.org/dl/)
# Monkey Lang
Currently extending the Monkey programming language designed in [_Writing An Interpreter In Go_](https://interpreterbook.com) and [_Writing a Compiler in Go_](https://compilerbook.com) by [Thorsten Ball](https://github.com/mrnugget). I **_highly_** recommend picking up a copy of his books.
I'll formally document the language and it's features at some point, but for now I'm keeping a list of the additional functionality I've added on top of original design.
All additional features (where applicable) have been implemented for both the interpreter and the compiler:
1. Ability to execute Monkey files (.mo file ext) in addition to the interactive console. This is now the default behavior. Add `--console` flag when executing to drop into the REPL instead.
2. Both file execution and console usage respond to an `--engine=` flag where you can choose to use the evaluator or the VM.
3. Logical operators `&&` and `||`
4. Single line comments starting with `//`
5. Multi line comments using `/* */`
6. `const` variable declaration (although it only mocks let at this point until I add variable reassignment)
7. Modulo operator `%`
8. Postfix operators `++` and `--`
9. Comparison operators `>=` and `<=`
10. String comparisons using `!=` and `==`
11. Line numbers throughout the tokens/lexer/parsing/evaluator used for better errors.
12. Ability to have question marks in identifiers. Ex: `has_attribute?`
13. Additional builtin functions:
| Type | Builtin |
|-------------|---------------|
| Array | `pop`, `join` |
| String | `split` |
14. [VS Code syntax highlighting extension](https://github.com/bradford-hamilton/vscode-monkeylang-syntax). Not yet published, but working and provides basic syntax highlighting.
15. Add installation support through [brew](https://brew.sh)
16. Add roughly +20% code coverage
## Installation
_**Option A:**_
```
brew tap bradford-hamilton/monkey
brew install bradford-hamilton/monkey/monkey
```
_**Option B:**_
If you mosey on over to [releases](https://github.com/bradford-hamilton/monkey-lang/releases), you'll find binaries for darwin, linux, windows, and amd64. You can download directly from there.
_**Option C:**_
If you have Go installed on your machine, use `go install`:
```
go install github.com/bradford-hamilton/monkey-lang
```
This will place the binary in your `go/bin` and is ready to use.
## Usage
Build
```
go build -o monkey main.go
```
Run
```
./monkey [option...] filePath
```
## Examples
Running with vm
```
./monkey --engine=vm examples/program.mo
```
Running with evaluator
```
./monkey --engine=eval examples/program.mo
```
Run interactive console
```
./monkey --console
```
## Show your support
Give a ⭐ if this project was helpful in any way!