I am starting this project on 2024-08-28 The Code will be written on a Raspberry pi zero 2W Just to maybe challange myself and prove that a complex level project can be made in simplest machine (Cost of a raspberry pi zero 2 W at this time in india is around 1.5k rupees or roughly 15 dollars)
- Install Go and set up the environment.
- Test installation using
go version
. - Complete Go Tour to learn basics:
- Variables, loops, conditionals.
- Structs, interfaces, functions.
- All basic Stuff (Go as deep as you want to)
- Learn the three main parts of an interpreter:
- Lexical Analysis (Tokenizer).
- Parsing (Abstract Syntax Tree).
- Evaluation (Executing AST).
- Define the minimal language features(Yet to be finalized):
- Arithmetic operations (
+
,-
,*
,/
). - Variables and assignments.
- Conditional statements (
if
,else
). - Print statements for output.
- Arithmetic operations (
- Define token types (
NUMBER
,IDENTIFIER
,OPERATOR
,KEYWORD
, etc.). - Write the
Lexer
function to tokenize input. - Handle whitespace and invalid input gracefully.
- Test the lexer with simple examples:
- Input:
x = 5 + 3
. - Output: A list of tokens.
- Input:
- Define AST nodes using structs:
- Binary expressions.
- Variable declarations.
- Literals.
- Write a recursive descent parser to build an AST:
- Parse expressions like
1 + 2
. - Handle assignments like
x = 5
.
- Parse expressions like
- Test the parser:
- Input:
x = 1 + 2
. - Output: A tree-like structure (AST).
- Input:
- Write an
Eval
function to evaluate the AST. - Store variables in a map for assignments.
- Handle:
- Arithmetic operations.
- Variable lookups.
- Print statements.
- Add basic error handling for:
- Invalid syntax.
- Undefined variables.
- Test the interpreter:
- Input:
x = 10; y = x + 5; print(y)
. - Output:
15
.
- Input:
- Add support for conditionals:
if x > 5 { print("greater") } else { print("less") }
(Optional) Add looping constructs like while or for.
(Optional) Implement functions and function calls.
-
Improve error messages for:
- Lexing errors.
- Parsing errors.
- Runtime errors.
-
Build a simple CLI or REPL:
-
Allow users to run files or interactively input code.
-
Enhance syntax with:
- Comments.
- String literals.
- Additional operators.
-
- Invalid input.
- Large expressions.
- Edge scenarios.
- Simplify logic.
- Add comments for readability.
- Write basic documentation for the language.
- Create a executable
Check Blog for complete timeline