Skip to content

Boxfort/jlox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 

Repository files navigation

Jlox - Java Lox Interpreter

Implementation of Lox in Java following the book Crafting Interpreters by Bob Nystrom.

Grammar

program        -> statement* EOF ;

declaration    -> varDecl | statement ;

varDecl        -> "var" IDENTIFIER ( "=" expression )? ";" ;

statement      -> exprStmt | ifStmt | printStmt | whileStmt | block;

exprStmt       -> expression ";" ;
ifStmt         -> "if" "(" expression ")" statement ( "else" statement )? ;
printStmt      -> "print" expression ";" ;
whileStmt      -> "while "(" expression ")" statement ;
block          -> "{" declaration* "}" ;

expression     -> assignment ;
assignment     -> IDENTIFIER "=" assignment | logic_or ;
logic_or       -> logic_and ( "or" logic_and )* ;
logic_and      -> chain ( "and" chain )* ;
chain          -> ternary ("," ternary)* ;
ternary        -> equality ("?" equality ":" equality)* ;
equality       -> comparison ( ( "!=" | "==" ) comparison )* ;
comparison     -> addition ( ( ">" | ">=" | "<" | "<=" ) addition )* ;
addition       -> multiplication ( ( "-" | "+" ) multiplication)* ;
multiplication -> unary ( ( "/" | "*" ) unary)* ;
unary          -> ( "!" | "-" ) unary | primary ;
primary        -> NUMBER | STRING | "false" | "true" | "nil" | "(" expression ")" | IDENTIFIER ;

About

Java Lox interpreter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages