robolson-simplesem 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/simplesem.gemspec +6 -6
- metadata +3 -7
- data/lib/simplesem/arithmetic.rb +0 -601
- data/lib/simplesem/simple_sem.rb +0 -823
data/Rakefile
CHANGED
@@ -2,12 +2,12 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('simplesem', '0.1.
|
5
|
+
Echoe.new('simplesem', '0.1.2') do |p|
|
6
6
|
p.description = "SIMPLESEM Interpreter"
|
7
7
|
p.url = "http://github.com/robolson/simplesem"
|
8
8
|
p.author = "Rob Olson"
|
9
9
|
p.email = "rko618@gmail.com"
|
10
|
-
p.
|
10
|
+
p.runtime_dependencies = ["treetop >=1.2.4"]
|
11
11
|
end
|
12
12
|
|
13
13
|
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/simplesem.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{simplesem}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Rob Olson"]
|
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.description = %q{SIMPLESEM Interpreter}
|
12
12
|
s.email = %q{rko618@gmail.com}
|
13
13
|
s.executables = ["simplesem"]
|
14
|
-
s.extra_rdoc_files = ["LICENSE", "README.textile", "bin/simplesem", "lib/simplesem/arithmetic.
|
15
|
-
s.files = ["LICENSE", "Manifest", "README.textile", "Rakefile", "bin/simplesem", "lib/simplesem/arithmetic.
|
14
|
+
s.extra_rdoc_files = ["LICENSE", "README.textile", "bin/simplesem", "lib/simplesem/arithmetic.treetop", "lib/simplesem/arithmetic_node_classes.rb", "lib/simplesem/simple_sem.treetop", "lib/simplesem/simplesem_program.rb", "lib/simplesem.rb"]
|
15
|
+
s.files = ["LICENSE", "Manifest", "README.textile", "Rakefile", "bin/simplesem", "lib/simplesem/arithmetic.treetop", "lib/simplesem/arithmetic_node_classes.rb", "lib/simplesem/simple_sem.treetop", "lib/simplesem/simplesem_program.rb", "lib/simplesem.rb", "sample_programs/case-statement.txt", "sample_programs/gcd.txt", "sample_programs/hello-world.txt", "sample_programs/while-loop.txt", "simplesem.gemspec", "simplesem.tmproj", "test/simplesem_test.rb", "test/test_helper.rb"]
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.homepage = %q{http://github.com/robolson/simplesem}
|
18
18
|
s.rdoc_options = ["--line-numbers", "--title", "Simplesem", "--main", "README.textile"]
|
@@ -27,11 +27,11 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.specification_version = 2
|
28
28
|
|
29
29
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
30
|
-
s.
|
30
|
+
s.add_runtime_dependency(%q<treetop>, [">= 1.2.4"])
|
31
31
|
else
|
32
|
-
s.add_dependency(%q<treetop>, [">=
|
32
|
+
s.add_dependency(%q<treetop>, [">= 1.2.4"])
|
33
33
|
end
|
34
34
|
else
|
35
|
-
s.add_dependency(%q<treetop>, [">=
|
35
|
+
s.add_dependency(%q<treetop>, [">= 1.2.4"])
|
36
36
|
end
|
37
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: robolson-simplesem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Olson
|
@@ -14,13 +14,13 @@ default_executable: simplesem
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: treetop
|
17
|
-
type: :
|
17
|
+
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 1.2.4
|
24
24
|
version:
|
25
25
|
description: SIMPLESEM Interpreter
|
26
26
|
email: rko618@gmail.com
|
@@ -32,10 +32,8 @@ extra_rdoc_files:
|
|
32
32
|
- LICENSE
|
33
33
|
- README.textile
|
34
34
|
- bin/simplesem
|
35
|
-
- lib/simplesem/arithmetic.rb
|
36
35
|
- lib/simplesem/arithmetic.treetop
|
37
36
|
- lib/simplesem/arithmetic_node_classes.rb
|
38
|
-
- lib/simplesem/simple_sem.rb
|
39
37
|
- lib/simplesem/simple_sem.treetop
|
40
38
|
- lib/simplesem/simplesem_program.rb
|
41
39
|
- lib/simplesem.rb
|
@@ -45,10 +43,8 @@ files:
|
|
45
43
|
- README.textile
|
46
44
|
- Rakefile
|
47
45
|
- bin/simplesem
|
48
|
-
- lib/simplesem/arithmetic.rb
|
49
46
|
- lib/simplesem/arithmetic.treetop
|
50
47
|
- lib/simplesem/arithmetic_node_classes.rb
|
51
|
-
- lib/simplesem/simple_sem.rb
|
52
48
|
- lib/simplesem/simple_sem.treetop
|
53
49
|
- lib/simplesem/simplesem_program.rb
|
54
50
|
- lib/simplesem.rb
|
data/lib/simplesem/arithmetic.rb
DELETED
@@ -1,601 +0,0 @@
|
|
1
|
-
module Arithmetic
|
2
|
-
include Treetop::Runtime
|
3
|
-
|
4
|
-
def root
|
5
|
-
@root || :expression
|
6
|
-
end
|
7
|
-
|
8
|
-
def _nt_expression
|
9
|
-
start_index = index
|
10
|
-
if node_cache[:expression].has_key?(index)
|
11
|
-
cached = node_cache[:expression][index]
|
12
|
-
@index = cached.interval.end if cached
|
13
|
-
return cached
|
14
|
-
end
|
15
|
-
|
16
|
-
i0 = index
|
17
|
-
r1 = _nt_comparative
|
18
|
-
if r1
|
19
|
-
r0 = r1
|
20
|
-
else
|
21
|
-
r2 = _nt_additive
|
22
|
-
if r2
|
23
|
-
r0 = r2
|
24
|
-
else
|
25
|
-
self.index = i0
|
26
|
-
r0 = nil
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
node_cache[:expression][start_index] = r0
|
31
|
-
|
32
|
-
return r0
|
33
|
-
end
|
34
|
-
|
35
|
-
module Comparative0
|
36
|
-
def operand_1
|
37
|
-
elements[0]
|
38
|
-
end
|
39
|
-
|
40
|
-
def space
|
41
|
-
elements[1]
|
42
|
-
end
|
43
|
-
|
44
|
-
def operator
|
45
|
-
elements[2]
|
46
|
-
end
|
47
|
-
|
48
|
-
def space
|
49
|
-
elements[3]
|
50
|
-
end
|
51
|
-
|
52
|
-
def operand_2
|
53
|
-
elements[4]
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def _nt_comparative
|
58
|
-
start_index = index
|
59
|
-
if node_cache[:comparative].has_key?(index)
|
60
|
-
cached = node_cache[:comparative][index]
|
61
|
-
@index = cached.interval.end if cached
|
62
|
-
return cached
|
63
|
-
end
|
64
|
-
|
65
|
-
i0, s0 = index, []
|
66
|
-
r1 = _nt_additive
|
67
|
-
s0 << r1
|
68
|
-
if r1
|
69
|
-
r2 = _nt_space
|
70
|
-
s0 << r2
|
71
|
-
if r2
|
72
|
-
r3 = _nt_comparison_op
|
73
|
-
s0 << r3
|
74
|
-
if r3
|
75
|
-
r4 = _nt_space
|
76
|
-
s0 << r4
|
77
|
-
if r4
|
78
|
-
r5 = _nt_additive
|
79
|
-
s0 << r5
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
if s0.last
|
85
|
-
r0 = (BinaryOperation).new(input, i0...index, s0)
|
86
|
-
r0.extend(Comparative0)
|
87
|
-
else
|
88
|
-
self.index = i0
|
89
|
-
r0 = nil
|
90
|
-
end
|
91
|
-
|
92
|
-
node_cache[:comparative][start_index] = r0
|
93
|
-
|
94
|
-
return r0
|
95
|
-
end
|
96
|
-
|
97
|
-
module ComparisonOp0
|
98
|
-
def apply(a, b)
|
99
|
-
a >= b
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
module ComparisonOp1
|
104
|
-
def apply(a, b)
|
105
|
-
a <= b
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
module ComparisonOp2
|
110
|
-
def apply(a, b)
|
111
|
-
a > b
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
module ComparisonOp3
|
116
|
-
def apply(a, b)
|
117
|
-
a < b
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
module ComparisonOp4
|
122
|
-
def apply(a, b)
|
123
|
-
a != b
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
module ComparisonOp5
|
128
|
-
def apply(a, b)
|
129
|
-
a == b
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def _nt_comparison_op
|
134
|
-
start_index = index
|
135
|
-
if node_cache[:comparison_op].has_key?(index)
|
136
|
-
cached = node_cache[:comparison_op][index]
|
137
|
-
@index = cached.interval.end if cached
|
138
|
-
return cached
|
139
|
-
end
|
140
|
-
|
141
|
-
i0 = index
|
142
|
-
if input.index('>=', index) == index
|
143
|
-
r1 = (SyntaxNode).new(input, index...(index + 2))
|
144
|
-
r1.extend(ComparisonOp0)
|
145
|
-
@index += 2
|
146
|
-
else
|
147
|
-
terminal_parse_failure('>=')
|
148
|
-
r1 = nil
|
149
|
-
end
|
150
|
-
if r1
|
151
|
-
r0 = r1
|
152
|
-
else
|
153
|
-
if input.index('<=', index) == index
|
154
|
-
r2 = (SyntaxNode).new(input, index...(index + 2))
|
155
|
-
r2.extend(ComparisonOp1)
|
156
|
-
@index += 2
|
157
|
-
else
|
158
|
-
terminal_parse_failure('<=')
|
159
|
-
r2 = nil
|
160
|
-
end
|
161
|
-
if r2
|
162
|
-
r0 = r2
|
163
|
-
else
|
164
|
-
if input.index('>', index) == index
|
165
|
-
r3 = (SyntaxNode).new(input, index...(index + 1))
|
166
|
-
r3.extend(ComparisonOp2)
|
167
|
-
@index += 1
|
168
|
-
else
|
169
|
-
terminal_parse_failure('>')
|
170
|
-
r3 = nil
|
171
|
-
end
|
172
|
-
if r3
|
173
|
-
r0 = r3
|
174
|
-
else
|
175
|
-
if input.index('<', index) == index
|
176
|
-
r4 = (SyntaxNode).new(input, index...(index + 1))
|
177
|
-
r4.extend(ComparisonOp3)
|
178
|
-
@index += 1
|
179
|
-
else
|
180
|
-
terminal_parse_failure('<')
|
181
|
-
r4 = nil
|
182
|
-
end
|
183
|
-
if r4
|
184
|
-
r0 = r4
|
185
|
-
else
|
186
|
-
if input.index('!=', index) == index
|
187
|
-
r5 = (SyntaxNode).new(input, index...(index + 2))
|
188
|
-
r5.extend(ComparisonOp4)
|
189
|
-
@index += 2
|
190
|
-
else
|
191
|
-
terminal_parse_failure('!=')
|
192
|
-
r5 = nil
|
193
|
-
end
|
194
|
-
if r5
|
195
|
-
r0 = r5
|
196
|
-
else
|
197
|
-
if input.index('=', index) == index
|
198
|
-
r6 = (SyntaxNode).new(input, index...(index + 1))
|
199
|
-
r6.extend(ComparisonOp5)
|
200
|
-
@index += 1
|
201
|
-
else
|
202
|
-
terminal_parse_failure('=')
|
203
|
-
r6 = nil
|
204
|
-
end
|
205
|
-
if r6
|
206
|
-
r0 = r6
|
207
|
-
else
|
208
|
-
self.index = i0
|
209
|
-
r0 = nil
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
node_cache[:comparison_op][start_index] = r0
|
218
|
-
|
219
|
-
return r0
|
220
|
-
end
|
221
|
-
|
222
|
-
module Additive0
|
223
|
-
def operand_1
|
224
|
-
elements[0]
|
225
|
-
end
|
226
|
-
|
227
|
-
def space
|
228
|
-
elements[1]
|
229
|
-
end
|
230
|
-
|
231
|
-
def operator
|
232
|
-
elements[2]
|
233
|
-
end
|
234
|
-
|
235
|
-
def space
|
236
|
-
elements[3]
|
237
|
-
end
|
238
|
-
|
239
|
-
def operand_2
|
240
|
-
elements[4]
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
def _nt_additive
|
245
|
-
start_index = index
|
246
|
-
if node_cache[:additive].has_key?(index)
|
247
|
-
cached = node_cache[:additive][index]
|
248
|
-
@index = cached.interval.end if cached
|
249
|
-
return cached
|
250
|
-
end
|
251
|
-
|
252
|
-
i0 = index
|
253
|
-
i1, s1 = index, []
|
254
|
-
r2 = _nt_multitive
|
255
|
-
s1 << r2
|
256
|
-
if r2
|
257
|
-
r3 = _nt_space
|
258
|
-
s1 << r3
|
259
|
-
if r3
|
260
|
-
r4 = _nt_additive_op
|
261
|
-
s1 << r4
|
262
|
-
if r4
|
263
|
-
r5 = _nt_space
|
264
|
-
s1 << r5
|
265
|
-
if r5
|
266
|
-
r6 = _nt_additive
|
267
|
-
s1 << r6
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
if s1.last
|
273
|
-
r1 = (BinaryOperation).new(input, i1...index, s1)
|
274
|
-
r1.extend(Additive0)
|
275
|
-
else
|
276
|
-
self.index = i1
|
277
|
-
r1 = nil
|
278
|
-
end
|
279
|
-
if r1
|
280
|
-
r0 = r1
|
281
|
-
else
|
282
|
-
r7 = _nt_multitive
|
283
|
-
if r7
|
284
|
-
r0 = r7
|
285
|
-
else
|
286
|
-
self.index = i0
|
287
|
-
r0 = nil
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
node_cache[:additive][start_index] = r0
|
292
|
-
|
293
|
-
return r0
|
294
|
-
end
|
295
|
-
|
296
|
-
module AdditiveOp0
|
297
|
-
def apply(a, b)
|
298
|
-
a + b
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
module AdditiveOp1
|
303
|
-
def apply(a, b)
|
304
|
-
a - b
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
def _nt_additive_op
|
309
|
-
start_index = index
|
310
|
-
if node_cache[:additive_op].has_key?(index)
|
311
|
-
cached = node_cache[:additive_op][index]
|
312
|
-
@index = cached.interval.end if cached
|
313
|
-
return cached
|
314
|
-
end
|
315
|
-
|
316
|
-
i0 = index
|
317
|
-
if input.index('+', index) == index
|
318
|
-
r1 = (SyntaxNode).new(input, index...(index + 1))
|
319
|
-
r1.extend(AdditiveOp0)
|
320
|
-
@index += 1
|
321
|
-
else
|
322
|
-
terminal_parse_failure('+')
|
323
|
-
r1 = nil
|
324
|
-
end
|
325
|
-
if r1
|
326
|
-
r0 = r1
|
327
|
-
else
|
328
|
-
if input.index('-', index) == index
|
329
|
-
r2 = (SyntaxNode).new(input, index...(index + 1))
|
330
|
-
r2.extend(AdditiveOp1)
|
331
|
-
@index += 1
|
332
|
-
else
|
333
|
-
terminal_parse_failure('-')
|
334
|
-
r2 = nil
|
335
|
-
end
|
336
|
-
if r2
|
337
|
-
r0 = r2
|
338
|
-
else
|
339
|
-
self.index = i0
|
340
|
-
r0 = nil
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
node_cache[:additive_op][start_index] = r0
|
345
|
-
|
346
|
-
return r0
|
347
|
-
end
|
348
|
-
|
349
|
-
module Multitive0
|
350
|
-
def operand_1
|
351
|
-
elements[0]
|
352
|
-
end
|
353
|
-
|
354
|
-
def space
|
355
|
-
elements[1]
|
356
|
-
end
|
357
|
-
|
358
|
-
def operator
|
359
|
-
elements[2]
|
360
|
-
end
|
361
|
-
|
362
|
-
def space
|
363
|
-
elements[3]
|
364
|
-
end
|
365
|
-
|
366
|
-
def operand_2
|
367
|
-
elements[4]
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
def _nt_multitive
|
372
|
-
start_index = index
|
373
|
-
if node_cache[:multitive].has_key?(index)
|
374
|
-
cached = node_cache[:multitive][index]
|
375
|
-
@index = cached.interval.end if cached
|
376
|
-
return cached
|
377
|
-
end
|
378
|
-
|
379
|
-
i0 = index
|
380
|
-
i1, s1 = index, []
|
381
|
-
r2 = _nt_primary
|
382
|
-
s1 << r2
|
383
|
-
if r2
|
384
|
-
r3 = _nt_space
|
385
|
-
s1 << r3
|
386
|
-
if r3
|
387
|
-
r4 = _nt_multitive_op
|
388
|
-
s1 << r4
|
389
|
-
if r4
|
390
|
-
r5 = _nt_space
|
391
|
-
s1 << r5
|
392
|
-
if r5
|
393
|
-
r6 = _nt_multitive
|
394
|
-
s1 << r6
|
395
|
-
end
|
396
|
-
end
|
397
|
-
end
|
398
|
-
end
|
399
|
-
if s1.last
|
400
|
-
r1 = (BinaryOperation).new(input, i1...index, s1)
|
401
|
-
r1.extend(Multitive0)
|
402
|
-
else
|
403
|
-
self.index = i1
|
404
|
-
r1 = nil
|
405
|
-
end
|
406
|
-
if r1
|
407
|
-
r0 = r1
|
408
|
-
else
|
409
|
-
r7 = _nt_primary
|
410
|
-
if r7
|
411
|
-
r0 = r7
|
412
|
-
else
|
413
|
-
self.index = i0
|
414
|
-
r0 = nil
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
node_cache[:multitive][start_index] = r0
|
419
|
-
|
420
|
-
return r0
|
421
|
-
end
|
422
|
-
|
423
|
-
module MultitiveOp0
|
424
|
-
def apply(a, b)
|
425
|
-
a * b
|
426
|
-
end
|
427
|
-
end
|
428
|
-
|
429
|
-
module MultitiveOp1
|
430
|
-
def apply(a, b)
|
431
|
-
a / b
|
432
|
-
end
|
433
|
-
end
|
434
|
-
|
435
|
-
def _nt_multitive_op
|
436
|
-
start_index = index
|
437
|
-
if node_cache[:multitive_op].has_key?(index)
|
438
|
-
cached = node_cache[:multitive_op][index]
|
439
|
-
@index = cached.interval.end if cached
|
440
|
-
return cached
|
441
|
-
end
|
442
|
-
|
443
|
-
i0 = index
|
444
|
-
if input.index('*', index) == index
|
445
|
-
r1 = (SyntaxNode).new(input, index...(index + 1))
|
446
|
-
r1.extend(MultitiveOp0)
|
447
|
-
@index += 1
|
448
|
-
else
|
449
|
-
terminal_parse_failure('*')
|
450
|
-
r1 = nil
|
451
|
-
end
|
452
|
-
if r1
|
453
|
-
r0 = r1
|
454
|
-
else
|
455
|
-
if input.index('/', index) == index
|
456
|
-
r2 = (SyntaxNode).new(input, index...(index + 1))
|
457
|
-
r2.extend(MultitiveOp1)
|
458
|
-
@index += 1
|
459
|
-
else
|
460
|
-
terminal_parse_failure('/')
|
461
|
-
r2 = nil
|
462
|
-
end
|
463
|
-
if r2
|
464
|
-
r0 = r2
|
465
|
-
else
|
466
|
-
self.index = i0
|
467
|
-
r0 = nil
|
468
|
-
end
|
469
|
-
end
|
470
|
-
|
471
|
-
node_cache[:multitive_op][start_index] = r0
|
472
|
-
|
473
|
-
return r0
|
474
|
-
end
|
475
|
-
|
476
|
-
module Number0
|
477
|
-
end
|
478
|
-
|
479
|
-
module Number1
|
480
|
-
def eval(env={})
|
481
|
-
text_value.to_i
|
482
|
-
end
|
483
|
-
end
|
484
|
-
|
485
|
-
def _nt_number
|
486
|
-
start_index = index
|
487
|
-
if node_cache[:number].has_key?(index)
|
488
|
-
cached = node_cache[:number][index]
|
489
|
-
@index = cached.interval.end if cached
|
490
|
-
return cached
|
491
|
-
end
|
492
|
-
|
493
|
-
i0 = index
|
494
|
-
i1, s1 = index, []
|
495
|
-
if input.index('-', index) == index
|
496
|
-
r3 = (SyntaxNode).new(input, index...(index + 1))
|
497
|
-
@index += 1
|
498
|
-
else
|
499
|
-
terminal_parse_failure('-')
|
500
|
-
r3 = nil
|
501
|
-
end
|
502
|
-
if r3
|
503
|
-
r2 = r3
|
504
|
-
else
|
505
|
-
r2 = SyntaxNode.new(input, index...index)
|
506
|
-
end
|
507
|
-
s1 << r2
|
508
|
-
if r2
|
509
|
-
if input.index(Regexp.new('[1-9]'), index) == index
|
510
|
-
r4 = (SyntaxNode).new(input, index...(index + 1))
|
511
|
-
@index += 1
|
512
|
-
else
|
513
|
-
r4 = nil
|
514
|
-
end
|
515
|
-
s1 << r4
|
516
|
-
if r4
|
517
|
-
s5, i5 = [], index
|
518
|
-
loop do
|
519
|
-
if input.index(Regexp.new('[0-9]'), index) == index
|
520
|
-
r6 = (SyntaxNode).new(input, index...(index + 1))
|
521
|
-
@index += 1
|
522
|
-
else
|
523
|
-
r6 = nil
|
524
|
-
end
|
525
|
-
if r6
|
526
|
-
s5 << r6
|
527
|
-
else
|
528
|
-
break
|
529
|
-
end
|
530
|
-
end
|
531
|
-
r5 = SyntaxNode.new(input, i5...index, s5)
|
532
|
-
s1 << r5
|
533
|
-
end
|
534
|
-
end
|
535
|
-
if s1.last
|
536
|
-
r1 = (SyntaxNode).new(input, i1...index, s1)
|
537
|
-
r1.extend(Number0)
|
538
|
-
else
|
539
|
-
self.index = i1
|
540
|
-
r1 = nil
|
541
|
-
end
|
542
|
-
if r1
|
543
|
-
r0 = r1
|
544
|
-
r0.extend(Number1)
|
545
|
-
else
|
546
|
-
if input.index('0', index) == index
|
547
|
-
r7 = (SyntaxNode).new(input, index...(index + 1))
|
548
|
-
@index += 1
|
549
|
-
else
|
550
|
-
terminal_parse_failure('0')
|
551
|
-
r7 = nil
|
552
|
-
end
|
553
|
-
if r7
|
554
|
-
r0 = r7
|
555
|
-
r0.extend(Number1)
|
556
|
-
else
|
557
|
-
self.index = i0
|
558
|
-
r0 = nil
|
559
|
-
end
|
560
|
-
end
|
561
|
-
|
562
|
-
node_cache[:number][start_index] = r0
|
563
|
-
|
564
|
-
return r0
|
565
|
-
end
|
566
|
-
|
567
|
-
def _nt_space
|
568
|
-
start_index = index
|
569
|
-
if node_cache[:space].has_key?(index)
|
570
|
-
cached = node_cache[:space][index]
|
571
|
-
@index = cached.interval.end if cached
|
572
|
-
return cached
|
573
|
-
end
|
574
|
-
|
575
|
-
s0, i0 = [], index
|
576
|
-
loop do
|
577
|
-
if input.index(' ', index) == index
|
578
|
-
r1 = (SyntaxNode).new(input, index...(index + 1))
|
579
|
-
@index += 1
|
580
|
-
else
|
581
|
-
terminal_parse_failure(' ')
|
582
|
-
r1 = nil
|
583
|
-
end
|
584
|
-
if r1
|
585
|
-
s0 << r1
|
586
|
-
else
|
587
|
-
break
|
588
|
-
end
|
589
|
-
end
|
590
|
-
r0 = SyntaxNode.new(input, i0...index, s0)
|
591
|
-
|
592
|
-
node_cache[:space][start_index] = r0
|
593
|
-
|
594
|
-
return r0
|
595
|
-
end
|
596
|
-
|
597
|
-
end
|
598
|
-
|
599
|
-
class ArithmeticParser < Treetop::Runtime::CompiledParser
|
600
|
-
include Arithmetic
|
601
|
-
end
|