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 | 1
1
1
1
22
22
2
22
34
34
4
34
4
253
10
123
123
123
46
123
19
123
8
123
32
123
630
38
38
16
38
511
12
89
5
6
39
115
115
27
115
3
3
1
| (function(sc) {
"use strict";
require("../compiler");
var Syntax = sc.lang.compiler.Syntax;
var Node = {
createAssignmentExpression: function(operator, left, right, remain) {
var node = {
type: Syntax.AssignmentExpression,
operator: operator,
left: left,
right: right
};
if (remain) {
node.remain = remain;
}
return node;
},
createBinaryExpression: function(operator, left, right) {
var node = {
type: Syntax.BinaryExpression,
operator: operator.value,
left: left,
right: right
};
if (operator.adverb) {
node.adverb = operator.adverb;
}
return node;
},
createBlockExpression: function(body) {
return {
type: Syntax.BlockExpression,
body: body
};
},
createCallExpression: function(callee, method, args, stamp) {
return {
type: Syntax.CallExpression,
stamp: stamp,
callee: callee,
method: method,
args: args,
};
},
createEnvironmentExpression: function(id) {
return {
type: Syntax.EnvironmentExpression,
id: id
};
},
createFunctionExpression: function(args, body, opts) {
var node;
node = {
type: Syntax.FunctionExpression,
body: body
};
if (args) {
node.args = args;
}
if (opts.closed) {
node.closed = true;
}
if (opts.partial) {
node.partial = true;
}
if (opts.blockList) {
node.blockList = true;
}
return node;
},
createIdentifier: function(name) {
return {
type: Syntax.Identifier,
name: name
};
},
createListExpression: function(elements, immutable) {
var node = {
type: Syntax.ListExpression,
elements: elements
};
if (immutable) {
node.immutable = !!immutable;
}
return node;
},
createLiteral: function(token) {
return {
type: Syntax.Literal,
value: token.value,
valueType: token.type
};
},
createEventExpression: function(elements) {
return {
type: Syntax.EventExpression,
elements: elements
};
},
createProgram: function(body) {
return {
type: Syntax.Program,
body: body
};
},
createThisExpression: function(name) {
return {
type: Syntax.ThisExpression,
name: name
};
},
createUnaryExpression: function(operator, arg) {
return {
type: Syntax.UnaryExpression,
operator: operator,
arg: arg
};
},
createVariableDeclaration: function(declarations, kind) {
return {
type: Syntax.VariableDeclaration,
declarations: declarations,
kind: kind
};
},
createVariableDeclarator: function(id, init) {
var node = {
type: Syntax.VariableDeclarator,
id: id
};
if (init) {
node.init = init;
}
return node;
},
createValueMethodEvaluator: function(id, expr) {
return {
type: Syntax.ValueMethodEvaluator,
id: id,
expr: expr,
segmented: true
};
},
createValueMethodResult: function(id) {
return {
type: Syntax.ValueMethodResult,
id: id
};
}
};
sc.lang.compiler.Node = Node;
})(sc);
|