rlox/src/parser/GRAMMAR

18 lines
706 B
Text
Raw Normal View History

2023-01-22 23:33:57 +01:00
program -> statement* EOF ;
2023-01-20 16:10:03 +01:00
2023-01-22 23:33:57 +01:00
statement -> exprStmt | printStmt | declaration | block ;
exprStmt -> expression ";" ;
printStmt -> "print" expression ";" ;
declaration -> "var" IDENTIFIER ( "=" expression )? ";" ;
block -> "{" statement* "}" ;
expression -> assignment
assignment -> IDENTIFIER "=" assignment | equality ;
2023-01-20 16:10:03 +01:00
equality -> comparison ( ( "==" | "!=" ) comparison )* ;
comparison -> term ( ">" | ">=" | "<" | "<=" term )* ;
term -> factor ( ( "+" | "-" ) factor )*
factor -> unary ( ( "*" | "/" ) unary )* ;
unary -> ( "!" | "-" ) unary | primary ;
2023-01-22 23:33:57 +01:00
primary -> "(" expression ")" | IDENTIFIER | NUMBER | STRING | "true" | "false" | "nil" ;