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
291
292
293
294
295
296
297
|
function DEFNODE(type, props, methods, base) {
if (arguments.length < 4) base = AST_Node;
if (!props) props = [];
else props = props.split(/\s+/);
if (base && base.PROPS)
props = props.concat(base.PROPS);
var code = "return function AST_" + type + "(props){ if (props) { ";
for (var i = props.length; --i >= 0;) {
code += "this." + props[i] + " = props." + props[i] + ";";
}
code += " } }";
var ctor = new Function(code)();
if (base) {
ctor.prototype = new base;
}
ctor.prototype.CTOR = ctor;
ctor.PROPS = props || null;
if (type) {
ctor.prototype.TYPE = ctor.TYPE = type;
}
if (methods) for (var i in methods) if (HOP(methods, i)) {
ctor.prototype[i] = methods[i];
}
return ctor;
};
var AST_Token = DEFNODE("Token", "type value line col pos endpos nlb", {
}, null);
var AST_Node = DEFNODE("Node", "start end", {
}, null);
var AST_Directive = DEFNODE("Directive", "value", {
});
var AST_Debugger = DEFNODE("Debugger", null, {
});
var AST_Parenthesized = DEFNODE("Parenthesized", "expression", {
documentation: "Represents an expression which is always parenthesized. Used for the \
conditions in IF/WHILE."
});
var AST_Bracketed = DEFNODE("Bracketed", "body", {
documentation: "Represents a block of statements that are always included in brackets. \
Used for bodies of FUNCTION/TRY/CATCH/THROW/SWITCH."
});
/* -----[ loops ]----- */
var AST_LabeledStatement = DEFNODE("LabeledStatement", "label body", {
});
var AST_Statement = DEFNODE("Statement", null, {
}, AST_LabeledStatement);
var AST_Do = DEFNODE("Do", "condition", {
}, AST_LabeledStatement);
var AST_While = DEFNODE("While", "condition", {
}, AST_LabeledStatement);
var AST_For = DEFNODE("For", "init condition step", {
}, AST_LabeledStatement);
var AST_ForIn = DEFNODE("ForIn", "init name object", {
}, AST_LabeledStatement);
var AST_With = DEFNODE("With", "expression body", {
});
var AST_LoopControl = DEFNODE("LoopControl", "label", {
});
var AST_Break = DEFNODE("Break", null, {
}, AST_LoopControl);
var AST_Continue = DEFNODE("Continue", null, {
}, AST_LoopControl);
/* -----[ functions ]----- */
var AST_Scope = DEFNODE("Scope", "identifiers body", {
});
var AST_Toplevel = DEFNODE("Toplevel", null, {
}, AST_Scope);
var AST_Lambda = DEFNODE("Lambda", "name argnames", {
}, AST_Scope);
var AST_Function = DEFNODE("Function", null, {
}, AST_Lambda);
var AST_Defun = DEFNODE("Defun", null, {
}, AST_Function);
/* -----[ JUMPS ]----- */
var AST_Jump = DEFNODE("Jump", "value");
var AST_Return = DEFNODE("Return", null, {
}, AST_Jump);
var AST_Throw = DEFNODE("Throw", null, {
}, AST_Jump);
/* -----[ IF ]----- */
var AST_If = DEFNODE("If", "condition consequent alternative", {
});
/* -----[ SWITCH ]----- */
var AST_Switch = DEFNODE("Switch", "expression", {
}, AST_LabeledStatement);
var AST_SwitchBlock = DEFNODE("SwitchBlock", null, {
}, AST_Bracketed);
var AST_SwitchBranch = DEFNODE("SwitchBranch", "body", {
});
var AST_Default = DEFNODE("Default", null, {
}, AST_SwitchBranch);
var AST_Case = DEFNODE("Case", "expression", {
}, AST_SwitchBranch);
/* -----[ EXCEPTIONS ]----- */
var AST_Try = DEFNODE("Try", "btry bcatch bfinally", {
});
var AST_Catch = DEFNODE("Catch", "argname body", {
});
var AST_Finally = DEFNODE("Finally", null, {
}, AST_Bracketed);
/* -----[ VAR/CONST ]----- */
var AST_Definitions = DEFNODE("Definitions", "definitions", {
});
var AST_Var = DEFNODE("Var", null, {
}, AST_Definitions);
var AST_Const = DEFNODE("Const", null, {
}, AST_Definitions);
var AST_VarDef = DEFNODE("VarDef", "name value", {
});
/* -----[ OTHER ]----- */
var AST_Call = DEFNODE("Call", "expression args", {
});
var AST_New = DEFNODE("New", null, {
}, AST_Call);
var AST_Seq = DEFNODE("Seq", "first second", {
});
var AST_PropAccess = DEFNODE("PropAccess", "expression property", {
});
var AST_Dot = DEFNODE("Dot", null, {
}, AST_PropAccess);
var AST_Sub = DEFNODE("Sub", null, {
}, AST_PropAccess);
var AST_Unary = DEFNODE("Unary", "operator expression", {
});
var AST_UnaryPrefix = DEFNODE("UnaryPrefix", null, {
}, AST_Unary);
var AST_UnaryPostfix = DEFNODE("UnaryPostfix", null, {
}, AST_Unary);
var AST_Binary = DEFNODE("Binary", "left operator right", {
});
var AST_Conditional = DEFNODE("Conditional", "condition consequent alternative", {
});
var AST_Assign = DEFNODE("Assign", "left operator right", {
});
/* -----[ LITERALS ]----- */
var AST_RegExp = DEFNODE("Regexp", "pattern mods", {
});
var AST_Array = DEFNODE("Array", "elements", {
});
var AST_Object = DEFNODE("Object", "properties", {
});
var AST_ObjectProperty = DEFNODE("ObjectProperty");
var AST_ObjectKeyVal = DEFNODE("ObjectKeyval", "key value", {
}, AST_ObjectProperty);
var AST_ObjectSetter = DEFNODE("ObjectSetter", "name func", {
}, AST_ObjectProperty);
var AST_ObjectGetter = DEFNODE("ObjectGetter", "name func", {
}, AST_ObjectProperty);
var AST_Symbol = DEFNODE("Symbol", "name", {
});
var AST_String = DEFNODE("String", "value", {
});
var AST_Number = DEFNODE("Number", "value", {
});
var AST_Boolean = DEFNODE("Boolean", "value", {
});
var AST_Atom = DEFNODE("Atom", null, {
});
var AST_Null = DEFNODE("Null", null, {
}, AST_Atom);
var AST_Undefined = DEFNODE("Undefined", null, {
}, AST_Atom);
var AST_False = DEFNODE("False", null, {
}, AST_Atom);
var AST_True = DEFNODE("True", null, {
}, AST_Atom);
|