- Add tests for the interpreter, parser and lexer
- Handle case
print ;
- Compile the program
$ rustc src/main.rs -o lox
NOTE: To compile in debug mode, use the following command:
$ rustc src/main -o lox --cfg debug_lox
- Execute as REPL
$ ./lox
>
or give a lox script as input
$ ./lox [FILE_NAME]
program -> declaration* EOF;
declaration -> varDecl
| statement;
varDecl -> "var" IDENTIFIER ("=" expression)? ";";
primary -> NUMBER | STRING | "true" | "false" | "nil"
| "(" expression ")"
| IDENTIFIER;
expression -> assignment;
assignment -> IDENTIFIER "=" assingment
| equality;
program -> statement* EOF;
statement -> exprStmt
| printStmt;
exprStmt -> expression ";" ;
printStmt -> "print" expression ";";
expression -> equality ;
equality -> comparison ( ( "!=" | "==" ) comparison )* ;
comparison -> term ( ( ">" | ">=" | "<" | "<=" ) term )* ;
term -> factor ( ( "-" | "+" ) factor )* ;
factor -> unary ( ( "/" | "*" ) unary )* ;
unary -> ( "!" | "-" ) unary
| primary ;
primary -> NUMBER | STRING | "true" | "false" | "nil"
| "(" expression ")" ;
The bellow grammar would be used to create a syntax tree which is abstract (AST).
expression -> literal
| grouping
| unary
| binary;
literal -> NUMBER
| STRING
| "true"
| "false"
| "nil";
grouping -> "(" expression ")";
binary -> expression operator expression;
operator -> "*"
| "/"
| "-"
| "+"
| "=="
| "!="
| "<"
| ">"
| "<="
| ">=";
- Learn more about error codes while exiting the program.
- Difference between expression and statement?
- What is dynamic dispatch and static dispatch?