The Hou programming language based on Monkey, but with a little twist on the syntax and features.
Hou ("Monkey" in Chinese).
My go-to project for practicing a new programming language is:
- Thorsten Ball's writing on interpreters (https://interpreterbook.com) and compilers (https://compilerbook.com)
- Bob Nystrom's Crafting Interpreters handbook for making programming languages
I reimplemented Monkey tree-walking interpreter in Go as a learning exercise. The code in this repository closely resembles that presented in Thorsten's book. The interpreter is fully working.
Don't miss out the step-by-step walk-through in this project, where each commit is a fully working part. Read the books and follow along with the commit history.
Start the REPL:
$ go get github.com/cedrickchee/hou
$ hou
This is the Hou programming language!
Feel free to type in commands
>>
Then entering some Hou code:
- Variable bindings
>> let name = "awesome people"
>> puts("Hello " + name)
Hello awesome people
null
- Functions and closures
>> let newAdder = fn(x) { fn(y) { x + y } };
>> let addTwo = newAdder(2);
>> addTwo(3);
5
- Arrays and hash maps
>> let music = [{"song": "We are the World", "singer": "Michael Jackson", "year": 1985}, {"song": "Help!", "singer": "The Beatles", "year": 1965}]
>> music[0]
{song: We are the World, singer: Michael Jackson, year: 1985}
>> music[1]["song"]
Help!
- Errors
>> color = "green"
__,__
.--. .-" "-. .--.
/ .. \/ .-. .-. \/ .. \
| | '| / Y \ |' | |
| \ \ \ 0 | 0 / / / |
\ '- ,\.-"""""""-./, -' /
''-' /_ ^ ^ _\ '-''
| \._ _./ |
\ \ '~' / /
'._ '-=-' _.'
'-----'
Woops! We ran into some monkey business here!
parser errors:
no prefix parse function for = found
To build, run make
.
$ git clone https://github.com/cedrickchee/hou
$ cd hou
$ make
To run the tests, run make test
.
- 1.2 Define token
- 1.3 Lexer (basic)
- 1.4 Lexer (extended)
- 1.5 REPL (basic)
- 2.4 Parser (basic)
- 2.4 Parser (error handling)
- 2.5 Parser (return)
- 2.6 Pratt Parser (prefix)
- 2.6 Pratt Parser (infix)
- 2.8 Parser tracing
- 2.8 Parser (extended)
- 2.9 REPL (read-parse-print-loop)
- 3.4 Evaluation (Object System)
- 3.5 Evaluate Expression (basic)
- 3.5 Complete the REPL
- 3.5 Evaluation (literals)
- 3.5 Evaluation (prefix expressions)
- 3.5 Evaluation (infix expressions)
- 3.6 Evaluation (conditionals)
- 3.7 Evaluation (return statements)
- 3.8 Evaluation (error handling)
- 3.9 Evaluation (bindings and environment)
- 3.10 Evaluation (functions and call expressions)
- 4.2 Data Types (strings)
- 4.2 Data Types (string concatentation)
- 4.3 Builtins (len)
- 4.4 Data Types (arrays)
- 4.4 Arrays (index operator expressions)
- 4.4 Arrays (evaluating array literals)
- 4.4 Arrays (indexing)
- 4.4 Arrays (more built-in functions)
- 4.5 Hash
- 4.6 Hello World