Skip to content

Rust implementation for the book Crafting Interpreter's tree walk interpreter for Lox language.

License

Notifications You must be signed in to change notification settings

giprayogo/warlox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

Yet another Rust implementation for Crafting Interpreter's tree walk interpreter for Lox language.

Grammar

Note: Precedence for optional implementations (extra materials from the book) roughly follows C's (not C++) grammar, with one difference: I'm not sure how to restrict assignments's left hand side to equality instead of ternary in a recursive descent parser.

See StackOverflow and The Syntax of C in Backus-Naur form.

program     ::= declaration* EOF
declaration ::= varDecl | statement
varDecl     ::= "var" IDENTIFIER ( "=" expression )? ";"
statement   ::= exprStmt | ifStmt | printStmt | whileStmt | block
ifStmt      ::= "if" "(" expression ")" statement ( "else" statement )?
whileStmt   ::= "while" "(" expression ")" statement
forStmt     ::= "for" "(" varDecl | exprStmt ";" expression? ";" expression? ")" statement
block       ::= "{" declaration* "}"
exprStmt    ::= expression
printStmt   ::= "print" expression
expression  ::= comma
comma       ::= assignment ( "," assignment )*
assignment  ::= ternary "=" assignment | ternary
ternary     ::= logic_or "?" expression ":" ternary
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 | primary
primary     ::= NUMBER | STRING | "true" | "false" | "nil" | "(" expression ")" | IDENTIFIER

About

Rust implementation for the book Crafting Interpreter's tree walk interpreter for Lox language.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages