Compiler for a BASIC-like language, inspired by the teeny-tiny-compiler by Austin Henley.
- Write a program in the BASIC-like language and store it in examples/<program_name>.txt. Here we use parse-if.txt
LET bar = 5 LET foo = bar * 3 + 2 IF foo > 0 THEN PRINT "yes!" ENDIF
- Compile and run the program
$ sh compile.sh parse-if Filepath input: examples/parse-if.txt Filepath output: examples/c-files/parse-if.c Compiling... Finished release [optimized] target(s) in 0.00s Running `target/release/basic-compiler parse-if` Running... yes!
-
Clone the repository
HTTPS:git clone https://github.com/BraSDon/basic-compiler.git
SSH:
git clone git@github.com:BraSDon/basic-compiler.git
-
Change into project directory
cd basic-compiler
-
Build the project
cargo build --release
-
Compile and run one of the example programs; or create your own in examples/
sh compile.sh parse-if
program ::= {statement}
statement ::= "PRINT" (expression | string) nl
| "IF" comparison "THEN" nl {statement} "ENDIF" nl
| "WHILE" comparison "REPEAT" nl {statement} "ENDWHILE" nl
| "LABEL" ident nl
| "GOTO" ident nl
| "LET" ident "=" expression nl
| "INPUT" ident nl
comparison ::= expression (("==" | "!=" | ">" | ">=" | "<" | "<=") expression)+
expression ::= term {( "-" | "+" ) term}
term ::= unary {( "/" | "*" ) unary}
unary ::= ["+" | "-"] primary
primary ::= number | ident
nl ::= '\n'+