Welcome to my learning journey in crafting interpreters and compilers in Go! This project is inspired by the books "Crafting Interpreters" by Robert Nystrom and "Writing an Interpreter in Go" by Thorsten Ball. My goal is to apply the concepts and techniques from these books to build a robust interpreter and eventually a compiler using Go.
This repository contains my implementation of a programming language interpreter written in Go. The project is divided into several stages, each focusing on different aspects of interpreter and compiler design, including lexical analysis, parsing, semantic analysis, and interpretation.
To get started with the project, you'll need to have Go installed on your machine. You can download and install Go from the official Go website.
Clone the repository:
git clone https://github.com/arsenzairov/crafting-interpreters.git
cd crafting-interpreters
Build and run the interpreter:
go build -o interpreter .
./interpreter
The project is structured as follows:
scanner/
: Contains the lexical analyzer which tokenizes the input source code.parser/
: Contains the parser which generates the Abstract Syntax Tree (AST) from tokens.ast/
: Defines the AST node types and visitor interfaces.interpreter/
: Contains the interpreter that traverses the AST and executes the program.main.go
: The entry point of the interpreter.
- Lexical Analysis: Tokenizes the source code into meaningful tokens.
- Parsing: Constructs an AST from the tokens.
- Interpretation: Executes the program by traversing the AST.
- Error Handling: Provides meaningful error messages with line numbers for easy debugging.
Here are some examples of what you can do with the interpreter:
true && false
5 + (3 * 2)
"Hello, " + "world!"
This project is heavily inspired by the following books:
- Crafting Interpreters by Robert Nystrom
- Writing an Interpreter in Go by Thorsten Ball
Contributions are welcome! If you have any suggestions or improvements, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
Happy coding!