depager 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +4 -0
- data/README.en +5 -10
- data/bin/depager +17 -20
- data/examples/c89/c89.tab.rb +5632 -702
- data/examples/pl0d/pl0ds.dr +41 -41
- data/examples/pl0d/pl0ds.tab.rb +1887 -874
- data/examples/sample_calc/calc.action.tab.rb +243 -69
- data/examples/sample_calc/{calc.astl.action.dr → calc.ast.action.dr} +7 -7
- data/examples/sample_calc/calc.ast.action.tab.rb +755 -0
- data/examples/sample_calc/{calc.astl.dr → calc.ast.dr} +7 -7
- data/examples/sample_calc/calc.ast.tab.rb +672 -0
- data/examples/sample_calc/calc.astdf.dr +5 -5
- data/examples/sample_calc/calc.astdf.tab.rb +405 -202
- data/examples/sample_calc/calc.atree.tab.rb +243 -69
- data/examples/sample_calc/calc.cst.tab.rb +275 -109
- data/examples/sample_calc/calc.lex.tab.rb +210 -28
- data/examples/sample_calc/calc.nvaction.tab.rb +251 -77
- data/examples/sample_calc/calc.tab.rb +210 -28
- data/examples/sample_calc/calc_prec.nvaction.tab.rb +224 -50
- data/examples/slex_test/divreg.slex.tab.rb +97 -21
- data/examples/slex_test/ljoin.slex.tab.rb +128 -35
- data/lib/depager.rb +77 -44
- data/lib/depager/{ast_base.dr → ast.dr} +56 -18
- data/lib/depager/{ast_base.rb → ast.rb} +432 -424
- data/lib/depager/astdf.rb +3 -6
- data/lib/depager/atree.rb +54 -62
- data/lib/depager/cst.dr +2 -2
- data/lib/depager/cst.rb +64 -77
- data/lib/depager/grammar.rb +225 -66
- data/lib/depager/lex.dr +1 -1
- data/lib/depager/lex.rb +45 -54
- data/lib/depager/lr.rb +181 -262
- data/lib/depager/lr_put_table.rb +116 -0
- data/lib/depager/nvaction.rb +1 -1
- data/lib/depager/parser.rb +23 -2
- data/lib/depager/slex.dr +3 -3
- data/lib/depager/slex.rb +148 -169
- data/lib/depager/srp.rb +1 -1
- data/lib/depager/template/ast.erbs +69 -0
- data/lib/depager/template/extension_lalr_master.erb +3 -3
- data/lib/depager/template/extension_lalr_slave.erb +7 -7
- data/lib/depager/template/simple.erb +4 -2
- data/lib/depager/template/single_lalr_parser.erb +30 -10
- data/lib/depager/utils.rb +10 -9
- data/lib/depager/version.rb +2 -8
- metadata +10 -11
- data/examples/sample_calc/calc.astl.action.tab.rb +0 -593
- data/examples/sample_calc/calc.astl.tab.rb +0 -501
- data/lib/depager/astl.rb +0 -14
- data/lib/depager/template/astdf.erbs +0 -57
- data/lib/depager/template/astl.erbs +0 -57
@@ -3,8 +3,8 @@ begin; require 'rubygems'; rescue Exception; end
|
|
3
3
|
require 'depager/parser.rb'
|
4
4
|
|
5
5
|
|
6
|
-
module
|
7
|
-
end
|
6
|
+
module Depager::DecoratorUtils; end
|
7
|
+
module D4StatefulLexerTest1; end
|
8
8
|
|
9
9
|
class StatefulLexerTest1 < Depager::LALR::Basis
|
10
10
|
|
@@ -12,15 +12,15 @@ class StatefulLexerTest1 < Depager::LALR::Basis
|
|
12
12
|
### Reduce Table
|
13
13
|
reduce_table = [
|
14
14
|
[ -1, 1 ], # ( 0) $start : expr
|
15
|
-
[ 0, 4 ], # ( 1) expr : expr / __expr_0_2__ fact
|
15
|
+
[ 0, 4 ], # ( 1) expr : expr '/' __expr_0_2__ fact
|
16
16
|
[ 0, 1 ], # ( 2) expr : fact
|
17
17
|
[ 2, 0 ], # ( 3) __expr_0_2__ :
|
18
18
|
[ 1, 1 ], # ( 4) fact : REGEXP
|
19
19
|
]
|
20
20
|
### Extension Params
|
21
21
|
nparams = {
|
22
|
-
'NVAction' => 3,
|
23
22
|
'StatefulLexer' => 2,
|
23
|
+
'NVAction' => 3,
|
24
24
|
}
|
25
25
|
### Term to Int
|
26
26
|
t2i = {
|
@@ -38,20 +38,20 @@ class StatefulLexerTest1 < Depager::LALR::Basis
|
|
38
38
|
]
|
39
39
|
### Action Table
|
40
40
|
action_table = [
|
41
|
-
[ nil, nil, nil,
|
41
|
+
[ nil, nil, nil, 3, ],
|
42
42
|
[ ACC, nil, 4, nil, ],
|
43
43
|
[ nil, nil, nil, nil, ],
|
44
44
|
[ nil, nil, nil, nil, ],
|
45
45
|
[ nil, nil, nil, nil, ],
|
46
|
-
[ nil, nil, nil,
|
46
|
+
[ nil, nil, nil, 3, ],
|
47
47
|
[ nil, nil, nil, nil, ],
|
48
48
|
]
|
49
49
|
### Default Reduce Table
|
50
50
|
defred_table = [
|
51
51
|
nil,
|
52
52
|
nil,
|
53
|
-
-4,
|
54
53
|
-2,
|
54
|
+
-4,
|
55
55
|
-3,
|
56
56
|
nil,
|
57
57
|
-1,
|
@@ -59,8 +59,8 @@ class StatefulLexerTest1 < Depager::LALR::Basis
|
|
59
59
|
defred_after_shift_table = [
|
60
60
|
nil,
|
61
61
|
nil,
|
62
|
-
-4,
|
63
62
|
-2,
|
63
|
+
-4,
|
64
64
|
-3,
|
65
65
|
nil,
|
66
66
|
-1,
|
@@ -79,7 +79,7 @@ class StatefulLexerTest1 < Depager::LALR::Basis
|
|
79
79
|
]
|
80
80
|
### Goto Table
|
81
81
|
goto_table = [
|
82
|
-
[ 1,
|
82
|
+
[ 1, 2, nil, ],
|
83
83
|
[ nil, nil, nil, ],
|
84
84
|
[ nil, nil, nil, ],
|
85
85
|
[ nil, nil, nil, ],
|
@@ -88,6 +88,83 @@ class StatefulLexerTest1 < Depager::LALR::Basis
|
|
88
88
|
[ nil, nil, nil, ],
|
89
89
|
]
|
90
90
|
|
91
|
+
|
92
|
+
alias orig_error error
|
93
|
+
def error
|
94
|
+
orig_error
|
95
|
+
warn "current state: #{StateInfo[@stack.last]}"
|
96
|
+
end
|
97
|
+
|
98
|
+
### States
|
99
|
+
StateInfo = [
|
100
|
+
<<'----------',
|
101
|
+
I000 =
|
102
|
+
( 0) $start : _ expr
|
103
|
+
|
104
|
+
REGEXP shift, and goto to state 3
|
105
|
+
|
106
|
+
|
107
|
+
----------
|
108
|
+
|
109
|
+
<<'----------',
|
110
|
+
I001 =
|
111
|
+
( 0) $start : expr _
|
112
|
+
( 1) expr : expr _ '/' __expr_0_2__ fact
|
113
|
+
|
114
|
+
'/' shift, and goto to state 4
|
115
|
+
|
116
|
+
|
117
|
+
$end accept
|
118
|
+
|
119
|
+
----------
|
120
|
+
|
121
|
+
<<'----------',
|
122
|
+
I002 =
|
123
|
+
( 2) expr : fact _
|
124
|
+
|
125
|
+
|
126
|
+
$default reduce using rule 2 (expr) [after shift]
|
127
|
+
|
128
|
+
----------
|
129
|
+
|
130
|
+
<<'----------',
|
131
|
+
I003 =
|
132
|
+
( 4) fact : REGEXP _
|
133
|
+
|
134
|
+
|
135
|
+
$default reduce using rule 4 (fact) [after shift]
|
136
|
+
|
137
|
+
----------
|
138
|
+
|
139
|
+
<<'----------',
|
140
|
+
I004 =
|
141
|
+
( 1) expr : expr '/' _ __expr_0_2__ fact
|
142
|
+
|
143
|
+
|
144
|
+
$default reduce using rule 3 (__expr_0_2__) [after shift]
|
145
|
+
|
146
|
+
----------
|
147
|
+
|
148
|
+
<<'----------',
|
149
|
+
I005 =
|
150
|
+
( 1) expr : expr '/' __expr_0_2__ _ fact
|
151
|
+
|
152
|
+
REGEXP shift, and goto to state 3
|
153
|
+
|
154
|
+
|
155
|
+
----------
|
156
|
+
|
157
|
+
<<'----------',
|
158
|
+
I006 =
|
159
|
+
( 1) expr : expr '/' __expr_0_2__ fact _
|
160
|
+
|
161
|
+
|
162
|
+
$default reduce using rule 1 (expr) [after shift]
|
163
|
+
|
164
|
+
----------
|
165
|
+
]
|
166
|
+
|
167
|
+
|
91
168
|
Tables = [ reduce_table, nparams, action_table,
|
92
169
|
defred_table, defred_after_shift_table, goto_table,
|
93
170
|
t2i, i2t, nt2i, i2nt ]
|
@@ -100,17 +177,17 @@ class StatefulLexerTest1 < Depager::LALR::Basis
|
|
100
177
|
|
101
178
|
def lex_START(&block)
|
102
179
|
case @line
|
103
|
-
|
180
|
+
|
104
181
|
when /\A\s+/
|
105
182
|
@oldline = @line; @line = $'
|
106
183
|
|
107
184
|
|
108
|
-
|
185
|
+
|
109
186
|
when /\A\/(([^\/\\]+|\\.)*)\//
|
110
187
|
@oldline = @line; @line = $'
|
111
188
|
yield _Token(:REGEXP, $&)
|
112
189
|
|
113
|
-
|
190
|
+
|
114
191
|
when /\A./
|
115
192
|
@oldline = @line; @line = $'
|
116
193
|
yield _Token($&, $&)
|
@@ -123,7 +200,7 @@ class StatefulLexerTest1 < Depager::LALR::Basis
|
|
123
200
|
|
124
201
|
def lex_OPMODE(&block)
|
125
202
|
case @line
|
126
|
-
|
203
|
+
|
127
204
|
when /\A\//
|
128
205
|
@oldline = @line; @line = $'
|
129
206
|
yield _Token($&, $&)
|
@@ -152,7 +229,7 @@ end
|
|
152
229
|
|
153
230
|
class D4StatefulLexerTest1::StatefulLexer < Depager::LALR::Action #:nodoc:all
|
154
231
|
include Depager::DecoratorUtils
|
155
|
-
|
232
|
+
[]
|
156
233
|
on_reduce = [
|
157
234
|
nil,
|
158
235
|
nil,
|
@@ -185,7 +262,7 @@ end
|
|
185
262
|
|
186
263
|
class D4StatefulLexerTest1::NVAction < Depager::LALR::Action #:nodoc:all
|
187
264
|
include Depager::DecoratorUtils
|
188
|
-
|
265
|
+
[]
|
189
266
|
on_reduce = [
|
190
267
|
nil,
|
191
268
|
nil,
|
@@ -202,14 +279,13 @@ class D4StatefulLexerTest1::NVAction < Depager::LALR::Action #:nodoc:all
|
|
202
279
|
end
|
203
280
|
|
204
281
|
|
205
|
-
module_eval <<-'.,.,
|
206
|
-
|
207
|
-
_REGEXP = *val
|
282
|
+
module_eval <<-'.,.,120998293627530.,.,', 'slex_test/divreg.slex.dr', 22
|
283
|
+
def _act_3 val
|
284
|
+
_REGEXP, = *val
|
208
285
|
warn "REGEXP: #{_REGEXP.value}"
|
209
286
|
|
210
|
-
|
211
|
-
|
212
|
-
.,.,118754109260321.,.,
|
287
|
+
end
|
288
|
+
.,.,120998293627530.,.,
|
213
289
|
|
214
290
|
end
|
215
291
|
|
@@ -3,8 +3,8 @@ begin; require 'rubygems'; rescue Exception; end
|
|
3
3
|
require 'depager/parser.rb'
|
4
4
|
|
5
5
|
|
6
|
-
module
|
7
|
-
end
|
6
|
+
module Depager::DecoratorUtils; end
|
7
|
+
module D4StatefulLexerTest2; end
|
8
8
|
|
9
9
|
class StatefulLexerTest2 < Depager::LALR::Basis
|
10
10
|
|
@@ -14,15 +14,15 @@ class StatefulLexerTest2 < Depager::LALR::Basis
|
|
14
14
|
[ -1, 1 ], # ( 0) $start : stmts
|
15
15
|
[ 0, 0 ], # ( 1) stmts :
|
16
16
|
[ 0, 3 ], # ( 2) stmts : stmts expr EOL
|
17
|
-
[ 1, 4 ], # ( 3) expr : expr + __expr_0_2__ fact
|
17
|
+
[ 1, 4 ], # ( 3) expr : expr '+' __expr_0_2__ fact
|
18
18
|
[ 1, 1 ], # ( 4) expr : fact
|
19
19
|
[ 3, 0 ], # ( 5) __expr_0_2__ :
|
20
20
|
[ 2, 1 ], # ( 6) fact : ID
|
21
21
|
]
|
22
22
|
### Extension Params
|
23
23
|
nparams = {
|
24
|
-
'NVAction' => 3,
|
25
24
|
'StatefulLexer' => 2,
|
25
|
+
'NVAction' => 3,
|
26
26
|
}
|
27
27
|
### Term to Int
|
28
28
|
t2i = {
|
@@ -102,6 +102,103 @@ class StatefulLexerTest2 < Depager::LALR::Basis
|
|
102
102
|
[ nil, nil, nil, nil, ],
|
103
103
|
]
|
104
104
|
|
105
|
+
|
106
|
+
alias orig_error error
|
107
|
+
def error
|
108
|
+
orig_error
|
109
|
+
warn "current state: #{StateInfo[@stack.last]}"
|
110
|
+
end
|
111
|
+
|
112
|
+
### States
|
113
|
+
StateInfo = [
|
114
|
+
<<'----------',
|
115
|
+
I000 =
|
116
|
+
( 0) $start : _ stmts
|
117
|
+
|
118
|
+
|
119
|
+
$default reduce using rule 1 (stmts) [after shift]
|
120
|
+
|
121
|
+
----------
|
122
|
+
|
123
|
+
<<'----------',
|
124
|
+
I001 =
|
125
|
+
( 0) $start : stmts _
|
126
|
+
( 2) stmts : stmts _ expr EOL
|
127
|
+
|
128
|
+
ID shift, and goto to state 4
|
129
|
+
|
130
|
+
|
131
|
+
$end accept
|
132
|
+
|
133
|
+
----------
|
134
|
+
|
135
|
+
<<'----------',
|
136
|
+
I002 =
|
137
|
+
( 2) stmts : stmts expr _ EOL
|
138
|
+
( 3) expr : expr _ '+' __expr_0_2__ fact
|
139
|
+
|
140
|
+
EOL shift, and goto to state 5
|
141
|
+
'+' shift, and goto to state 6
|
142
|
+
|
143
|
+
|
144
|
+
----------
|
145
|
+
|
146
|
+
<<'----------',
|
147
|
+
I003 =
|
148
|
+
( 4) expr : fact _
|
149
|
+
|
150
|
+
|
151
|
+
$default reduce using rule 4 (expr) [after shift]
|
152
|
+
|
153
|
+
----------
|
154
|
+
|
155
|
+
<<'----------',
|
156
|
+
I004 =
|
157
|
+
( 6) fact : ID _
|
158
|
+
|
159
|
+
|
160
|
+
$default reduce using rule 6 (fact) [after shift]
|
161
|
+
|
162
|
+
----------
|
163
|
+
|
164
|
+
<<'----------',
|
165
|
+
I005 =
|
166
|
+
( 2) stmts : stmts expr EOL _
|
167
|
+
|
168
|
+
|
169
|
+
$default reduce using rule 2 (stmts) [after shift]
|
170
|
+
|
171
|
+
----------
|
172
|
+
|
173
|
+
<<'----------',
|
174
|
+
I006 =
|
175
|
+
( 3) expr : expr '+' _ __expr_0_2__ fact
|
176
|
+
|
177
|
+
|
178
|
+
$default reduce using rule 5 (__expr_0_2__) [after shift]
|
179
|
+
|
180
|
+
----------
|
181
|
+
|
182
|
+
<<'----------',
|
183
|
+
I007 =
|
184
|
+
( 3) expr : expr '+' __expr_0_2__ _ fact
|
185
|
+
|
186
|
+
ID shift, and goto to state 4
|
187
|
+
|
188
|
+
|
189
|
+
----------
|
190
|
+
|
191
|
+
<<'----------',
|
192
|
+
I008 =
|
193
|
+
( 3) expr : expr '+' __expr_0_2__ fact _
|
194
|
+
|
195
|
+
|
196
|
+
$default reduce using rule 3 (expr) [after shift]
|
197
|
+
|
198
|
+
----------
|
199
|
+
]
|
200
|
+
|
201
|
+
|
105
202
|
Tables = [ reduce_table, nparams, action_table,
|
106
203
|
defred_table, defred_after_shift_table, goto_table,
|
107
204
|
t2i, i2t, nt2i, i2nt ]
|
@@ -114,22 +211,22 @@ class StatefulLexerTest2 < Depager::LALR::Basis
|
|
114
211
|
|
115
212
|
def lex_START(&block)
|
116
213
|
case @line
|
117
|
-
|
214
|
+
|
118
215
|
when /\A[ \t]+/
|
119
216
|
@oldline = @line; @line = $'
|
120
217
|
|
121
218
|
|
122
|
-
|
219
|
+
|
123
220
|
when /\A\n/
|
124
221
|
@oldline = @line; @line = $'
|
125
222
|
yield _Token(:EOL, $&)
|
126
223
|
|
127
|
-
|
224
|
+
|
128
225
|
when /\A\w+/
|
129
226
|
@oldline = @line; @line = $'
|
130
227
|
yield _Token(:ID, $&)
|
131
228
|
|
132
|
-
|
229
|
+
|
133
230
|
when /\A./
|
134
231
|
@oldline = @line; @line = $'
|
135
232
|
yield _Token($&, $&)
|
@@ -142,7 +239,7 @@ class StatefulLexerTest2 < Depager::LALR::Basis
|
|
142
239
|
|
143
240
|
def lex_LCONT(&block)
|
144
241
|
case @line
|
145
|
-
|
242
|
+
|
146
243
|
when /\A\r?\n/
|
147
244
|
@oldline = @line; @line = $'
|
148
245
|
|
@@ -171,7 +268,7 @@ end
|
|
171
268
|
|
172
269
|
class D4StatefulLexerTest2::StatefulLexer < Depager::LALR::Action #:nodoc:all
|
173
270
|
include Depager::DecoratorUtils
|
174
|
-
|
271
|
+
[]
|
175
272
|
on_reduce = [
|
176
273
|
nil,
|
177
274
|
nil,
|
@@ -206,7 +303,7 @@ end
|
|
206
303
|
|
207
304
|
class D4StatefulLexerTest2::NVAction < Depager::LALR::Action #:nodoc:all
|
208
305
|
include Depager::DecoratorUtils
|
209
|
-
|
306
|
+
[]
|
210
307
|
on_reduce = [
|
211
308
|
nil,
|
212
309
|
nil,
|
@@ -225,41 +322,37 @@ class D4StatefulLexerTest2::NVAction < Depager::LALR::Action #:nodoc:all
|
|
225
322
|
end
|
226
323
|
|
227
324
|
|
228
|
-
module_eval <<-'.,.,
|
229
|
-
|
230
|
-
_stmts, _expr, _EOL = *val
|
325
|
+
module_eval <<-'.,.,120998293621426.,.,', 'slex_test/ljoin.slex.dr', 19
|
326
|
+
def _act_1 val
|
327
|
+
_stmts, _expr, _EOL, = *val
|
231
328
|
warn "#{_expr} <EOL>:#{@lexstate}"
|
232
329
|
|
233
|
-
|
234
|
-
|
235
|
-
.,.,118754109357478.,.,
|
330
|
+
end
|
331
|
+
.,.,120998293621426.,.,
|
236
332
|
|
237
|
-
module_eval <<-'.,.,
|
238
|
-
|
239
|
-
_expr, _, ___expr_0_2__, _fact = *val
|
333
|
+
module_eval <<-'.,.,120998293623094.,.,', 'slex_test/ljoin.slex.dr', 23
|
334
|
+
def _act_2 val
|
335
|
+
_expr, _, ___expr_0_2__, _fact, = *val
|
240
336
|
"#{_expr} + #{_fact}"
|
241
337
|
|
242
|
-
|
243
|
-
|
244
|
-
.,.,118754109356391.,.,
|
338
|
+
end
|
339
|
+
.,.,120998293623094.,.,
|
245
340
|
|
246
|
-
module_eval <<-'.,.,
|
247
|
-
|
248
|
-
_fact = *val
|
341
|
+
module_eval <<-'.,.,120998293640556.,.,', 'slex_test/ljoin.slex.dr', 25
|
342
|
+
def _act_3 val
|
343
|
+
_fact, = *val
|
249
344
|
_fact
|
250
345
|
|
251
|
-
|
252
|
-
|
253
|
-
.,.,118754109362724.,.,
|
346
|
+
end
|
347
|
+
.,.,120998293640556.,.,
|
254
348
|
|
255
|
-
module_eval <<-'.,.,
|
256
|
-
|
257
|
-
_ID = *val
|
349
|
+
module_eval <<-'.,.,120998293664604.,.,', 'slex_test/ljoin.slex.dr', 29
|
350
|
+
def _act_5 val
|
351
|
+
_ID, = *val
|
258
352
|
_ID.value
|
259
353
|
|
260
|
-
|
261
|
-
|
262
|
-
.,.,118754109319023.,.,
|
354
|
+
end
|
355
|
+
.,.,120998293664604.,.,
|
263
356
|
|
264
357
|
end
|
265
358
|
|