-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.cfg
27 lines (21 loc) · 899 Bytes
/
grammar.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
program -> declaration* EOF ;
declaration -> varDeclaration
| statement ;
statement -> exprStatement
| printStatement
| block;
block -> "{" declaration* "}" ;
exprStatement -> expression ";" ;
printStatement -> "print" expression ";" ;
varDeclaration -> "var" IDENTIFIER ( "=" expression )? ";" ;
expression -> assignment ;
assignment -> IDENTIFIER "=" assignment
| equality ;
equality -> comparison ( ( "==" | "!=" ) comparison )* ;
comparison -> term ( ( ">" | ">=" | "<" | "<=" ) term )* ;
term -> factor ( ( "-" | "+" ) factor )* ;
factor -> unary ( ( "*" | "/" ) unary )* ;
unary -> ( "-" | "!" ) unary
| primary ;
primary -> NUMBER | STRING | IDENTIFIER | "true" | "false" | "nil"
| "(" expression ")" ;