depager 0.2.3 → 0.3.0.b20160729
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.en +4 -19
- data/README.ja +42 -79
- data/bin/depager +42 -45
- data/examples/action_pl0d/pl0d.action.dr +421 -0
- data/examples/action_pl0d/test.pl0ds +49 -0
- data/examples/c89/c89.dr +493 -496
- data/examples/c89/test.c89 +10 -10
- data/examples/extension/astdf.rb +10 -0
- data/examples/extension/atree.dr +55 -0
- data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
- data/examples/extension/calc.simple_action.dr +33 -0
- data/examples/extension/paction.dr +16 -15
- data/examples/extension/pactiontest.dr +14 -14
- data/examples/extension/simple_action.rb +44 -0
- data/examples/pl0d/pl0ds.dr +337 -334
- data/examples/pl0d/test.pl0ds +33 -33
- data/examples/rie_calc/calc.rie.dr +57 -0
- data/examples/rie_calc/test.calc +4 -0
- data/examples/rie_dcuse/dcuse.rie.dr +71 -0
- data/examples/rie_dcuse/test.dcuse +1 -0
- data/examples/rie_pl0/orig_ex/exerrdg.pl0 +44 -0
- data/examples/rie_pl0/orig_ex/exerrm.pl0 +19 -0
- data/examples/rie_pl0/orig_ex/exerrmre.pl0 +20 -0
- data/examples/rie_pl0/orig_ex/exerrtok.pl0 +18 -0
- data/examples/rie_pl0/orig_ex/exmdg.pl0 +40 -0
- data/examples/rie_pl0/orig_ex/exmdgwwl.pl0 +43 -0
- data/examples/rie_pl0/orig_ex/exmrw.pl0 +22 -0
- data/examples/rie_pl0/orig_ex/exmwwl.pl0 +18 -0
- data/examples/rie_pl0/orig_ex/exnorw.pl0 +17 -0
- data/examples/rie_pl0/pl0.rie.dr +450 -0
- data/examples/rie_pl0/test.pl0 +10 -0
- data/examples/sample_calc/calc.action.dr +33 -33
- data/examples/sample_calc/calc.ast.action.dr +65 -66
- data/examples/sample_calc/calc.ast.dr +55 -55
- data/examples/sample_calc/calc.cst.dr +45 -45
- data/examples/sample_calc/calc.dr +43 -43
- data/examples/sample_calc/calc.lex.dr +29 -29
- data/examples/sample_calc/{calc_prec.nvaction.dr → calc_prec.action.dr} +31 -31
- data/examples/slex_test/divreg.slex.dr +29 -29
- data/examples/slex_test/ljoin.slex.dr +36 -36
- data/examples/slex_test/test.divreg +1 -1
- data/examples/slex_test/test.ljoin +3 -3
- data/lib/depager.rb +582 -670
- data/lib/depager/grammar.rb +256 -291
- data/lib/depager/lr.rb +574 -579
- data/lib/depager/parser.rb +282 -277
- data/lib/depager/ruby/plugins/_rie_debug.rb +35 -0
- data/lib/depager/ruby/plugins/action.rb +53 -43
- data/lib/depager/ruby/plugins/ast.dr +364 -269
- data/lib/depager/ruby/plugins/ast.rb +1367 -1308
- data/lib/depager/ruby/plugins/cst.dr +172 -180
- data/lib/depager/ruby/plugins/cst.rb +587 -626
- data/lib/depager/ruby/plugins/lex.dr +85 -89
- data/lib/depager/ruby/plugins/lex.rb +310 -336
- data/lib/depager/ruby/plugins/rie.dr +723 -0
- data/lib/depager/ruby/plugins/rie.rb +1653 -0
- data/lib/depager/ruby/plugins/slex.dr +202 -200
- data/lib/depager/ruby/plugins/slex.rb +780 -817
- data/lib/depager/ruby/plugins/srp.rb +56 -51
- data/lib/depager/ruby/templates/extension_lalr_master.erb +46 -51
- data/lib/depager/ruby/templates/extension_lalr_slave.erb +99 -107
- data/lib/depager/ruby/templates/single_lalr_parser.erb +115 -117
- data/lib/depager/utils.rb +148 -318
- data/lib/depager/version.rb +4 -3
- metadata +52 -60
- data/ChangeLog +0 -16
- data/data/depager/pre-setup.rb +0 -3
- data/examples/c89/c89.tab.rb +0 -7127
- data/examples/pl0d/pl0ds.tab.rb +0 -2698
- data/examples/sample_calc/calc.action.tab.rb +0 -457
- data/examples/sample_calc/calc.ast.action.tab.rb +0 -749
- data/examples/sample_calc/calc.ast.tab.rb +0 -665
- data/examples/sample_calc/calc.astdf.dr +0 -54
- data/examples/sample_calc/calc.astdf.tab.rb +0 -672
- data/examples/sample_calc/calc.atree.tab.rb +0 -451
- data/examples/sample_calc/calc.cst.tab.rb +0 -644
- data/examples/sample_calc/calc.lex.tab.rb +0 -374
- data/examples/sample_calc/calc.nvaction.dr +0 -33
- data/examples/sample_calc/calc.nvaction.tab.rb +0 -465
- data/examples/sample_calc/calc.tab.rb +0 -365
- data/examples/sample_calc/calc_prec.nvaction.tab.rb +0 -431
- data/examples/slex_test/divreg.slex.tab.rb +0 -303
- data/examples/slex_test/ljoin.slex.tab.rb +0 -370
- data/lib/depager/ruby/plugins/_ast_tmpl.rb +0 -73
- data/lib/depager/ruby/plugins/astdf.rb +0 -6
- data/lib/depager/ruby/plugins/atree.dr +0 -55
- data/lib/depager/ruby/plugins/atree.rb +0 -347
- data/lib/depager/ruby/plugins/nvaction.rb +0 -19
- data/lib/depager/ruby/templates/simple.erb +0 -23
- data/setup.rb +0 -1585
@@ -1,51 +1,56 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
end
|
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
|
-
warn
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
warn "
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
class Depager::LALR::ShiftReducePrinter < Depager::LALR::AdvancedParser
|
3
|
+
def initialize inside
|
4
|
+
super
|
5
|
+
end
|
6
|
+
|
7
|
+
def dumpstack stack
|
8
|
+
result = ''
|
9
|
+
stack.each_with_index do |v, x|
|
10
|
+
result += if x % 2 == 0
|
11
|
+
"(#{v}) "
|
12
|
+
else
|
13
|
+
if v[1] == :NT
|
14
|
+
"#{int_to_nonterm[v[0]]}:#{v[1..-1].inspect} "
|
15
|
+
elsif int_to_term[v[0]].class == String
|
16
|
+
"'#{int_to_term[v[0]]}':#{v[1..-1].inspect}"
|
17
|
+
else
|
18
|
+
"#{int_to_term[v[0]]}:#{v[1..-1].inspect} "
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
result
|
23
|
+
end
|
24
|
+
|
25
|
+
def after_shift
|
26
|
+
st0 = stack[stack.size - 3]
|
27
|
+
st = stack.last
|
28
|
+
sh = int_to_term[stack[stack.size - 2][0]]
|
29
|
+
la = int_to_term[lookahead[0]]
|
30
|
+
warn "LA:<#{la}> shift:<#{sh}> state:#{st0}->#{st}"
|
31
|
+
warn "LINE:<#{basis.line}>"
|
32
|
+
warn dumpstack(stack) + "\n"
|
33
|
+
end
|
34
|
+
|
35
|
+
def after_reduce
|
36
|
+
st = stack.last
|
37
|
+
re = int_to_nonterm[stack[stack.size - 2][0]]
|
38
|
+
la = int_to_term[lookahead[0]]
|
39
|
+
warn "LA:<#{la}> reduce:<#{re}> state: ->#{st}"
|
40
|
+
warn "LINE:<#{basis.line}>"
|
41
|
+
warn dumpstack(stack) + "\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
def after_accept
|
45
|
+
warn "acc."
|
46
|
+
end
|
47
|
+
|
48
|
+
def after_error
|
49
|
+
st = stack.last
|
50
|
+
re = int_to_nonterm[stack[stack.size - 2][0]]
|
51
|
+
la = int_to_term[lookahead[0]]
|
52
|
+
warn "LA:<#{la}> last_state:#{st}"
|
53
|
+
warn "LINE:<#{basis.line}>"
|
54
|
+
warn dumpstack(stack) + "\n"
|
55
|
+
end
|
56
|
+
end
|
@@ -1,51 +1,46 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
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
|
-
<%= optinner %>
|
48
|
-
end
|
49
|
-
|
50
|
-
### Outer Code
|
51
|
-
<%= optouter %>
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
###
|
4
|
+
### <%= d_parser.target_namespace %> - Depager Extension (master)
|
5
|
+
###
|
6
|
+
require 'depager/parser.rb'
|
7
|
+
|
8
|
+
<%- @requirements.each do |i| -%>
|
9
|
+
require <%= i %>
|
10
|
+
<%- end -%>
|
11
|
+
|
12
|
+
<%- r = ''; d_parser.target_namespace.split('::')[0..-2].each do |i| -%>
|
13
|
+
module <%= "#{r}#{i}" %> ; end
|
14
|
+
<%- r << "#{i}::"-%>
|
15
|
+
<%- end -%>
|
16
|
+
|
17
|
+
class <%= d_parser.target_namespace %> < Depager::Extension
|
18
|
+
<%- @mixins.uniq.each do |i| -%>
|
19
|
+
include <%= i %>
|
20
|
+
<%- end -%>
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@master = self
|
24
|
+
@slaves = []
|
25
|
+
end
|
26
|
+
|
27
|
+
def extension_registered g_parser
|
28
|
+
super g_parser
|
29
|
+
|
30
|
+
<%- x = 0; h = {}; -%>
|
31
|
+
<%- @slaves.each do |i, m| -%>
|
32
|
+
<%- unless h[m] -%>
|
33
|
+
@slaves[<%= x %>] = <%= m %>.new(g_parser, self)
|
34
|
+
<%- h[m] = x -%>
|
35
|
+
<%- else -%>
|
36
|
+
# use @slaves[<%= h[m] %>](<%= m %>)
|
37
|
+
<%- end -%>
|
38
|
+
g_parser.hooks[:<%= i %>].push [@slaves[<%= h[m] %>], :do_parse]
|
39
|
+
<%- x += 1; -%>
|
40
|
+
<%- end -%>
|
41
|
+
end
|
42
|
+
|
43
|
+
<%= @inner_code %>
|
44
|
+
end
|
45
|
+
|
46
|
+
<%= @outer_code %>
|
@@ -1,107 +1,99 @@
|
|
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
|
-
end
|
101
|
-
|
102
|
-
### Inner Code
|
103
|
-
<%= optinner %>
|
104
|
-
end
|
105
|
-
|
106
|
-
### Outer Code
|
107
|
-
<%= optouter %>
|
1
|
+
<%- g = g_parser.table.grammar -%>
|
2
|
+
###
|
3
|
+
### <%= target_namespace %> - Part of Depager Extension (slave)
|
4
|
+
###
|
5
|
+
|
6
|
+
module <%= target_namespace %> #:nodoc:all
|
7
|
+
class <%= target_name %> < Depager::LALR::Basis #:nodoc:all
|
8
|
+
include Depager::Utils::ExtensionSlaveMethods
|
9
|
+
<% @slave_mixins.uniq.each do |i| %>
|
10
|
+
include <%=i%><%end%>
|
11
|
+
|
12
|
+
### Reduce Table
|
13
|
+
reduce_table = [
|
14
|
+
<%- g_parser.table.grammar.rulelist.each do |i| -%>
|
15
|
+
[ <%= i.lhs - 1%>, <%= i.rhs.size %> ],
|
16
|
+
<%- end -%>
|
17
|
+
]
|
18
|
+
### Term to Int
|
19
|
+
<%- values = (g.nonterms.size ... g.syms.size).map{|i| [ g.syms[i].inspect, i - g.nonterms.size] } -%>
|
20
|
+
term_to_int = {
|
21
|
+
<%- values.each do |k, v| -%>
|
22
|
+
<%= k %> => <%= v %>,
|
23
|
+
<%- end -%>
|
24
|
+
}
|
25
|
+
### Int to Term
|
26
|
+
int_to_term = [
|
27
|
+
<%- values.each do |k, v| -%>
|
28
|
+
<%= k %>,
|
29
|
+
<%- end -%>
|
30
|
+
]
|
31
|
+
### Action Table
|
32
|
+
action_table = [
|
33
|
+
<%- g_parser.table.action_table.each do |i| -%>
|
34
|
+
[ <% i.each do |j| %><%= j ? "#{j}" : 'nil' %>, <% end %>],
|
35
|
+
<%- end -%>
|
36
|
+
]
|
37
|
+
### Default Reduce Table
|
38
|
+
defred_table = [
|
39
|
+
<%- g_parser.table.defred_table.each do |i| -%>
|
40
|
+
<%= i ? "#{i}" : 'nil' %>,
|
41
|
+
<%- end -%>
|
42
|
+
]
|
43
|
+
defred_after_shift_table = [
|
44
|
+
<%- g_parser.table.defred_after_shift_table.each do |i| -%>
|
45
|
+
<%= i ? "#{i}" : 'nil' %>,
|
46
|
+
<%- end -%>
|
47
|
+
]
|
48
|
+
### Nonterm to Int
|
49
|
+
<%- values = (1 ... g.nonterms.size).map{|i| [ ":#{g.syms[i]}", i-1] } -%>
|
50
|
+
nonterm_to_int = {
|
51
|
+
<%- values.each do |k, v| -%>
|
52
|
+
<%= k %> => <%= v %>,
|
53
|
+
<%- end -%>
|
54
|
+
}
|
55
|
+
### Int to Nonterm
|
56
|
+
int_to_nonterm = [
|
57
|
+
<%- values.each do |k, v| -%>
|
58
|
+
<%= k %>,
|
59
|
+
<%- end -%>
|
60
|
+
]
|
61
|
+
### Goto Table
|
62
|
+
goto_table = [
|
63
|
+
<%- g_parser.table.goto_table.each do |i| -%>
|
64
|
+
[ <% i.each do |j| %><%= j ? "#{j}" : 'nil' %>, <% end %>],
|
65
|
+
<%- end -%>
|
66
|
+
]
|
67
|
+
|
68
|
+
Tables = [ reduce_table, action_table,
|
69
|
+
defred_table, defred_after_shift_table, goto_table,
|
70
|
+
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
71
|
+
|
72
|
+
def initialize g_parser, master
|
73
|
+
super()
|
74
|
+
@g_parser = g_parser
|
75
|
+
@d_parser = g_parser.d_parser
|
76
|
+
@master = master
|
77
|
+
@decorated = <%= @decorators.inject('self'){|r, i| "#{i.sub(/^@/, '')}.new(#{r})" } %>
|
78
|
+
end
|
79
|
+
|
80
|
+
<% if @do_parse_re %>
|
81
|
+
def do_parse?
|
82
|
+
if @line.match(/^\s*<%= @do_parse_re %>/)
|
83
|
+
<% if @do_parse_skip %> @line = $' <% end %>
|
84
|
+
true
|
85
|
+
else
|
86
|
+
false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
<% end %>
|
90
|
+
|
91
|
+
def banner
|
92
|
+
"<%= @banner %> / <%= d_parser.target_namespace %>"
|
93
|
+
end
|
94
|
+
|
95
|
+
<%= g_parser.inner_code %>
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
<%= g_parser.outer_code %>
|
@@ -1,117 +1,115 @@
|
|
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
|
-
<%= optmain %>
|
117
|
-
end
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
<%- g = g_parser.table.grammar -%>
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
rescue LoadError
|
6
|
+
end
|
7
|
+
|
8
|
+
<%- if Depager.configuration[:embed_runtime] -%>
|
9
|
+
<%= File.read File.expand_path("#{Depager::TEMPLATES_DIR}/../parser.rb") %>
|
10
|
+
<%- else -%>
|
11
|
+
require 'depager/parser.rb'
|
12
|
+
<%- end -%>
|
13
|
+
|
14
|
+
<%- @requirements.uniq.each do |i| -%>
|
15
|
+
require <%=i%>
|
16
|
+
<%- end -%>
|
17
|
+
|
18
|
+
<%- r = ''; target_namespace.split('::')[0..-2].each do |i| -%>
|
19
|
+
module <%= "#{r}#{i}" %> ; end
|
20
|
+
<%- r << "#{i}::"-%>
|
21
|
+
<%- end-%>
|
22
|
+
|
23
|
+
module <%= target_namespace %>
|
24
|
+
def self.create_decorated_parser(*args)
|
25
|
+
basis = <%= target_name %>.new(*args)
|
26
|
+
<%= @decorators.inject("basis"){|r, i| "#{i.tr('@', '') }.new(#{r})" } %>
|
27
|
+
end
|
28
|
+
|
29
|
+
class <%= target_name %> < Depager::LALR::Basis
|
30
|
+
<%- @mixins.each do |i| -%>
|
31
|
+
include <%= i %>
|
32
|
+
<%- end -%>
|
33
|
+
|
34
|
+
### Reduce Table
|
35
|
+
reduce_table = [
|
36
|
+
<%- g_parser.table.grammar.rulelist.each do |i| -%>
|
37
|
+
[ <%= '%04s' % (i.lhs - 1)%>, <%= "%04s" % i.rhs.size %> ], # <%= i %>
|
38
|
+
<%- end -%>
|
39
|
+
]
|
40
|
+
### Term to Int
|
41
|
+
<%- values = (g.nonterms.size ... g.syms.size).map{|i| [ g.syms[i].inspect, i - g.nonterms.size] } -%>
|
42
|
+
term_to_int = {
|
43
|
+
<%- values.each do |k, v| -%>
|
44
|
+
<%= k %> => <%= v %>,
|
45
|
+
<%- end -%>
|
46
|
+
}
|
47
|
+
### Int to Term
|
48
|
+
int_to_term = [
|
49
|
+
<%- values.each do |k, v| -%>
|
50
|
+
<%= k %>,
|
51
|
+
<%- end -%>
|
52
|
+
]
|
53
|
+
### Action Table
|
54
|
+
action_table = [
|
55
|
+
<%- g_parser.table.action_table.each do |i| -%>
|
56
|
+
[ <% i.each do |j| %><%= j ? "#{j}" : 'nil' %>, <% end %>],
|
57
|
+
<%- end -%>
|
58
|
+
]
|
59
|
+
### Default Reduce Table
|
60
|
+
defred_table = [
|
61
|
+
<%- g_parser.table.defred_table.each do |i| -%>
|
62
|
+
<%= i ? "#{i}" : 'nil' %>,
|
63
|
+
<%- end -%>
|
64
|
+
]
|
65
|
+
defred_after_shift_table = [
|
66
|
+
<%- g_parser.table.defred_after_shift_table.each do |i| -%>
|
67
|
+
<%= i ? "#{i}" : 'nil' %>,
|
68
|
+
<%- end -%>
|
69
|
+
]
|
70
|
+
### Nonterm to Int
|
71
|
+
<%- values = (1 ... g.nonterms.size).map{|i| [ ":#{g.syms[i]}", i-1] } -%>
|
72
|
+
nonterm_to_int = {
|
73
|
+
<%- values.each do |k, v| -%>
|
74
|
+
<%= k %> => <%= v %>,
|
75
|
+
<%- end -%>
|
76
|
+
}
|
77
|
+
### Int to Nonterm
|
78
|
+
int_to_nonterm = [
|
79
|
+
<%- values.each do |k, v| -%>
|
80
|
+
<%= k %>,
|
81
|
+
<%- end -%>
|
82
|
+
]
|
83
|
+
### Goto Table
|
84
|
+
goto_table = [
|
85
|
+
<%- g_parser.table.goto_table.each do |i| -%>
|
86
|
+
[ <% i.each do |j| %><%= j ? "#{j}" : 'nil' %>, <% end %>],
|
87
|
+
<%- end -%>
|
88
|
+
]
|
89
|
+
|
90
|
+
<%- if Depager.debug_mode? -%>
|
91
|
+
alias orig_error error
|
92
|
+
def error
|
93
|
+
orig_error
|
94
|
+
warn "current state: #{StateInfo[@stack.last]}"
|
95
|
+
end
|
96
|
+
|
97
|
+
### States
|
98
|
+
StateInfo = [
|
99
|
+
<%- g_parser.table.state_info.each do |s| -%>
|
100
|
+
<<'----------',
|
101
|
+
<%= s.strip %>
|
102
|
+
----------
|
103
|
+
<%- end -%>
|
104
|
+
]
|
105
|
+
<%- end -%>
|
106
|
+
|
107
|
+
Tables = [ reduce_table, action_table,
|
108
|
+
defred_table, defred_after_shift_table, goto_table,
|
109
|
+
term_to_int, int_to_term, nonterm_to_int, int_to_nonterm ]
|
110
|
+
|
111
|
+
<%= g_parser.inner_code + @inner_code %>
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
<%= g_parser.outer_code + @outer_code %>
|