Interpreter for the Lox programming language implemented in Java.
Implementation of the interpreter follows guidelines provided by the book
Crafting Interpreters written by
Robert Nystorm.
- JDK (Java Development Toolkit)
- Maven
- Clone the repository
git clone git@github.com:peshala-prabhapoorna/jlox.git
- Move into the root of the repository
cd jlox
- Build the interpreter
mvn clean compile
- Run the interpreter
./jlox
mvn clean compile package
program → declaration* EOF ;
declaration → varDecl | statement ;
statement → exprStmt
| forStmt
| ifStmt
| printStmt
| whileStmt
| block ;
forStmt → "for" "(" ( varDecl | exprStmt | ";")
expression? ";"
expression? ")" statement ;
block → "{" declaration* "}" ;
varDecl → "var" IDENTIFIER ( "=" expression )? ";" ;
exprStmt → expression ";" ;
ifStmt → "if" "(" expression ")" statement ( "else" statement )? ;
printStmt → "print" expression ";" ;
whileStmt → "while" "(" expression ")" statement ;
expression → assignment ;
assignment → IDENTIFIER "=" assignment | comma ;
comma → conditional ( "," conditional )* ;
conditional → logic_or ( "?" expression ":" conditional )? ;
logic_or → logic_and ( "or" logic_and )* ;
logic_and → equality ( "and" equality )* ;
equality → comparison ( ( "!=" | "==" ) comparison )* ;
comparison → term ( ( ">" | ">=" | "<" | "<=" ) term )* ;
term → factor ( ( "-" | "+" ) factor )* ;
factor → unary ( ( "/" | "*" ) unary )* ;
unary → ( "!" | "-" ) unary | call ;
call → primary ( "(" arguments? ")" )* ;
arguments → expression ( "," expression )* ;
primary → NUMBER | STRING | "true" | "false" | "nil"
| "(" expression ")"
| IDENTIFIER
// Error productions...
| ( "!=" | "==" ) equality
| ( ">" | ">=" | "<" | "<=" ) comparison
| ( "+" ) term
| ( "/" | "*" ) factor ;