Skip to content

interpreter for the Lox programming language implemented in Java

License

Notifications You must be signed in to change notification settings

peshala-prabhapoorna/jlox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jlox

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.

jlox - sta

Build and Run

Dependencies

  1. JDK (Java Development Toolkit)
  2. Maven

Steps

  1. Clone the repository
git clone git@github.com:peshala-prabhapoorna/jlox.git
  1. Move into the root of the repository
cd jlox
  1. Build the interpreter
mvn clean compile
  1. Run the interpreter
./jlox

Build Jar File

mvn clean compile package

grammar

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 ;

About

interpreter for the Lox programming language implemented in Java

Resources

License

Stars

Watchers

Forks

Packages

No packages published