alphalang 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/alphalang +6 -0
- data/lib/alpha.rb +3 -1
- data/lib/nodes/basenodes.rb +27 -13
- data/lib/nodes/stmtnodes.rb +110 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd90e0cc81ecac899602c5a173f188110fecd877428fcab72e8bc77076e75d00
|
4
|
+
data.tar.gz: 1b1e538edb038c95ccffcb50fb8f48f5081977701082164da879ab848af80edb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95e31bbc359dc485d7e5e623164f2f3c636c68975e6c7bd1c83fcfe75c11cbe8b1fe6c4d35eeefae0bfcf7c0b668f673a8649cea39d9bfe6f7319d860947e87b
|
7
|
+
data.tar.gz: 15cd10c8ce16fea278f3d99f3c8caecf3e811249c6a1d933360433d22ca06c0816602555a1aa314ba720a00229e6401256520de7d664da884a98e1bff2e3d24e
|
data/bin/alphalang
CHANGED
@@ -44,6 +44,10 @@ OptionParser.new do |opts|
|
|
44
44
|
opts.on('--listlocale', 'Lists all keywords from a specific locale file from your locales directory.') do
|
45
45
|
options[:listlocale] = true
|
46
46
|
end
|
47
|
+
|
48
|
+
opts.on('--printtree', 'Lists all keywords from a specific locale file from your locales directory.') do
|
49
|
+
options[:printtree] = true
|
50
|
+
end
|
47
51
|
end.parse!
|
48
52
|
|
49
53
|
verbose_flag = options[:verbose]
|
@@ -54,6 +58,8 @@ create_locale_flag = options[:createlocale]
|
|
54
58
|
delete_locale_flag = options[:deletelocale]
|
55
59
|
list_locales_flag = options[:listlocales]
|
56
60
|
list_locale_flag = options[:listlocale]
|
61
|
+
PRINT_TREE_FLAG = options[:printtree]
|
62
|
+
TREE_ARRAY = []
|
57
63
|
|
58
64
|
if create_locale_flag
|
59
65
|
require_relative '../lib/locale_creator'
|
data/lib/alpha.rb
CHANGED
data/lib/nodes/basenodes.rb
CHANGED
@@ -36,6 +36,10 @@ class BoolNode < Node
|
|
36
36
|
@value = false if value == ScopeManager.false_value
|
37
37
|
end
|
38
38
|
|
39
|
+
def to_s
|
40
|
+
@value.to_s
|
41
|
+
end
|
42
|
+
|
39
43
|
def evaluate
|
40
44
|
@value
|
41
45
|
end
|
@@ -53,6 +57,10 @@ class AndNode < Node
|
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
60
|
+
def to_s
|
61
|
+
"#{@lhs} and #{@rhs}"
|
62
|
+
end
|
63
|
+
|
56
64
|
def evaluate
|
57
65
|
@lhs.evaluate && @rhs.evaluate
|
58
66
|
end
|
@@ -68,6 +76,10 @@ class OrNode < Node
|
|
68
76
|
end
|
69
77
|
end
|
70
78
|
|
79
|
+
def to_s
|
80
|
+
"#{@lhs} or #{@rhs}"
|
81
|
+
end
|
82
|
+
|
71
83
|
def evaluate
|
72
84
|
@lhs.evaluate || @rhs.evaluate
|
73
85
|
end
|
@@ -78,6 +90,10 @@ class NotNode < Node
|
|
78
90
|
@node = node
|
79
91
|
end
|
80
92
|
|
93
|
+
def to_s
|
94
|
+
"not #{@node}"
|
95
|
+
end
|
96
|
+
|
81
97
|
def evaluate
|
82
98
|
not @node.evaluate
|
83
99
|
end
|
@@ -92,6 +108,10 @@ class CompareNode < Node
|
|
92
108
|
@lhs, @op, @rhs = lhs, op, rhs
|
93
109
|
end
|
94
110
|
|
111
|
+
def to_s
|
112
|
+
"#{@lhs} #{@op} #{@rhs}"
|
113
|
+
end
|
114
|
+
|
95
115
|
def evaluate
|
96
116
|
@value = @lhs.evaluate.send(@op, @rhs.evaluate)
|
97
117
|
end
|
@@ -105,21 +125,13 @@ class BinaryOperationNode < Node
|
|
105
125
|
@lhs, @op, @rhs = lhs, op, rhs
|
106
126
|
end
|
107
127
|
|
128
|
+
def to_s
|
129
|
+
"#{@lhs} #{@op} #{@rhs}"
|
130
|
+
end
|
131
|
+
|
108
132
|
def evaluate
|
109
133
|
if @rhs.evaluate.is_a?(ArrayNode) && @op == '+'
|
110
134
|
return @value = @rhs.evaluate + @lhs.evaluate
|
111
|
-
elsif @lhs.evaluate.is_a?(Array) && @op == '+'
|
112
|
-
return @value = @lhs.evaluate.append(@rhs.evaluate)
|
113
|
-
end
|
114
|
-
|
115
|
-
if @rhs.evaluate.is_a?(ArrayNode) && @op == '-'
|
116
|
-
return @value = @rhs.evaluate - @lhs.evaluate
|
117
|
-
elsif @lhs.evaluate.is_a?(Array) && @op == '-'
|
118
|
-
return @lhs.evaluate.reject { |v| v.evaluate == @rhs.evaluate }
|
119
|
-
end
|
120
|
-
|
121
|
-
if @rhs.evaluate.is_a?(ArrayNode) or @rhs.evaluate.is_a?(Array) and @lhs.evaluate.is_a?(Numeric)
|
122
|
-
raise SyntaxError, "You can't subtract an array from a number! #{@lhs.evaluate} #{@op} #{@rhs.name}"
|
123
135
|
end
|
124
136
|
|
125
137
|
if @op == '/'
|
@@ -163,10 +175,12 @@ class ArrayNode < Node
|
|
163
175
|
|
164
176
|
def +(value)
|
165
177
|
@value.append(value)
|
178
|
+
self
|
166
179
|
end
|
167
180
|
|
168
181
|
def -(value)
|
169
|
-
@value.reject { |v| v.evaluate == value }
|
182
|
+
@value = @value.reject { |v| v.evaluate == value }
|
183
|
+
self
|
170
184
|
end
|
171
185
|
|
172
186
|
def [](index)
|
data/lib/nodes/stmtnodes.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
require_relative 'basenodes'
|
2
2
|
|
3
|
+
def set_up_scope_header
|
4
|
+
result = "<#{ScopeManager.scope_lvl}> "
|
5
|
+
result += '++--++--' * (ScopeManager.scope_lvl + 1) + ' '
|
6
|
+
result
|
7
|
+
end
|
8
|
+
|
3
9
|
###################### Variable Nodes
|
4
10
|
|
5
11
|
class VariableCallNode < Node
|
@@ -9,8 +15,19 @@ class VariableCallNode < Node
|
|
9
15
|
@name = name
|
10
16
|
end
|
11
17
|
|
18
|
+
def create_tree_entry
|
19
|
+
result = set_up_scope_header
|
20
|
+
result += "Variable #{@name} is now #{@value}"
|
21
|
+
TREE_ARRAY << result unless TREE_ARRAY[-1] == result
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
@name
|
26
|
+
end
|
27
|
+
|
12
28
|
def evaluate
|
13
29
|
@value = ScopeManager.lookup_var(@name)
|
30
|
+
create_tree_entry if PRINT_TREE_FLAG
|
14
31
|
return @value
|
15
32
|
end
|
16
33
|
end
|
@@ -23,8 +40,19 @@ class VariableDecNode < Node
|
|
23
40
|
@name = name
|
24
41
|
end
|
25
42
|
|
43
|
+
def create_tree_entry
|
44
|
+
result = set_up_scope_header
|
45
|
+
result += "Variable #{@name} is now #{@value}"
|
46
|
+
TREE_ARRAY << result unless TREE_ARRAY[-1] == result
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_s
|
50
|
+
"#{@name} = #{@value}"
|
51
|
+
end
|
52
|
+
|
26
53
|
def evaluate
|
27
54
|
ScopeManager.add_to_current_scope(name, @value)
|
55
|
+
create_tree_entry if PRINT_TREE_FLAG
|
28
56
|
self
|
29
57
|
end
|
30
58
|
end
|
@@ -41,6 +69,7 @@ class ArrayCallNode < Node
|
|
41
69
|
raise ArgumentError, "You are trying to access an out of bounds index. Here -> #{@value}[#{@index}]"
|
42
70
|
end
|
43
71
|
@value = arr[@index]
|
72
|
+
@value
|
44
73
|
end
|
45
74
|
end
|
46
75
|
|
@@ -53,8 +82,19 @@ class FunctionDecNode < Node
|
|
53
82
|
@args = node.args
|
54
83
|
end
|
55
84
|
|
85
|
+
def create_tree_entry
|
86
|
+
result = set_up_scope_header
|
87
|
+
result += "Function #{@name} declared"
|
88
|
+
TREE_ARRAY << result unless TREE_ARRAY[-1] == result
|
89
|
+
end
|
90
|
+
|
91
|
+
def to_s
|
92
|
+
"#{@name} = #{@value}"
|
93
|
+
end
|
94
|
+
|
56
95
|
def evaluate
|
57
96
|
ScopeManager.add_func_to_global_scope(@name, @value, @args)
|
97
|
+
create_tree_entry if PRINT_TREE_FLAG
|
58
98
|
return nil
|
59
99
|
end
|
60
100
|
end
|
@@ -67,6 +107,20 @@ class FuncCallNode < Node
|
|
67
107
|
@args = args
|
68
108
|
end
|
69
109
|
|
110
|
+
def to_s
|
111
|
+
if @args == NilClass
|
112
|
+
"#{name}()"
|
113
|
+
else
|
114
|
+
"#{name}(#{@args})"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def create_tree_entry
|
119
|
+
result = set_up_scope_header
|
120
|
+
result += "Function #{@name} is called"
|
121
|
+
TREE_ARRAY << result unless TREE_ARRAY[-1] == result
|
122
|
+
end
|
123
|
+
|
70
124
|
def evaluate
|
71
125
|
func = ScopeManager.lookup_func(@name)
|
72
126
|
|
@@ -95,6 +149,7 @@ class FuncCallNode < Node
|
|
95
149
|
ScopeManager.scope_lvl = old_scope_lvl
|
96
150
|
end
|
97
151
|
|
152
|
+
create_tree_entry if PRINT_TREE_FLAG
|
98
153
|
return func_return_value
|
99
154
|
end
|
100
155
|
end
|
@@ -108,8 +163,20 @@ class IfNode < Node
|
|
108
163
|
@argument, @node = argument, node
|
109
164
|
end
|
110
165
|
|
166
|
+
def to_s
|
167
|
+
"If #{argument}"
|
168
|
+
end
|
169
|
+
|
170
|
+
def create_tree_entry
|
171
|
+
result = set_up_scope_header
|
172
|
+
result += "If statement #{@argument} is used"
|
173
|
+
TREE_ARRAY << result unless TREE_ARRAY[-1] == result
|
174
|
+
end
|
175
|
+
|
111
176
|
def evaluate
|
112
177
|
@value = @node.evaluate
|
178
|
+
create_tree_entry if PRINT_TREE_FLAG
|
179
|
+
@value
|
113
180
|
end
|
114
181
|
end
|
115
182
|
|
@@ -120,8 +187,20 @@ class ElseifNode < Node
|
|
120
187
|
@argument, @node = argument, node
|
121
188
|
end
|
122
189
|
|
190
|
+
def to_s
|
191
|
+
'Else'
|
192
|
+
end
|
193
|
+
|
194
|
+
def create_tree_entry
|
195
|
+
result = set_up_scope_header
|
196
|
+
result += "Elseif statement is used. #{@argument}"
|
197
|
+
TREE_ARRAY << result unless TREE_ARRAY[-1] == result
|
198
|
+
end
|
199
|
+
|
123
200
|
def evaluate
|
124
201
|
@value = @node.evaluate
|
202
|
+
create_tree_entry if PRINT_TREE_FLAG
|
203
|
+
@value
|
125
204
|
end
|
126
205
|
end
|
127
206
|
|
@@ -133,8 +212,16 @@ class ElseNode < Node
|
|
133
212
|
@argument = BoolNode.new(ScopeManager.true_value)
|
134
213
|
end
|
135
214
|
|
215
|
+
def create_tree_entry
|
216
|
+
result = set_up_scope_header
|
217
|
+
result += "Else statement is used."
|
218
|
+
TREE_ARRAY << result unless TREE_ARRAY[-1] == result
|
219
|
+
end
|
220
|
+
|
136
221
|
def evaluate
|
137
222
|
@value = @node.evaluate
|
223
|
+
create_tree_entry if PRINT_TREE_FLAG
|
224
|
+
@value
|
138
225
|
end
|
139
226
|
end
|
140
227
|
|
@@ -163,10 +250,19 @@ class WhileLoopNode < Node
|
|
163
250
|
super(statement)
|
164
251
|
end
|
165
252
|
|
253
|
+
def create_tree_entry
|
254
|
+
result = set_up_scope_header
|
255
|
+
result += "While Loop ran with #{@counter} iterations."
|
256
|
+
TREE_ARRAY << result unless TREE_ARRAY[-1] == result
|
257
|
+
end
|
258
|
+
|
166
259
|
def evaluate
|
260
|
+
@counter = 0
|
167
261
|
while @condition.evaluate
|
168
262
|
@value.evaluate
|
263
|
+
@counter += 1
|
169
264
|
end
|
265
|
+
create_tree_entry if PRINT_TREE_FLAG
|
170
266
|
self.class
|
171
267
|
end
|
172
268
|
end
|
@@ -180,16 +276,20 @@ class PrintNode
|
|
180
276
|
@value = value
|
181
277
|
end
|
182
278
|
|
279
|
+
def create_tree_entry
|
280
|
+
result = set_up_scope_header
|
281
|
+
result += "Printed #{@value}."
|
282
|
+
TREE_ARRAY << result unless TREE_ARRAY[-1] == result
|
283
|
+
end
|
284
|
+
|
183
285
|
def evaluate
|
184
286
|
if @value.evaluate.is_a?(ArrayNode)
|
185
287
|
print "Array #{@value.name}: " unless TEST_UNIT_ACTIVE
|
186
288
|
puts @value.evaluate unless TEST_UNIT_ACTIVE
|
187
|
-
elsif @value.evaluate.is_a?(Array)
|
188
|
-
print "Array #{@value.name}: " unless TEST_UNIT_ACTIVE
|
189
|
-
puts @value.evaluate.join(', ') unless TEST_UNIT_ACTIVE
|
190
289
|
else
|
191
290
|
puts @value.evaluate unless TEST_UNIT_ACTIVE
|
192
291
|
end
|
292
|
+
create_tree_entry if PRINT_TREE_FLAG
|
193
293
|
self.class
|
194
294
|
end
|
195
295
|
end
|
@@ -199,8 +299,15 @@ class PauseNode < Node
|
|
199
299
|
super(value)
|
200
300
|
end
|
201
301
|
|
302
|
+
def create_tree_entry
|
303
|
+
result = set_up_scope_header
|
304
|
+
result += "Paused for #{@value} seconds."
|
305
|
+
TREE_ARRAY << result unless TREE_ARRAY[-1] == result
|
306
|
+
end
|
307
|
+
|
202
308
|
def evaluate
|
203
309
|
@value = 0 if @value.evaluate.negative?
|
310
|
+
create_tree_entry if PRINT_TREE_FLAG
|
204
311
|
sleep @value.evaluate
|
205
312
|
end
|
206
313
|
end
|