-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathast.js
More file actions
142 lines (126 loc) · 2.54 KB
/
Copy pathast.js
File metadata and controls
142 lines (126 loc) · 2.54 KB
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
// All the Abstract Syntax Tree nodes, used in the parser and interpreter
export class Literal {
constructor(value) {
this.type = 'Literal'
this.value = value
}
}
export class Array {
constructor(value) {
this.type = 'Array'
this.value = value
}
}
export class Var {
constructor(name, value) {
this.type = 'Var'
this.name = name
this.value = value
}
}
export class Binary {
constructor(left, operator, right) {
this.type = 'Binary'
this.left = left
this.operator = operator
this.right = right
}
}
export class Func {
constructor(name, params, body) {
this.type = 'Func'
this.name = name
this.params = params
this.body = body
}
}
export class Return {
constructor(value) {
this.type = 'Return'
this.value = value
}
}
export class For {
constructor(id, range, body) {
this.type = 'For'
this.id = id
this.range = range
this.body = body
}
}
export class While {
constructor(condition, body) {
this.type = 'While'
this.condition = condition
this.body = body
}
}
export class Conditional {
constructor(condition, body, otherwise) {
this.type = 'Conditional'
this.condition = condition
this.body = body
this.otherwise = otherwise
}
}
export class Set {
constructor(caller, property, value) {
this.type = 'Set'
this.caller = caller
this.property = property
this.value = value
}
}
export class Struct {
constructor(name, members) {
this.type = 'Struct'
this.name = name
this.members = members
}
}
export class Instance {
constructor(name, members) {
this.type = 'Instance'
this.name = name
this.members = members
}
}
export class Call {
constructor(caller, args) {
this.tye = 'Call'
this.caller = caller
this.args = args
}
}
export class Get {
constructor(caller, property, isExpr = false) {
this.type = 'Get'
this.caller = caller
this.property = property
this.isExpr = isExpr
}
}
export class Unary {
constructor(operator, apply) {
this.type = 'Unary'
this.operator = operator
this.apply = apply
}
}
export default {
Literal,
Array,
Var,
Binary,
Func,
Return,
For,
While,
Conditional,
Set,
Struct,
Instance,
Call,
Get,
Unary
}