-
Notifications
You must be signed in to change notification settings - Fork 0
/
small.js
290 lines (289 loc) · 15.1 KB
/
small.js
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// Generated automatically by nearley, version 2.20.1
// http://github.com/Hardmath123/nearley
(function () {
function id(x) { return x[0]; }
const myLexer = require("./lexer");
var grammar = {
Lexer: myLexer,
ParserRules: [
{"name": "statements$ebnf$1", "symbols": []},
{"name": "statements$ebnf$1$subexpression$1", "symbols": ["statement", "_ml"]},
{"name": "statements$ebnf$1", "symbols": ["statements$ebnf$1", "statements$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "statements", "symbols": ["_ml", "statements$ebnf$1"], "postprocess":
(data) => {
return data[1].map(item => item[0]);
}
},
{"name": "statement", "symbols": ["var_declare"], "postprocess": id},
{"name": "statement", "symbols": ["var_assign"], "postprocess": id},
{"name": "statement", "symbols": ["method"], "postprocess": id},
{"name": "statement", "symbols": ["fun_call"], "postprocess": id},
{"name": "statement", "symbols": ["control"], "postprocess": id},
{"name": "statement", "symbols": ["loop"], "postprocess": id},
{"name": "var_declare$ebnf$1$subexpression$1", "symbols": [(myLexer.has("var_type") ? {type: "var_type"} : var_type), "_"]},
{"name": "var_declare$ebnf$1", "symbols": ["var_declare$ebnf$1$subexpression$1"]},
{"name": "var_declare$ebnf$1$subexpression$2", "symbols": [(myLexer.has("var_type") ? {type: "var_type"} : var_type), "_"]},
{"name": "var_declare$ebnf$1", "symbols": ["var_declare$ebnf$1", "var_declare$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "var_declare", "symbols": ["var_declare$ebnf$1", (myLexer.has("identifier") ? {type: "identifier"} : identifier), "_", (myLexer.has("EL") ? {type: "EL"} : EL)], "postprocess":
(data) => {
return {
type: "var_declare",
var_types: data[0].map(item => item[0]),
var_name: data[1],
}
}
},
{"name": "var_assign$ebnf$1$subexpression$1", "symbols": [(myLexer.has("var_type") ? {type: "var_type"} : var_type), "_"]},
{"name": "var_assign$ebnf$1", "symbols": ["var_assign$ebnf$1$subexpression$1"]},
{"name": "var_assign$ebnf$1$subexpression$2", "symbols": [(myLexer.has("var_type") ? {type: "var_type"} : var_type), "_"]},
{"name": "var_assign$ebnf$1", "symbols": ["var_assign$ebnf$1", "var_assign$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "var_assign", "symbols": ["var_assign$ebnf$1", (myLexer.has("identifier") ? {type: "identifier"} : identifier), "_", {"literal":"="}, "_", "expr", "_", (myLexer.has("EL") ? {type: "EL"} : EL)], "postprocess":
(data) => {
return {
type: "var_assign",
var_types: data[0].map(x => x[0]),
var_name: data[1],
value: data[5]
}
}
},
{"name": "var_assign", "symbols": [(myLexer.has("identifier") ? {type: "identifier"} : identifier), "_", {"literal":"="}, "_", "expr", "_", (myLexer.has("EL") ? {type: "EL"} : EL)], "postprocess":
(data) => {
return {
type: "var_assign",
var_name: data[0],
value: data[4]
}
}
},
{"name": "expr", "symbols": [(myLexer.has("string") ? {type: "string"} : string)], "postprocess": id},
{"name": "expr", "symbols": [(myLexer.has("char") ? {type: "char"} : char)], "postprocess": id},
{"name": "expr", "symbols": [(myLexer.has("float") ? {type: "float"} : float)], "postprocess": id},
{"name": "expr", "symbols": [(myLexer.has("number") ? {type: "number"} : number)], "postprocess": id},
{"name": "expr", "symbols": ["identifiers"], "postprocess": id},
{"name": "expr", "symbols": ["fun_call__"], "postprocess": id},
{"name": "identifiers$ebnf$1", "symbols": []},
{"name": "identifiers$ebnf$1$subexpression$1", "symbols": [(myLexer.has("lbrack") ? {type: "lbrack"} : lbrack), (myLexer.has("identifier") ? {type: "identifier"} : identifier), (myLexer.has("rbrack") ? {type: "rbrack"} : rbrack)]},
{"name": "identifiers$ebnf$1", "symbols": ["identifiers$ebnf$1", "identifiers$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "identifiers", "symbols": [(myLexer.has("identifier") ? {type: "identifier"} : identifier), "identifiers$ebnf$1"], "postprocess":
(data) => {
return {
type: "identifiers",
primary: data[0],
auxiliary: data[1].map(x => x[1])
}
}
},
{"name": "method", "symbols": ["fun_signature", "fun_body"], "postprocess":
(data) => {
return {
type: "method",
signature: data[0],
body: data[1]
}
}
},
{"name": "fun_signature", "symbols": [(myLexer.has("var_type") ? {type: "var_type"} : var_type), "_", (myLexer.has("identifier") ? {type: "identifier"} : identifier), "_", {"literal":"("}, "fun_params", {"literal":")"}, "_ml", {"literal":"{"}], "postprocess":
(data) => {
return {
type: "fun_signature",
name: data[2],
params: data[5],
returns: data[0]
}
}
},
{"name": "fun_body", "symbols": ["statements", {"literal":"}"}], "postprocess":
(data) => {
return {
type: "fun_body",
statements: data[0],
};
}
},
{"name": "fun_params$ebnf$1", "symbols": []},
{"name": "fun_params$ebnf$1$subexpression$1$ebnf$1", "symbols": [(myLexer.has("comma") ? {type: "comma"} : comma)], "postprocess": id},
{"name": "fun_params$ebnf$1$subexpression$1$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
{"name": "fun_params$ebnf$1$subexpression$1", "symbols": ["_ml", "fun_params$ebnf$1$subexpression$1$ebnf$1", "_", (myLexer.has("var_type") ? {type: "var_type"} : var_type), "__", (myLexer.has("identifier") ? {type: "identifier"} : identifier)]},
{"name": "fun_params$ebnf$1", "symbols": ["fun_params$ebnf$1", "fun_params$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "fun_params", "symbols": ["fun_params$ebnf$1"], "postprocess":
(data) => {
return {
type: "fun_params",
param_types: data[0].map(x => x[3]),
param_values: data[0].map(x => x[5])
}
}
},
{"name": "fun_call", "symbols": [(myLexer.has("identifier") ? {type: "identifier"} : identifier), "_", {"literal":"("}, "arg_list", {"literal":")"}, "_", (myLexer.has("EL") ? {type: "EL"} : EL)], "postprocess":
(data) => {
return {
type: "fun_call",
fun_name: data[0],
arguments: data[3]
}
}
},
{"name": "fun_call__", "symbols": [(myLexer.has("identifier") ? {type: "identifier"} : identifier), "_", {"literal":"("}, "arg_list", {"literal":")"}], "postprocess":
(data) => {
return {
type: "fun_call__",
fun_name: data[0],
arguments: data[3]
}
}
},
{"name": "arg_list$ebnf$1", "symbols": []},
{"name": "arg_list$ebnf$1$subexpression$1$ebnf$1", "symbols": [(myLexer.has("comma") ? {type: "comma"} : comma)], "postprocess": id},
{"name": "arg_list$ebnf$1$subexpression$1$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
{"name": "arg_list$ebnf$1$subexpression$1", "symbols": ["_ml", "expr", "_ml", "arg_list$ebnf$1$subexpression$1$ebnf$1"]},
{"name": "arg_list$ebnf$1", "symbols": ["arg_list$ebnf$1", "arg_list$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "arg_list", "symbols": ["arg_list$ebnf$1"], "postprocess":
(data) => {
return {
type: "arg_list",
arg_values: data[0].map(x => x[1])
}
}
},
{"name": "control", "symbols": ["condition", "control_body"], "postprocess":
(data) => {
return {
type: "control",
condition: data[0],
body: data[1]
}
}
},
{"name": "condition$ebnf$1$subexpression$1", "symbols": [(myLexer.has("control_key") ? {type: "control_key"} : control_key), "_"]},
{"name": "condition$ebnf$1", "symbols": ["condition$ebnf$1$subexpression$1"]},
{"name": "condition$ebnf$1$subexpression$2", "symbols": [(myLexer.has("control_key") ? {type: "control_key"} : control_key), "_"]},
{"name": "condition$ebnf$1", "symbols": ["condition$ebnf$1", "condition$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "condition$ebnf$2", "symbols": []},
{"name": "condition$ebnf$2$subexpression$1", "symbols": [(myLexer.has("logical") ? {type: "logical"} : logical), "_", "check", "_"]},
{"name": "condition$ebnf$2", "symbols": ["condition$ebnf$2", "condition$ebnf$2$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "condition", "symbols": ["condition$ebnf$1", {"literal":"("}, "_", "check", "_", "condition$ebnf$2", {"literal":")"}, "_ml", {"literal":"{"}], "postprocess":
(data) => {
return {
type: "condition",
control_keys: data[0].map(x => x[0]),
checks: [data[3], ...data[5].map(x => x[2])],
logicals: data[5].map(x => x[0]),
};
}
},
{"name": "check", "symbols": ["expr", "_", (myLexer.has("conditional") ? {type: "conditional"} : conditional), "_", "expr"], "postprocess":
(data) => {
return {
type: "check",
left: data[0],
conditional: data[2],
right: data[4],
};
}
},
{"name": "control_body", "symbols": ["statements", {"literal":"}"}], "postprocess":
(data) => {
return {
type: "control_body",
statements: data[0],
};
}
},
{"name": "loop", "symbols": ["loop_params", "loop_body"], "postprocess":
(data) => {
return {
type: "loop",
loop_params: data[0],
body: data[1]
}
}
},
{"name": "loop_params", "symbols": [(myLexer.has("loop_key") ? {type: "loop_key"} : loop_key), "_", {"literal":"("}, "var_assign", "_", "stop_condition", "_", "incrementor", "_", {"literal":")"}, "_ml", {"literal":"{"}], "postprocess":
(data) => {
return {
type: "loop_params",
loop_key: data[0],
counter_var: data[3],
stop_condition: data[5],
incrementor: data[7],
}
}
},
{"name": "loop_params", "symbols": [(myLexer.has("loop_key") ? {type: "loop_key"} : loop_key), "_", {"literal":"("}, "_", "check", "_", {"literal":")"}, "_ml", {"literal":"{"}], "postprocess":
(data) => {
return {
type: "loop_params",
loop_key: data[0],
check: data[4],
}
}
},
{"name": "stop_condition", "symbols": ["expr", "_", (myLexer.has("conditional") ? {type: "conditional"} : conditional), "_", "expr", "_", (myLexer.has("EL") ? {type: "EL"} : EL)], "postprocess":
(data) => {
return {
type: "stop_condition",
left: data[0],
conditional: data[2],
right: data[4],
}
}
},
{"name": "incrementor", "symbols": [(myLexer.has("identifier") ? {type: "identifier"} : identifier), {"literal":"++"}], "postprocess":
(data) => {
return {
type: "incrementor",
identifier: data[0],
op: data[1],
}
}
},
{"name": "incrementor", "symbols": [(myLexer.has("identifier") ? {type: "identifier"} : identifier), {"literal":"--"}], "postprocess":
(data) => {
return {
type: "incrementor",
identifier: data[0],
op: data[1],
}
}
},
{"name": "loop_body", "symbols": ["statements", {"literal":"}"}], "postprocess":
(data) => {
return {
type: "control_body",
statements: data[0],
};
}
},
{"name": "__lb_$ebnf$1$subexpression$1", "symbols": ["_", (myLexer.has("NL") ? {type: "NL"} : NL)]},
{"name": "__lb_$ebnf$1", "symbols": ["__lb_$ebnf$1$subexpression$1"]},
{"name": "__lb_$ebnf$1$subexpression$2", "symbols": ["_", (myLexer.has("NL") ? {type: "NL"} : NL)]},
{"name": "__lb_$ebnf$1", "symbols": ["__lb_$ebnf$1", "__lb_$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "__lb_", "symbols": ["__lb_$ebnf$1", "_"]},
{"name": "_ml$ebnf$1", "symbols": []},
{"name": "_ml$ebnf$1$subexpression$1", "symbols": [(myLexer.has("WS") ? {type: "WS"} : WS)]},
{"name": "_ml$ebnf$1$subexpression$1", "symbols": [(myLexer.has("NL") ? {type: "NL"} : NL)]},
{"name": "_ml$ebnf$1", "symbols": ["_ml$ebnf$1", "_ml$ebnf$1$subexpression$1"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "_ml", "symbols": ["_ml$ebnf$1"]},
{"name": "__ml$ebnf$1$subexpression$1", "symbols": [(myLexer.has("WS") ? {type: "WS"} : WS)]},
{"name": "__ml$ebnf$1$subexpression$1", "symbols": [(myLexer.has("NL") ? {type: "NL"} : NL)]},
{"name": "__ml$ebnf$1", "symbols": ["__ml$ebnf$1$subexpression$1"]},
{"name": "__ml$ebnf$1$subexpression$2", "symbols": [(myLexer.has("WS") ? {type: "WS"} : WS)]},
{"name": "__ml$ebnf$1$subexpression$2", "symbols": [(myLexer.has("NL") ? {type: "NL"} : NL)]},
{"name": "__ml$ebnf$1", "symbols": ["__ml$ebnf$1", "__ml$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "__ml", "symbols": ["__ml$ebnf$1"]},
{"name": "_$ebnf$1", "symbols": []},
{"name": "_$ebnf$1", "symbols": ["_$ebnf$1", (myLexer.has("WS") ? {type: "WS"} : WS)], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "_", "symbols": ["_$ebnf$1"]},
{"name": "__$ebnf$1", "symbols": [(myLexer.has("WS") ? {type: "WS"} : WS)]},
{"name": "__$ebnf$1", "symbols": ["__$ebnf$1", (myLexer.has("WS") ? {type: "WS"} : WS)], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
{"name": "__", "symbols": ["__$ebnf$1"]}
]
, ParserStart: "statements"
}
if (typeof module !== 'undefined'&& typeof module.exports !== 'undefined') {
module.exports = grammar;
} else {
window.grammar = grammar;
}
})();