reference: https://craftinginterpreters.com/contents.html
program → declaration* EOF ;
declaration → classDecl
| funDecl
| varDecl
| statement ;
classDecl → "class" IDENTIFIER ( "<" IDENTIFIER )? "{" function* "}" ;
funDecl → "fun" function ;
function → IDENTIFIER "(" parameters? ")" block ;
parameters → IDENTIFIER ( "," IDENTIFIER )* ;
statement → exprStmt
| ifStmt
| printStmt
| whileStmt
| forStmt
| returnStmt
| block ;
ifStmt → "if" "(" expression ")" statement
( "else" statement )? ;
whileStmt → "while" "(" expression ")" statement ;
forStmt → "for" "(" ( varDecl | exprStmt | ";" )
expression? ";"
expression? ")" statement ;
returnStmt → "return" expression? ";" ;
block → "{" declaration* "}" ;
varDecl → "var" IDENTIFIER ( "=" expression )? ";" ;
exprStmt → expression ";" ;
printStmt → "print" expression ";" ;
expression → unary ( ( "=" | "!=" | "==" | ">" | ">=" | "<" | "<=" | "-" | "+" | "/" | "*" | "?" expression ":" | "and" | "or") unary )* ;
unary → ( "!" | "-" ) unary
| primary ;
primary → NUMBER | STRING | "true" | "false" | "nil" | "this"
| "(" expression ")"
| ("super" ".")? IDENTIFIER ;