-
Notifications
You must be signed in to change notification settings - Fork 34
/
liftoscript.grammar
95 lines (85 loc) · 2.5 KB
/
liftoscript.grammar
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
@top Program { expression* }
@precedence {
unary
fncall @left
arrindex @left
times @left
plus @left
cmp @left
andor @left
ternary @right
assign @right
}
expression {
BinaryExpression |
NumberExpression |
WeightExpression |
Percentage |
ParenthesisExpression |
BlockExpression |
Ternary |
IfExpression |
ForExpression |
AssignmentExpression |
IncAssignmentExpression |
BuiltinFunctionExpression |
VariableExpression |
StateVariable |
Variable |
UnaryExpression
}
ParenthesisExpression { "(" expression ")" }
BlockExpression { "{" expression* "}" }
IfExpression {
@specialize<Keyword, "if"> ParenthesisExpression
BlockExpression
(@specialize<Keyword, "else"> @specialize<Keyword, "if"> ParenthesisExpression BlockExpression)*
(@specialize<Keyword, "else"> BlockExpression)?
}
ForExpression {
@specialize<Keyword, "for"> "(" Variable "in" ForInExpression ")"
BlockExpression
}
ForInExpression {
expression
}
AssignmentExpression { (StateVariable | Variable | VariableExpression) !assign "=" expression }
IncAssignmentExpression { (StateVariable | Variable | VariableExpression) !assign IncAssignment expression }
VariableExpression { Keyword (!arrindex "[" VariableIndex (":" VariableIndex)* "]")? }
StateVariable { StateKeyword (!arrindex "[" StateVariableIndex "]")? "." Keyword }
VariableIndex { Wildcard | expression }
StateVariableIndex { expression }
Wildcard { "*" }
BuiltinFunctionExpression { Keyword !fncall "(" expression? ("," expression)* ")" }
Ternary { expression !ternary "?" expression ":" expression }
NumberExpression { !unary Plus? Number }
WeightExpression { NumberExpression Unit }
BinaryExpression {
expression !plus Plus expression |
expression !times Times expression |
expression !cmp Cmp expression |
expression !andor AndOr expression
}
UnaryExpression {
!unary Not expression
}
@skip { space | LineComment | ";" | "{~" | "~}" }
@tokens {
space { @whitespace+ }
LineComment { "//" ![\n]* }
@precedence { LineComment, Times }
Keyword { @asciiLetter (@asciiLetter | @digit | "_")* }
StateKeyword { "state" }
Variable { "var." Keyword }
Unit { "lb" | "kg" }
@precedence { StateKeyword, Variable, Unit, Keyword }
Number { (@digit+ ("." @digit+)*) | "." @digit+ | @digit+ "." }
Plus { ("+" | "-") }
Percentage { Number "%" }
IncAssignment { ("+=" | "-=" | "*=" | "/=") }
@precedence { Percentage, Number, Plus }
Times { ("*" | "/" | "%") }
Cmp { ( ">" "="? | "==" | "!=" | "<" "="? ) }
AndOr { ( "&&" | "||" ) }
Not { "!" }
}