This is a small basic compiler built to learn how compilers work. It compiles our own dialect of BASIC to C, while being written in Python. Read the tutorial by MR Austin Z. Henley: Let's make a Teeny Tiny compiler, part 1
Knowing that just reading the tutorial and copy/past the code isn't enough to understand and grasp those concepts, I went through this process:
- read the tutorial and got a general idea about the structure of the project.
- debugued the final version of the compiler using break points (part3) and wrote some notes.
- based on those notes i built it.
It supports:
- Numerical variables
- Basic arithmetic
- If statements
- While loops
- Print text and numbers
- Input numbers
- Labels and goto
- Comments
Example code:
PRINT "How many fibonacci numbers do you want?"
INPUT nums
PRINT ""
LET a = 0
LET b = 1
WHILE nums > 0 REPEAT
PRINT a
LET c = a + b
LET a = b
LET b = c
LET nums = nums - 1
ENDWHILE