ruby-ll 1.1.3-java → 2.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +68 -2
- data/doc/driver_architecture.md +32 -0
- data/ext/c/driver.c +71 -2
- data/ext/c/driver_config.c +1 -1
- data/ext/c/driver_config.h +1 -1
- data/ext/java/org/libll/Driver.java +63 -7
- data/lib/libll.jar +0 -0
- data/lib/ll.rb +1 -0
- data/lib/ll/branch.rb +7 -1
- data/lib/ll/configuration_compiler.rb +34 -9
- data/lib/ll/driver.rb +4 -0
- data/lib/ll/grammar_compiler.rb +77 -27
- data/lib/ll/lexer.rb +75 -51
- data/lib/ll/operator.rb +26 -0
- data/lib/ll/parser.rb +129 -62
- data/lib/ll/version.rb +1 -1
- metadata +59 -57
data/lib/ll/driver.rb
CHANGED
@@ -30,6 +30,10 @@ module LL
|
|
30
30
|
message = "Unexpected #{token_type}, expected #{expected} instead"
|
31
31
|
when :eof
|
32
32
|
message = "Received #{token_type} but there's nothing left to parse"
|
33
|
+
when :star
|
34
|
+
message = %Q{Unexpected #{token_type} for a "*" operator}
|
35
|
+
when :plus
|
36
|
+
message = %Q{Unexpected #{token_type} for a "+" operator}
|
33
37
|
end
|
34
38
|
|
35
39
|
return message
|
data/lib/ll/grammar_compiler.rb
CHANGED
@@ -179,7 +179,7 @@ module LL
|
|
179
179
|
##
|
180
180
|
# Processes the assignment of terminals.
|
181
181
|
#
|
182
|
-
# @see #process
|
182
|
+
# @see [#process]
|
183
183
|
#
|
184
184
|
def on_terminals(node, compiled_grammar)
|
185
185
|
node.children.each do |child|
|
@@ -199,7 +199,7 @@ module LL
|
|
199
199
|
##
|
200
200
|
# Processes an %inner directive.
|
201
201
|
#
|
202
|
-
# @see #process
|
202
|
+
# @see [#process]
|
203
203
|
#
|
204
204
|
def on_inner(node, compiled_grammar)
|
205
205
|
compiled_grammar.inner = process(node.children[0], compiled_grammar)
|
@@ -208,7 +208,7 @@ module LL
|
|
208
208
|
##
|
209
209
|
# Processes a %header directive.
|
210
210
|
#
|
211
|
-
# @see #process
|
211
|
+
# @see [#process]
|
212
212
|
#
|
213
213
|
def on_header(node, compiled_grammar)
|
214
214
|
compiled_grammar.header = process(node.children[0], compiled_grammar)
|
@@ -217,7 +217,7 @@ module LL
|
|
217
217
|
##
|
218
218
|
# Processes a node containing Ruby source code.
|
219
219
|
#
|
220
|
-
# @see #process
|
220
|
+
# @see [#process]
|
221
221
|
# @return [String]
|
222
222
|
#
|
223
223
|
def on_ruby(node, compiled_grammar)
|
@@ -227,7 +227,7 @@ module LL
|
|
227
227
|
##
|
228
228
|
# Extracts the name from an identifier.
|
229
229
|
#
|
230
|
-
# @see #process
|
230
|
+
# @see [#process]
|
231
231
|
# @return [String]
|
232
232
|
#
|
233
233
|
def on_ident(node, compiled_grammar)
|
@@ -237,7 +237,7 @@ module LL
|
|
237
237
|
##
|
238
238
|
# Processes an epsilon.
|
239
239
|
#
|
240
|
-
# @see #process
|
240
|
+
# @see [#process]
|
241
241
|
# @return [LL::Epsilon]
|
242
242
|
#
|
243
243
|
def on_epsilon(node, compiled_grammar)
|
@@ -247,7 +247,7 @@ module LL
|
|
247
247
|
##
|
248
248
|
# Processes the assignment of a rule.
|
249
249
|
#
|
250
|
-
# @see #process
|
250
|
+
# @see [#process]
|
251
251
|
#
|
252
252
|
def on_rule(node, compiled_grammar)
|
253
253
|
name = process(node.children[0], compiled_grammar)
|
@@ -280,7 +280,7 @@ module LL
|
|
280
280
|
##
|
281
281
|
# Creates a basic prototype for a rule.
|
282
282
|
#
|
283
|
-
# @see #process
|
283
|
+
# @see [#process]
|
284
284
|
#
|
285
285
|
def on_rule_prototype(node, compiled_grammar)
|
286
286
|
name = process(node.children[0], compiled_grammar)
|
@@ -295,7 +295,7 @@ module LL
|
|
295
295
|
##
|
296
296
|
# Processes a single rule branch.
|
297
297
|
#
|
298
|
-
# @see #process
|
298
|
+
# @see [#process]
|
299
299
|
# @return [LL::Branch]
|
300
300
|
#
|
301
301
|
def on_branch(node, compiled_grammar)
|
@@ -313,33 +313,53 @@ module LL
|
|
313
313
|
##
|
314
314
|
# Processes the steps of a branch.
|
315
315
|
#
|
316
|
-
# @see #process
|
316
|
+
# @see [#process]
|
317
317
|
# @return [Array]
|
318
318
|
#
|
319
319
|
def on_steps(node, compiled_grammar)
|
320
|
-
|
320
|
+
return lookup_identifiers(node, compiled_grammar)
|
321
|
+
end
|
321
322
|
|
322
|
-
|
323
|
-
|
323
|
+
##
|
324
|
+
# Processes the "*" operator.
|
325
|
+
#
|
326
|
+
# @param [LL::AST::Node] node
|
327
|
+
# @param [LL::CompiledGrammar] compiled_grammar
|
328
|
+
# @return [LL::Operator]
|
329
|
+
#
|
330
|
+
def on_star(node, compiled_grammar)
|
331
|
+
steps = lookup_identifiers(node, compiled_grammar)
|
332
|
+
name = "_ll_star#{node.source_line.line}#{node.source_line.column}"
|
333
|
+
rule = Rule.new(name, node.source_line)
|
324
334
|
|
325
|
-
|
326
|
-
if retval.is_a?(String)
|
327
|
-
step = compiled_grammar.lookup_identifier(retval)
|
335
|
+
rule.add_branch(steps, node.source_line)
|
328
336
|
|
329
|
-
|
330
|
-
# Epsilon
|
331
|
-
else
|
332
|
-
step = retval
|
333
|
-
end
|
337
|
+
rule.increment_references
|
334
338
|
|
335
|
-
|
336
|
-
step.increment_references if step.respond_to?(:increment_references)
|
339
|
+
compiled_grammar.add_rule(rule)
|
337
340
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
+
return Operator.new(:star, rule, node.source_line)
|
342
|
+
end
|
343
|
+
|
344
|
+
##
|
345
|
+
# Processes the "+" operator.
|
346
|
+
#
|
347
|
+
# @param [LL::AST::Node] node
|
348
|
+
# @param [LL::CompiledGrammar] compiled_grammar
|
349
|
+
# @return [LL::Operator]
|
350
|
+
#
|
351
|
+
def on_plus(node, compiled_grammar)
|
352
|
+
steps = lookup_identifiers(node, compiled_grammar)
|
353
|
+
name = "_ll_plus#{node.source_line.line}#{node.source_line.column}"
|
354
|
+
rule = Rule.new(name, node.source_line)
|
355
|
+
|
356
|
+
rule.add_branch(steps, node.source_line)
|
341
357
|
|
342
|
-
|
358
|
+
rule.increment_references
|
359
|
+
|
360
|
+
compiled_grammar.add_rule(rule)
|
361
|
+
|
362
|
+
return Operator.new(:plus, rule, node.source_line)
|
343
363
|
end
|
344
364
|
|
345
365
|
private
|
@@ -355,5 +375,35 @@ module LL
|
|
355
375
|
node.source_line
|
356
376
|
)
|
357
377
|
end
|
378
|
+
|
379
|
+
##
|
380
|
+
# @see [#process]
|
381
|
+
# @return [Array]
|
382
|
+
#
|
383
|
+
def lookup_identifiers(node, compiled_grammar)
|
384
|
+
idents = []
|
385
|
+
|
386
|
+
node.children.each do |ident_node|
|
387
|
+
retval = process(ident_node, compiled_grammar)
|
388
|
+
|
389
|
+
# Literal rule/terminal names.
|
390
|
+
if retval.is_a?(String)
|
391
|
+
ident = compiled_grammar.lookup_identifier(retval)
|
392
|
+
|
393
|
+
undefined_identifier!(retval, ident_node, compiled_grammar) if !ident
|
394
|
+
# Epsilon
|
395
|
+
else
|
396
|
+
ident = retval
|
397
|
+
end
|
398
|
+
|
399
|
+
if ident
|
400
|
+
ident.increment_references if ident.respond_to?(:increment_references)
|
401
|
+
|
402
|
+
idents << ident
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
return idents
|
407
|
+
end
|
358
408
|
end # Compiler
|
359
409
|
end # LL
|
data/lib/ll/lexer.rb
CHANGED
@@ -64,49 +64,49 @@ self._ll_lexer_indicies = [
|
|
64
64
|
27, 1, 1, 1, 1, 1, 1, 1,
|
65
65
|
1, 1, 1, 1, 1, 1, 1, 1,
|
66
66
|
1, 1, 1, 1, 1, 1, 26, 1,
|
67
|
-
1, 28, 1, 29, 1, 1,
|
68
|
-
|
67
|
+
1, 28, 1, 29, 1, 1, 30, 31,
|
68
|
+
32, 33, 1, 1, 1, 1, 25, 25,
|
69
69
|
25, 25, 25, 25, 25, 25, 25, 25,
|
70
|
-
|
70
|
+
34, 35, 1, 36, 1, 1, 1, 25,
|
71
71
|
25, 25, 25, 25, 25, 25, 25, 25,
|
72
72
|
25, 25, 25, 25, 25, 25, 25, 25,
|
73
73
|
25, 25, 25, 25, 25, 25, 25, 25,
|
74
|
-
25, 1, 1, 1, 1,
|
74
|
+
25, 1, 1, 1, 1, 37, 1, 25,
|
75
75
|
25, 25, 25, 25, 25, 25, 25, 25,
|
76
76
|
25, 25, 25, 25, 25, 25, 25, 25,
|
77
77
|
25, 25, 25, 25, 25, 25, 25, 25,
|
78
|
-
25,
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
78
|
+
25, 38, 39, 1, 1, 1, 25, 40,
|
79
|
+
40, 40, 40, 40, 40, 40, 40, 40,
|
80
|
+
40, 40, 40, 40, 40, 40, 40, 40,
|
81
|
+
40, 40, 40, 40, 40, 40, 40, 40,
|
82
|
+
40, 40, 40, 40, 40, 40, 40, 40,
|
83
|
+
40, 40, 40, 40, 40, 40, 40, 40,
|
84
|
+
40, 40, 40, 40, 40, 40, 40, 25,
|
85
85
|
25, 25, 25, 25, 25, 25, 25, 25,
|
86
|
-
25,
|
86
|
+
25, 40, 40, 40, 40, 40, 40, 40,
|
87
87
|
25, 25, 25, 25, 25, 25, 25, 25,
|
88
88
|
25, 25, 25, 25, 25, 25, 25, 25,
|
89
89
|
25, 25, 25, 25, 25, 25, 25, 25,
|
90
|
-
25, 25,
|
90
|
+
25, 25, 40, 40, 40, 40, 25, 40,
|
91
91
|
25, 25, 25, 25, 25, 25, 25, 25,
|
92
92
|
25, 25, 25, 25, 25, 25, 25, 25,
|
93
93
|
25, 25, 25, 25, 25, 25, 25, 25,
|
94
|
-
25, 25,
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
94
|
+
25, 25, 40, 40, 40, 40, 40, 25,
|
95
|
+
41, 28, 43, 42, 42, 42, 42, 42,
|
96
|
+
42, 42, 42, 42, 42, 42, 42, 42,
|
97
|
+
42, 42, 42, 42, 42, 42, 42, 42,
|
98
|
+
42, 42, 42, 42, 42, 42, 42, 42,
|
99
|
+
42, 42, 42, 42, 42, 42, 42, 42,
|
100
|
+
42, 42, 42, 42, 42, 42, 42, 42,
|
101
|
+
42, 42, 42, 42, 42, 42, 42, 42,
|
102
|
+
42, 42, 42, 42, 42, 42, 42, 42,
|
103
|
+
42, 42, 42, 42, 42, 42, 42, 42,
|
104
|
+
42, 42, 42, 42, 42, 42, 42, 42,
|
105
|
+
42, 42, 42, 42, 42, 42, 42, 42,
|
106
|
+
42, 42, 42, 42, 42, 42, 42, 42,
|
107
|
+
42, 42, 42, 42, 42, 42, 42, 42,
|
108
|
+
42, 42, 42, 42, 42, 42, 42, 42,
|
109
|
+
42, 42, 42, 44, 42, 45, 42, 0
|
110
110
|
]
|
111
111
|
|
112
112
|
class << self
|
@@ -118,8 +118,8 @@ self._ll_lexer_trans_targs = [
|
|
118
118
|
6, 22, 8, 9, 10, 22, 12, 13,
|
119
119
|
22, 15, 16, 17, 18, 19, 20, 21,
|
120
120
|
22, 23, 22, 22, 24, 1, 22, 22,
|
121
|
-
22,
|
122
|
-
25, 25
|
121
|
+
22, 22, 22, 22, 22, 23, 22, 22,
|
122
|
+
22, 22, 25, 25, 25, 25
|
123
123
|
]
|
124
124
|
|
125
125
|
class << self
|
@@ -132,7 +132,7 @@ self._ll_lexer_trans_actions = [
|
|
132
132
|
3, 0, 0, 0, 0, 0, 0, 0,
|
133
133
|
4, 7, 8, 9, 0, 0, 10, 11,
|
134
134
|
12, 13, 14, 15, 16, 17, 18, 19,
|
135
|
-
20, 21
|
135
|
+
20, 21, 22, 23, 24, 25
|
136
136
|
]
|
137
137
|
|
138
138
|
class << self
|
@@ -164,8 +164,8 @@ end
|
|
164
164
|
self._ll_lexer_eof_trans = [
|
165
165
|
0, 0, 0, 0, 0, 0, 0, 0,
|
166
166
|
0, 0, 0, 0, 0, 0, 0, 0,
|
167
|
-
0, 0, 0, 0, 0, 0, 0,
|
168
|
-
|
167
|
+
0, 0, 0, 0, 0, 0, 0, 41,
|
168
|
+
42, 0
|
169
169
|
]
|
170
170
|
|
171
171
|
class << self
|
@@ -312,13 +312,13 @@ ts = p
|
|
312
312
|
cs = _ll_lexer_trans_targs[_trans]
|
313
313
|
if _ll_lexer_trans_actions[_trans] != 0
|
314
314
|
case _ll_lexer_trans_actions[_trans]
|
315
|
-
when
|
315
|
+
when 24 then
|
316
316
|
# line 188 "lib/ll/lexer.rl"
|
317
317
|
begin
|
318
318
|
te = p+1
|
319
319
|
begin brace_count += 1 end
|
320
320
|
end
|
321
|
-
when
|
321
|
+
when 25 then
|
322
322
|
# line 190 "lib/ll/lexer.rl"
|
323
323
|
begin
|
324
324
|
te = p+1
|
@@ -338,7 +338,7 @@ te = p+1
|
|
338
338
|
end
|
339
339
|
end
|
340
340
|
end
|
341
|
-
when
|
341
|
+
when 22 then
|
342
342
|
# line 206 "lib/ll/lexer.rl"
|
343
343
|
begin
|
344
344
|
te = p+1
|
@@ -367,33 +367,57 @@ te = p+1
|
|
367
367
|
te = p+1
|
368
368
|
begin emit(:T_HEADER, ts, te) end
|
369
369
|
end
|
370
|
-
when
|
370
|
+
when 16 then
|
371
371
|
# line 220 "lib/ll/lexer.rl"
|
372
372
|
begin
|
373
373
|
te = p+1
|
374
374
|
begin emit(:T_EQUALS, ts, te) end
|
375
375
|
end
|
376
|
-
when
|
376
|
+
when 14 then
|
377
377
|
# line 221 "lib/ll/lexer.rl"
|
378
378
|
begin
|
379
379
|
te = p+1
|
380
380
|
begin emit(:T_COLON, ts, te) end
|
381
381
|
end
|
382
|
-
when
|
382
|
+
when 15 then
|
383
383
|
# line 222 "lib/ll/lexer.rl"
|
384
384
|
begin
|
385
385
|
te = p+1
|
386
386
|
begin emit(:T_SEMICOLON, ts, te) end
|
387
387
|
end
|
388
|
-
when
|
388
|
+
when 19 then
|
389
389
|
# line 223 "lib/ll/lexer.rl"
|
390
390
|
begin
|
391
391
|
te = p+1
|
392
392
|
begin emit(:T_PIPE, ts, te) end
|
393
393
|
end
|
394
|
-
when
|
394
|
+
when 13 then
|
395
|
+
# line 225 "lib/ll/lexer.rl"
|
396
|
+
begin
|
397
|
+
te = p+1
|
398
|
+
begin emit(:T_PLUS, ts, te) end
|
399
|
+
end
|
400
|
+
when 12 then
|
395
401
|
# line 226 "lib/ll/lexer.rl"
|
396
402
|
begin
|
403
|
+
te = p+1
|
404
|
+
begin emit(:T_STAR, ts, te) end
|
405
|
+
end
|
406
|
+
when 10 then
|
407
|
+
# line 227 "lib/ll/lexer.rl"
|
408
|
+
begin
|
409
|
+
te = p+1
|
410
|
+
begin emit(:T_LPAREN, ts, te) end
|
411
|
+
end
|
412
|
+
when 11 then
|
413
|
+
# line 228 "lib/ll/lexer.rl"
|
414
|
+
begin
|
415
|
+
te = p+1
|
416
|
+
begin emit(:T_RPAREN, ts, te) end
|
417
|
+
end
|
418
|
+
when 18 then
|
419
|
+
# line 230 "lib/ll/lexer.rl"
|
420
|
+
begin
|
397
421
|
te = p+1
|
398
422
|
begin
|
399
423
|
mark = ts + 1
|
@@ -405,26 +429,26 @@ te = p+1
|
|
405
429
|
cs = 25;
|
406
430
|
end
|
407
431
|
end
|
408
|
-
when
|
432
|
+
when 21 then
|
409
433
|
# line 213 "lib/ll/lexer.rl"
|
410
434
|
begin
|
411
435
|
te = p
|
412
436
|
p = p - 1; end
|
413
|
-
when
|
437
|
+
when 20 then
|
414
438
|
# line 1 "NONE"
|
415
439
|
begin
|
416
440
|
case act
|
417
441
|
when 16 then
|
418
442
|
begin begin p = ((te))-1; end
|
419
443
|
emit(:T_EPSILON, ts, te) end
|
420
|
-
when
|
444
|
+
when 22 then
|
421
445
|
begin begin p = ((te))-1; end
|
422
446
|
|
423
447
|
emit(:T_IDENT, ts, te)
|
424
448
|
end
|
425
449
|
end
|
426
450
|
end
|
427
|
-
when
|
451
|
+
when 23 then
|
428
452
|
# line 148 "lib/ll/lexer.rl"
|
429
453
|
begin
|
430
454
|
|
@@ -458,7 +482,7 @@ te = p+1
|
|
458
482
|
begin
|
459
483
|
te = p+1
|
460
484
|
end
|
461
|
-
when
|
485
|
+
when 17 then
|
462
486
|
# line 1 "NONE"
|
463
487
|
begin
|
464
488
|
te = p+1
|
@@ -473,8 +497,8 @@ te = p+1
|
|
473
497
|
end
|
474
498
|
# line 168 "lib/ll/lexer.rl"
|
475
499
|
begin
|
476
|
-
act =
|
477
|
-
# line
|
500
|
+
act = 22; end
|
501
|
+
# line 501 "lib/ll/lexer.rb"
|
478
502
|
end
|
479
503
|
end
|
480
504
|
end
|
@@ -484,7 +508,7 @@ act = 18; end
|
|
484
508
|
# line 1 "NONE"
|
485
509
|
begin
|
486
510
|
ts = nil; end
|
487
|
-
# line
|
511
|
+
# line 511 "lib/ll/lexer.rb"
|
488
512
|
end
|
489
513
|
|
490
514
|
if cs == 0
|
@@ -576,7 +600,7 @@ end
|
|
576
600
|
end
|
577
601
|
|
578
602
|
|
579
|
-
# line
|
603
|
+
# line 242 "lib/ll/lexer.rl"
|
580
604
|
|
581
605
|
end # Lexer
|
582
606
|
end # Oga
|