mirror of
https://github.com/MorizzG/rlox.git
synced 2025-12-06 04:12:42 +00:00
finished resolver (chapter 11) and started classes (chapter 12)
This commit is contained in:
parent
42c9f17399
commit
10540708d4
34 changed files with 1449 additions and 439 deletions
48
GRAMMAR
Normal file
48
GRAMMAR
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
program -> statement* EOF ;
|
||||
|
||||
statement -> if_stmt
|
||||
| print_stmt
|
||||
| while_stmt
|
||||
| for_stmt
|
||||
| declaration
|
||||
| block
|
||||
| expr_stmt
|
||||
| break
|
||||
| return_stmt ;
|
||||
|
||||
if_stmt -> "if" "(" expression ")" statement ( "else" statement )? ;
|
||||
print_stmt -> "print" expression ";" ;
|
||||
while_stmt -> "while" "(" expression ")" statement ;
|
||||
for_stmt -> "for" "(" (declaration | expr_stmt | ";") ";" expression? ";" expression ";" ")" statement ;
|
||||
block -> "{" statement* "}" ;
|
||||
expr_Stmt -> expression ";" ;
|
||||
break -> "break" ";" ;
|
||||
return -> "return" expression? ";" ;
|
||||
|
||||
declaration -> var_decl | fun_decl | class_decl ;
|
||||
|
||||
var_decl -> "var" IDENTIFIER ( "=" expression )? ";"
|
||||
fun_decl -> "fun" IDENTIFIER "(" parameters ")" block ;
|
||||
class_decl -> "class" IDENTIFIER "{" method* "}" ;
|
||||
|
||||
method -> IDENTIFIER "(" parameters ")" block ;
|
||||
|
||||
expression -> assignment
|
||||
|
||||
assignment -> IDENTIFIER "=" assignment | logic_or ;
|
||||
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 -> "(" expression ")" | IDENTIFIER | lambda | NUMBER | STRING | "true" | "false" | "nil" ;
|
||||
|
||||
lambda -> "fun" "(" parameters ")" block ;
|
||||
|
||||
parameters -> ( IDENTIFIER ( "," IDENTIFIER )* )? ;
|
||||
Loading…
Add table
Add a link
Reference in a new issue