I built this compiler by following Austin Henley's Teeny Tiny compiler blog series which is implemented in Python. The Teeny Tiny language is a dialect of BASIC. Teeny Tiny compiles to C code and this version of the compiler is implemented in Rust.
Here are a list of features I'll be adding to improve the Teeny Tiny language:
- Parentheses for expressions
- Logical operators (and, or, not)
- ELSE IF and ELSE
- FOR loop
- Allow multiple code files
- Functions with parameters and return values
- Lexical scope
- Standard library
- Abstract syntax tree representation
- More primitive types
- Arrays
- Type checking
- More tests for the compiler
- Numerical variables
- Basic arithmetic
- If statements
- While loops
- Print text and numbers
- Input numbers
- Labels and goto
- Comments
- Create a file with teeny as the file extension. eg:
hello.teeny
- Write your teeny program. eg program:
PRINT "How many fibonacci numbers do you want?"
INPUT nums
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
- Pass file to the compiler with
cargo run -- hello.teeny
- After successfully compiling to C code. You should find a C file called
out.c
in the root folder of the project. - You can compile that with gcc if you have it installed.