-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlox.abnf
42 lines (25 loc) · 1.31 KB
/
lox.abnf
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
; Grammar for Lox.
; To generate png: ./bin/kgt -l abnf -e svg < /usr/local/swift/lox/ilox/grammar/lox.abnf | isvg -b white -o lox.png
program = *declaration "EOF"
declaration = varDeclaration / statement
varDeclaration = "var" identifier *1( "=" expression ) ";"
statement = expressionStatement / printStatement
printStatement = "print" expression ";"
expressionStatement = expression ";"
expression = expressionBlock
expressionBlock = conditional *( "," expressionBlock)
conditional = equality *1( "?" expression ":" conditional )
equality = comparison *( ( "!=" / "==" ) comparison )
comparison = term *( ( ">" / ">=" / "<" / "<=" ) term )
term = factor *( ( "-" / "+" ) factor )
factor = unary *( ( "/" / "*" ) unary )
unary = ( "-" / "!" ) unary / primary
primary = 1*DIGIT "." 1*DIGIT / string / identifier /
"true" / "false" / "nil" / "(" expression ")" /
; START OF ERROR PRODUCTIONS
( "!=" / "==" ) comparison /
( ">" / ">=" / "<" / "<=" ) term /
( "-" / "+" ) factor /
( "/" / "*" ) unary
string = DQUOTE 1*CHAR DQUOTE
identifier = 1*ALPHA