A simple compiler written in Go, designed for educational and experimental purposes. It features a hand-written lexer, parser, and evaluator for a basic scripting language.
- Tokenizer (lexer) for source code
- Recursive descent parser
- AST (Abstract Syntax Tree) generation
- REPL for live testing
- Interpreter/evaluator for expressions and statements
- Written 100% in Go with no external dependencies
/compiler
β
βββ lexer/ # Tokenizing logic
βββ parser/ # Parsing expressions/statements into AST
βββ ast/ # AST node definitions
βββ token/ # Token type definitions
βββ evaluator/ # Executes parsed AST
βββ repl/ # REPL interface
βββ main.go # Entry point
- Go 1.18 or higher
- Clone the repository:
git clone https://github.com/yourusername/go-compiler.git
cd go-compiler
- Run the REPL:
go run main.go
You should see:
>> let five = 5;
>> five + 10;
15
let name = "Mohit";
let age = 25;
age + 5;
Each component (lexer, parser, etc.) has its own _test.go
files.
To run all tests:
go test ./...
- Add support for functions
- Support conditionals (if/else)
- Handle escape characters in strings
- Add error recovery in parser
- Add support for arrays and hash maps
MIT License
Built as a learning project inspired by the Monkey Programming Language by Thorsten Ball.