-
Notifications
You must be signed in to change notification settings - Fork 3
/
Grammar.txt
131 lines (96 loc) · 2.89 KB
/
Grammar.txt
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
program ::= statement*
statement ::= atomic-statement
| block-statement
| del-statement
| empty-statement
| exit-statement
| for-statement
| fun-statement
| if-statement
| last-statement
| next-statement
| redo-statement
| ret-statement
| trace-statement
| var-statement
| when-statement
| whenever-statement
| while-statement
| expression-statement
atomic-statement ::= "atomic" statement ";"
block-statement ::= "{" statement* "}"
del-statement ::= "del" identifier ";"
empty-statement ::= ";"
exit-statement ::= "exit" ";"
for-statement ::= "for"
"("
statement
expression
";"
expression
")"
statement
fun-statement ::= "fun"
identifier
"("
list(identifier)
")"
statement
if-statement ::= "if" "(" expression ")" statement
last-statement ::= "last" ";"
next-statement ::= "next" ";"
redo-statement ::= "redo" ";"
ret-statement ::= "ret" expression? ";"
trace-statement ::= "trace" expression ";"
var-statement ::= "var" identifier ("=" expression)? ";"
when-statement ::= "when" "(" expression ")" statement
whenever-statement ::= "whenever" "(" expression ")" statement
while-statement ::= "while" "(" expression ")" statement
expression-statement ::= expression ";"
expression ::= value
| expression suffix*
| expression binary-operator expression
| unary-operator expression
value ::= boolean-value
| float-value
| fun-value
| integer-value
| string-value
| undefined-value
| identifier-expression
boolean-value ::= "false" | "true"
float-value ::= ...
fun-value ::= "lam" identifier? "(" list(identifier) ")"
(":" expression | "{" statement* "}")
integer-value ::= ...
string-value ::= ...
undefined-value ::= "undefined"
identifier-expression ::= identifier
suffix ::= call-suffix
| dot-suffix
| subscript-suffix
call-suffix ::= "(" list(expression) ")"
dot-suffix ::= "." identifier
subscript-suffix ::= "[" expression "]"
unary-operator ::= "+"
| "-"
| "not"
binary-operator ::= "*"
| "/"
| "mod"
| "+"
| "-"
| "<<"
| ">>"
| "<"
| ">="
| ">"
| "<="
| "=="
| "<>"
| "and"
| "xor"
| "or"
| "="
| ","
list(x) ::= (x ("," x)*)?