This repository contains my implementation of an interpreter and compiler for a programming language as I follow the book Interpreter and Compiler in Go by Thorsten Ball.
This project is an implementation for the custom programming language. The implementation consists of several key components:
- Lexical Analysis (Lexer): Breaks the input source code into tokens.
- Parsing: Converts the tokens into an Abstract Syntax Tree (AST).
- Evaluation: Interprets and executes the AST.
- ByteCode Compilation: Implementation in progress
- Virtual Machine: Implementation in progress
subject to change
├── ast/ # Abstract Syntax Tree implementation
├── evaluator/ # Code for evaluating the AST
├── lexer/ # Lexer to tokenize the source code
├── object/ # Definitions of Monkey language objects
├── parser/ # Parser to generate AST from tokens
├── repl/ # Read-Eval-Print Loop for interacting with the interpreter
├── token/ # Definitions of tokens
├── main.go # Entry point for running the interpreter
└── README.md # Project information and documentation
Ensure you have Go installed on your system. Then clone the repository and run the interpreter as follows:
git clone https://github.com/srivastavcodes/Flint.git
cd Flint
go run main.goThis will start the REPL (Read-Eval-Print Loop), where you can enter Flint code and see the language's response.
Here's an example of code written in the Monkey language:
let factorial = func(n) {
if (n == 0) {
return 1;
} else {
return n * factorial(n - 1);
}
};
factorial(5); // Outputs 120- Book: Writing an Interpreter in Go Writing a Compiler in Go by Thorsten Ball
This project is licensed under the MIT License. See the LICENSE file for details.