|
1 | 1 | # Interpreter and Compiler in Golang for Monkey programming language |
2 | 2 |
|
3 | | -Monkey has a C-like syntax, supports variable bindings, prefix and infix operators, has first-class and higher-order functions, can handle closures with ease, and has built-in integers, booleans, arrays and hashes. |
| 3 | +**Monkey** has a C-like syntax, supports variable bindings, prefix and infix operators, has first-class and higher-order functions, can handle closures with ease, and has built-in integers, booleans, arrays and hashes. |
4 | 4 |
|
5 | 5 | Based on Thorsten Ball's books interpreterbook.com and compilerbook.com |
6 | 6 |
|
7 | 7 | **By Raymond Gan** |
8 | 8 |
|
9 | 9 | ## Part 1: Interpreter |
10 | | -- Building an interpreter for a C-like programming language from scratch, with NO 3rd party libraries |
11 | | -- Building a lexer, a parser and an Abstract Syntax Tree (AST) |
| 10 | +- Build an **interpreter** for a C-like programming language from scratch, with NO 3rd party libraries. |
| 11 | +- Build a lexer, a parser, and Abstract Syntax Tree (AST). A **lexer** converts source code to tokens. A **parser** converts tokens to an **Abstract Syntax Tree**. **Tokens** are small, easily categorizable data structures. |
12 | 12 | - The Pratt parsing technique and a recursive descent parser |
13 | | -- Building a REPL |
| 13 | +- Build a REPL |
14 | 14 | - Build a tree-walking evaluator |
15 | 15 |
|
16 | 16 | Monkey language: |
@@ -59,7 +59,7 @@ let getName = fn(person) { person["name"]; }; |
59 | 59 | getName(people[0]); // => "Anna" |
60 | 60 | getName(people[1]); // => "Bob" |
61 | 61 | ``` |
62 | | -In Monkey functions are first-class citizens, treated like any other value. Thus we can use higher-order functions and pass functions around as values: |
| 62 | +In Monkey, functions are first-class citizens, treated like any other value. Thus we can use higher-order functions and pass functions around as values: |
63 | 63 | ``` |
64 | 64 | // Define the higher-order function `map`, that calls the given function `f` |
65 | 65 | // on each element in `arr` and returns an array of the produced values. |
@@ -96,7 +96,7 @@ hello("dear, future Reader!"); // => Hello dear, future Reader! |
96 | 96 | ``` |
97 | 97 | ## Part 2: Compiler |
98 | 98 |
|
99 | | -- Take the lexer, the parser, the AST, the REPL and the object system and use them to build a new, faster implementation of Monkey |
| 99 | +- Take the lexer, parser, AST, REPL and object system and use them to build a new, faster implementation of Monkey. |
100 | 100 | - Change its architecture and turn it into a **bytecode compiler and virtual machine**, from scratch. |
101 | 101 | - Build compiler and VM side-by-side so that we always have a running system to steadily evolve. |
102 | 102 |
|
|
0 commit comments