Module: Arithmetic

Includes:
Treetop::Runtime
Included in:
ArithmeticParser, SimpleSem
Defined in:
lib/simplesem/arithmetic.rb,
lib/simplesem/arithmetic_node_classes.rb

Defined Under Namespace

Modules: Additive0, AdditiveOp0, AdditiveOp1, Comparative0, ComparisonOp0, ComparisonOp1, ComparisonOp2, ComparisonOp3, ComparisonOp4, ComparisonOp5, Multitive0, MultitiveOp0, MultitiveOp1, Number0, Number1 Classes: BinaryOperation

Instance Method Summary collapse

Instance Method Details

#_nt_additiveObject



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
# File 'lib/simplesem/arithmetic.rb', line 244

def _nt_additive
  start_index = index
  if node_cache[:additive].has_key?(index)
    cached = node_cache[:additive][index]
    @index = cached.interval.end if cached
    return cached
  end

  i0 = index
  i1, s1 = index, []
  r2 = _nt_multitive
  s1 << r2
  if r2
    r3 = _nt_space
    s1 << r3
    if r3
      r4 = _nt_additive_op
      s1 << r4
      if r4
        r5 = _nt_space
        s1 << r5
        if r5
          r6 = _nt_additive
          s1 << r6
        end
      end
    end
  end
  if s1.last
    r1 = (BinaryOperation).new(input, i1...index, s1)
    r1.extend(Additive0)
  else
    self.index = i1
    r1 = nil
  end
  if r1
    r0 = r1
  else
    r7 = _nt_multitive
    if r7
      r0 = r7
    else
      self.index = i0
      r0 = nil
    end
  end

  node_cache[:additive][start_index] = r0

  return r0
end

#_nt_additive_opObject



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/simplesem/arithmetic.rb', line 308

def _nt_additive_op
  start_index = index
  if node_cache[:additive_op].has_key?(index)
    cached = node_cache[:additive_op][index]
    @index = cached.interval.end if cached
    return cached
  end

  i0 = index
  if input.index('+', index) == index
    r1 = (SyntaxNode).new(input, index...(index + 1))
    r1.extend(AdditiveOp0)
    @index += 1
  else
    terminal_parse_failure('+')
    r1 = nil
  end
  if r1
    r0 = r1
  else
    if input.index('-', index) == index
      r2 = (SyntaxNode).new(input, index...(index + 1))
      r2.extend(AdditiveOp1)
      @index += 1
    else
      terminal_parse_failure('-')
      r2 = nil
    end
    if r2
      r0 = r2
    else
      self.index = i0
      r0 = nil
    end
  end

  node_cache[:additive_op][start_index] = r0

  return r0
end

#_nt_comparativeObject



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
# File 'lib/simplesem/arithmetic.rb', line 57

def _nt_comparative
  start_index = index
  if node_cache[:comparative].has_key?(index)
    cached = node_cache[:comparative][index]
    @index = cached.interval.end if cached
    return cached
  end

  i0, s0 = index, []
  r1 = _nt_additive
  s0 << r1
  if r1
    r2 = _nt_space
    s0 << r2
    if r2
      r3 = _nt_comparison_op
      s0 << r3
      if r3
        r4 = _nt_space
        s0 << r4
        if r4
          r5 = _nt_additive
          s0 << r5
        end
      end
    end
  end
  if s0.last
    r0 = (BinaryOperation).new(input, i0...index, s0)
    r0.extend(Comparative0)
  else
    self.index = i0
    r0 = nil
  end

  node_cache[:comparative][start_index] = r0

  return r0
end

#_nt_comparison_opObject



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
# File 'lib/simplesem/arithmetic.rb', line 133

def _nt_comparison_op
  start_index = index
  if node_cache[:comparison_op].has_key?(index)
    cached = node_cache[:comparison_op][index]
    @index = cached.interval.end if cached
    return cached
  end

  i0 = index
  if input.index('>=', index) == index
    r1 = (SyntaxNode).new(input, index...(index + 2))
    r1.extend(ComparisonOp0)
    @index += 2
  else
    terminal_parse_failure('>=')
    r1 = nil
  end
  if r1
    r0 = r1
  else
    if input.index('<=', index) == index
      r2 = (SyntaxNode).new(input, index...(index + 2))
      r2.extend(ComparisonOp1)
      @index += 2
    else
      terminal_parse_failure('<=')
      r2 = nil
    end
    if r2
      r0 = r2
    else
      if input.index('>', index) == index
        r3 = (SyntaxNode).new(input, index...(index + 1))
        r3.extend(ComparisonOp2)
        @index += 1
      else
        terminal_parse_failure('>')
        r3 = nil
      end
      if r3
        r0 = r3
      else
        if input.index('<', index) == index
          r4 = (SyntaxNode).new(input, index...(index + 1))
          r4.extend(ComparisonOp3)
          @index += 1
        else
          terminal_parse_failure('<')
          r4 = nil
        end
        if r4
          r0 = r4
        else
          if input.index('!=', index) == index
            r5 = (SyntaxNode).new(input, index...(index + 2))
            r5.extend(ComparisonOp4)
            @index += 2
          else
            terminal_parse_failure('!=')
            r5 = nil
          end
          if r5
            r0 = r5
          else
            if input.index('=', index) == index
              r6 = (SyntaxNode).new(input, index...(index + 1))
              r6.extend(ComparisonOp5)
              @index += 1
            else
              terminal_parse_failure('=')
              r6 = nil
            end
            if r6
              r0 = r6
            else
              self.index = i0
              r0 = nil
            end
          end
        end
      end
    end
  end

  node_cache[:comparison_op][start_index] = r0

  return r0
end

#_nt_expressionObject



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
# File 'lib/simplesem/arithmetic.rb', line 8

def _nt_expression
  start_index = index
  if node_cache[:expression].has_key?(index)
    cached = node_cache[:expression][index]
    @index = cached.interval.end if cached
    return cached
  end

  i0 = index
  r1 = _nt_comparative
  if r1
    r0 = r1
  else
    r2 = _nt_additive
    if r2
      r0 = r2
    else
      self.index = i0
      r0 = nil
    end
  end

  node_cache[:expression][start_index] = r0

  return r0
end

#_nt_multitiveObject



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/simplesem/arithmetic.rb', line 371

def _nt_multitive
  start_index = index
  if node_cache[:multitive].has_key?(index)
    cached = node_cache[:multitive][index]
    @index = cached.interval.end if cached
    return cached
  end

  i0 = index
  i1, s1 = index, []
  r2 = _nt_primary
  s1 << r2
  if r2
    r3 = _nt_space
    s1 << r3
    if r3
      r4 = _nt_multitive_op
      s1 << r4
      if r4
        r5 = _nt_space
        s1 << r5
        if r5
          r6 = _nt_multitive
          s1 << r6
        end
      end
    end
  end
  if s1.last
    r1 = (BinaryOperation).new(input, i1...index, s1)
    r1.extend(Multitive0)
  else
    self.index = i1
    r1 = nil
  end
  if r1
    r0 = r1
  else
    r7 = _nt_primary
    if r7
      r0 = r7
    else
      self.index = i0
      r0 = nil
    end
  end

  node_cache[:multitive][start_index] = r0

  return r0
end

#_nt_multitive_opObject



435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/simplesem/arithmetic.rb', line 435

def _nt_multitive_op
  start_index = index
  if node_cache[:multitive_op].has_key?(index)
    cached = node_cache[:multitive_op][index]
    @index = cached.interval.end if cached
    return cached
  end

  i0 = index
  if input.index('*', index) == index
    r1 = (SyntaxNode).new(input, index...(index + 1))
    r1.extend(MultitiveOp0)
    @index += 1
  else
    terminal_parse_failure('*')
    r1 = nil
  end
  if r1
    r0 = r1
  else
    if input.index('/', index) == index
      r2 = (SyntaxNode).new(input, index...(index + 1))
      r2.extend(MultitiveOp1)
      @index += 1
    else
      terminal_parse_failure('/')
      r2 = nil
    end
    if r2
      r0 = r2
    else
      self.index = i0
      r0 = nil
    end
  end

  node_cache[:multitive_op][start_index] = r0

  return r0
end

#_nt_numberObject



485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
# File 'lib/simplesem/arithmetic.rb', line 485

def _nt_number
  start_index = index
  if node_cache[:number].has_key?(index)
    cached = node_cache[:number][index]
    @index = cached.interval.end if cached
    return cached
  end

  i0 = index
  i1, s1 = index, []
  if input.index('-', index) == index
    r3 = (SyntaxNode).new(input, index...(index + 1))
    @index += 1
  else
    terminal_parse_failure('-')
    r3 = nil
  end
  if r3
    r2 = r3
  else
    r2 = SyntaxNode.new(input, index...index)
  end
  s1 << r2
  if r2
    if input.index(Regexp.new('[1-9]'), index) == index
      r4 = (SyntaxNode).new(input, index...(index + 1))
      @index += 1
    else
      r4 = nil
    end
    s1 << r4
    if r4
      s5, i5 = [], index
      loop do
        if input.index(Regexp.new('[0-9]'), index) == index
          r6 = (SyntaxNode).new(input, index...(index + 1))
          @index += 1
        else
          r6 = nil
        end
        if r6
          s5 << r6
        else
          break
        end
      end
      r5 = SyntaxNode.new(input, i5...index, s5)
      s1 << r5
    end
  end
  if s1.last
    r1 = (SyntaxNode).new(input, i1...index, s1)
    r1.extend(Number0)
  else
    self.index = i1
    r1 = nil
  end
  if r1
    r0 = r1
    r0.extend(Number1)
  else
    if input.index('0', index) == index
      r7 = (SyntaxNode).new(input, index...(index + 1))
      @index += 1
    else
      terminal_parse_failure('0')
      r7 = nil
    end
    if r7
      r0 = r7
      r0.extend(Number1)
    else
      self.index = i0
      r0 = nil
    end
  end

  node_cache[:number][start_index] = r0

  return r0
end

#_nt_spaceObject



567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/simplesem/arithmetic.rb', line 567

def _nt_space
  start_index = index
  if node_cache[:space].has_key?(index)
    cached = node_cache[:space][index]
    @index = cached.interval.end if cached
    return cached
  end

  s0, i0 = [], index
  loop do
    if input.index(' ', index) == index
      r1 = (SyntaxNode).new(input, index...(index + 1))
      @index += 1
    else
      terminal_parse_failure(' ')
      r1 = nil
    end
    if r1
      s0 << r1
    else
      break
    end
  end
  r0 = SyntaxNode.new(input, i0...index, s0)

  node_cache[:space][start_index] = r0

  return r0
end

#rootObject



4
5
6
# File 'lib/simplesem/arithmetic.rb', line 4

def root
  @root || :expression
end