depager 0.2.3 → 0.3.0.b20250423
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.
- checksums.yaml +7 -0
- data/.rubocop.yml +44 -0
- data/.simplecov +5 -0
- data/Gemfile +12 -0
- data/LICENSE.gpl +339 -0
- data/Manifest.txt +73 -0
- data/README.en +7 -21
- data/README.ja +19 -99
- data/Rakefile +31 -0
- data/bin/depager +7 -45
- data/examples/action_pl0d/pl0d.action.dr +421 -0
- data/examples/action_pl0d/test.pl0ds +48 -0
- data/examples/c89/c89.dr +493 -496
- data/examples/c89/test.c89 +10 -10
- data/examples/extension/astdf.rb +9 -0
- data/examples/extension/atree.dr +55 -0
- data/examples/{sample_calc → extension}/calc.atree.dr +42 -43
- data/examples/{sample_calc/calc.action.dr → extension/calc.simple_action.dr} +33 -33
- data/examples/extension/paction.dr +16 -15
- data/examples/extension/pactiontest.dr +14 -14
- data/examples/extension/simple_action.rb +46 -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/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/examples/{sample_calc/calc.nvaction.dr → tiny_calc/calc.action.dr} +33 -33
- data/examples/{sample_calc → tiny_calc}/calc.ast.action.dr +76 -66
- data/examples/{sample_calc → tiny_calc}/calc.ast.dr +67 -55
- data/examples/tiny_calc/calc.cst.dr +50 -0
- data/examples/{sample_calc → tiny_calc}/calc.dr +43 -43
- data/examples/{sample_calc → tiny_calc}/calc.lex.dr +29 -29
- data/examples/{sample_calc/calc_prec.nvaction.dr → tiny_calc/calc_prec.action.dr} +31 -31
- data/lib/depager/cli.rb +44 -0
- data/lib/depager/grammar.rb +253 -291
- data/lib/depager/lr.rb +589 -579
- data/lib/depager/parser.rb +269 -277
- data/lib/depager/plugins/_rie_debug.rb +63 -0
- data/lib/depager/plugins/action.rb +47 -0
- data/lib/depager/plugins/ast.dr +367 -0
- data/lib/depager/plugins/ast.rb +1329 -0
- data/lib/depager/{ruby/plugins → plugins}/cst.dr +174 -180
- data/lib/depager/plugins/cst.rb +591 -0
- data/lib/depager/{ruby/plugins → plugins}/lex.dr +85 -89
- data/lib/depager/plugins/lex.rb +313 -0
- data/lib/depager/plugins/rie.dr +725 -0
- data/lib/depager/plugins/rie.rb +1614 -0
- data/lib/depager/{ruby/plugins → plugins}/slex.dr +201 -200
- data/lib/depager/plugins/slex.rb +769 -0
- data/lib/depager/plugins/srp.rb +46 -0
- data/lib/depager/ruby/templates/extension_lalr_master.erb +40 -51
- data/lib/depager/ruby/templates/extension_lalr_slave.erb +113 -107
- data/lib/depager/ruby/templates/single_lalr_parser.erb +124 -117
- data/lib/depager/utils.rb +158 -318
- data/lib/depager/version.rb +3 -3
- data/lib/depager.rb +572 -670
- metadata +77 -80
- 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.dr +0 -45
- 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.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/action.rb +0 -43
- data/lib/depager/ruby/plugins/ast.dr +0 -269
- data/lib/depager/ruby/plugins/ast.rb +0 -1308
- 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/cst.rb +0 -626
- data/lib/depager/ruby/plugins/lex.rb +0 -336
- data/lib/depager/ruby/plugins/nvaction.rb +0 -19
- data/lib/depager/ruby/plugins/slex.rb +0 -817
- data/lib/depager/ruby/plugins/srp.rb +0 -51
- data/lib/depager/ruby/templates/simple.erb +0 -23
- data/setup.rb +0 -1585
- /data/examples/{sample_calc → tiny_calc}/test.calc +0 -0
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
begin; require 'rubygems'; rescue Exception; end
|
|
3
|
-
require 'depager/parser.rb'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
module Depager::DecoratorUtils; end
|
|
7
|
-
module D4TinyCalc; end
|
|
8
|
-
|
|
9
|
-
class TinyCalc < Depager::LALR::Basis
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
### Reduce Table
|
|
13
|
-
reduce_table = [
|
|
14
|
-
[ -1, 1 ], # ( 0) $start : expr
|
|
15
|
-
[ 0, 3 ], # ( 1) expr : expr '+' term
|
|
16
|
-
[ 0, 3 ], # ( 2) expr : expr '-' term
|
|
17
|
-
[ 0, 1 ], # ( 3) expr : term
|
|
18
|
-
[ 1, 3 ], # ( 4) term : term '*' fact
|
|
19
|
-
[ 1, 3 ], # ( 5) term : term '/' fact
|
|
20
|
-
[ 1, 1 ], # ( 6) term : fact
|
|
21
|
-
[ 2, 1 ], # ( 7) fact : NUM
|
|
22
|
-
[ 2, 3 ], # ( 8) fact : '(' expr ')'
|
|
23
|
-
]
|
|
24
|
-
### Extension Params
|
|
25
|
-
nparams = {
|
|
26
|
-
}
|
|
27
|
-
### Term to Int
|
|
28
|
-
t2i = {
|
|
29
|
-
nil => 0,
|
|
30
|
-
false => 1,
|
|
31
|
-
"+" => 2,
|
|
32
|
-
"-" => 3,
|
|
33
|
-
"*" => 4,
|
|
34
|
-
"/" => 5,
|
|
35
|
-
:NUM => 6,
|
|
36
|
-
"(" => 7,
|
|
37
|
-
")" => 8,
|
|
38
|
-
}
|
|
39
|
-
### Int to Term
|
|
40
|
-
i2t = [
|
|
41
|
-
nil,
|
|
42
|
-
false,
|
|
43
|
-
"+",
|
|
44
|
-
"-",
|
|
45
|
-
"*",
|
|
46
|
-
"/",
|
|
47
|
-
:NUM,
|
|
48
|
-
"(",
|
|
49
|
-
")",
|
|
50
|
-
]
|
|
51
|
-
### Action Table
|
|
52
|
-
action_table = [
|
|
53
|
-
[ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
|
|
54
|
-
[ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
|
|
55
|
-
[ ACC, nil, 7, 8, nil, nil, nil, nil, nil, ],
|
|
56
|
-
[ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
|
|
57
|
-
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
|
58
|
-
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
|
59
|
-
[ nil, nil, 7, 8, nil, nil, nil, nil, 11, ],
|
|
60
|
-
[ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
|
|
61
|
-
[ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
|
|
62
|
-
[ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
|
|
63
|
-
[ nil, nil, nil, nil, nil, nil, 5, 1, nil, ],
|
|
64
|
-
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
|
65
|
-
[ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
|
|
66
|
-
[ nil, nil, nil, nil, 9, 10, nil, nil, nil, ],
|
|
67
|
-
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
|
68
|
-
[ nil, nil, nil, nil, nil, nil, nil, nil, nil, ],
|
|
69
|
-
]
|
|
70
|
-
### Default Reduce Table
|
|
71
|
-
defred_table = [
|
|
72
|
-
nil,
|
|
73
|
-
nil,
|
|
74
|
-
nil,
|
|
75
|
-
-3,
|
|
76
|
-
-6,
|
|
77
|
-
-7,
|
|
78
|
-
nil,
|
|
79
|
-
nil,
|
|
80
|
-
nil,
|
|
81
|
-
nil,
|
|
82
|
-
nil,
|
|
83
|
-
-8,
|
|
84
|
-
-1,
|
|
85
|
-
-2,
|
|
86
|
-
-4,
|
|
87
|
-
-5,
|
|
88
|
-
]
|
|
89
|
-
defred_after_shift_table = [
|
|
90
|
-
nil,
|
|
91
|
-
nil,
|
|
92
|
-
nil,
|
|
93
|
-
nil,
|
|
94
|
-
-6,
|
|
95
|
-
-7,
|
|
96
|
-
nil,
|
|
97
|
-
nil,
|
|
98
|
-
nil,
|
|
99
|
-
nil,
|
|
100
|
-
nil,
|
|
101
|
-
-8,
|
|
102
|
-
nil,
|
|
103
|
-
nil,
|
|
104
|
-
-4,
|
|
105
|
-
-5,
|
|
106
|
-
]
|
|
107
|
-
### Nonterm to Int
|
|
108
|
-
nt2i = {
|
|
109
|
-
:expr => 0,
|
|
110
|
-
:term => 1,
|
|
111
|
-
:fact => 2,
|
|
112
|
-
}
|
|
113
|
-
### Int to Nonterm
|
|
114
|
-
i2nt = [
|
|
115
|
-
:expr,
|
|
116
|
-
:term,
|
|
117
|
-
:fact,
|
|
118
|
-
]
|
|
119
|
-
### Goto Table
|
|
120
|
-
goto_table = [
|
|
121
|
-
[ 2, 3, 4, ],
|
|
122
|
-
[ 6, 3, 4, ],
|
|
123
|
-
[ nil, nil, nil, ],
|
|
124
|
-
[ nil, nil, nil, ],
|
|
125
|
-
[ nil, nil, nil, ],
|
|
126
|
-
[ nil, nil, nil, ],
|
|
127
|
-
[ nil, nil, nil, ],
|
|
128
|
-
[ nil, 12, 4, ],
|
|
129
|
-
[ nil, 13, 4, ],
|
|
130
|
-
[ nil, nil, 14, ],
|
|
131
|
-
[ nil, nil, 15, ],
|
|
132
|
-
[ nil, nil, nil, ],
|
|
133
|
-
[ nil, nil, nil, ],
|
|
134
|
-
[ nil, nil, nil, ],
|
|
135
|
-
[ nil, nil, nil, ],
|
|
136
|
-
[ nil, nil, nil, ],
|
|
137
|
-
]
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
alias orig_error error
|
|
141
|
-
def error
|
|
142
|
-
orig_error
|
|
143
|
-
warn "current state: #{StateInfo[@stack.last]}"
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
### States
|
|
147
|
-
StateInfo = [
|
|
148
|
-
<<'----------',
|
|
149
|
-
I000 =
|
|
150
|
-
( 0) $start : _ expr
|
|
151
|
-
|
|
152
|
-
NUM shift, and goto to state 5
|
|
153
|
-
'(' shift, and goto to state 1
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
----------
|
|
157
|
-
|
|
158
|
-
<<'----------',
|
|
159
|
-
I001 =
|
|
160
|
-
( 8) fact : '(' _ expr ')'
|
|
161
|
-
|
|
162
|
-
NUM shift, and goto to state 5
|
|
163
|
-
'(' shift, and goto to state 1
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
----------
|
|
167
|
-
|
|
168
|
-
<<'----------',
|
|
169
|
-
I002 =
|
|
170
|
-
( 0) $start : expr _
|
|
171
|
-
( 1) expr : expr _ '+' term
|
|
172
|
-
( 2) expr : expr _ '-' term
|
|
173
|
-
|
|
174
|
-
'+' shift, and goto to state 7
|
|
175
|
-
'-' shift, and goto to state 8
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
$end accept
|
|
179
|
-
|
|
180
|
-
----------
|
|
181
|
-
|
|
182
|
-
<<'----------',
|
|
183
|
-
I003 =
|
|
184
|
-
( 3) expr : term _
|
|
185
|
-
( 4) term : term _ '*' fact
|
|
186
|
-
( 5) term : term _ '/' fact
|
|
187
|
-
|
|
188
|
-
'*' shift, and goto to state 9
|
|
189
|
-
'/' shift, and goto to state 10
|
|
190
|
-
|
|
191
|
-
$default reduce using rule 3 (expr)
|
|
192
|
-
|
|
193
|
-
----------
|
|
194
|
-
|
|
195
|
-
<<'----------',
|
|
196
|
-
I004 =
|
|
197
|
-
( 6) term : fact _
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
$default reduce using rule 6 (term) [after shift]
|
|
201
|
-
|
|
202
|
-
----------
|
|
203
|
-
|
|
204
|
-
<<'----------',
|
|
205
|
-
I005 =
|
|
206
|
-
( 7) fact : NUM _
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
$default reduce using rule 7 (fact) [after shift]
|
|
210
|
-
|
|
211
|
-
----------
|
|
212
|
-
|
|
213
|
-
<<'----------',
|
|
214
|
-
I006 =
|
|
215
|
-
( 8) fact : '(' expr _ ')'
|
|
216
|
-
( 1) expr : expr _ '+' term
|
|
217
|
-
( 2) expr : expr _ '-' term
|
|
218
|
-
|
|
219
|
-
'+' shift, and goto to state 7
|
|
220
|
-
'-' shift, and goto to state 8
|
|
221
|
-
')' shift, and goto to state 11
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
----------
|
|
225
|
-
|
|
226
|
-
<<'----------',
|
|
227
|
-
I007 =
|
|
228
|
-
( 1) expr : expr '+' _ term
|
|
229
|
-
|
|
230
|
-
NUM shift, and goto to state 5
|
|
231
|
-
'(' shift, and goto to state 1
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
----------
|
|
235
|
-
|
|
236
|
-
<<'----------',
|
|
237
|
-
I008 =
|
|
238
|
-
( 2) expr : expr '-' _ term
|
|
239
|
-
|
|
240
|
-
NUM shift, and goto to state 5
|
|
241
|
-
'(' shift, and goto to state 1
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
----------
|
|
245
|
-
|
|
246
|
-
<<'----------',
|
|
247
|
-
I009 =
|
|
248
|
-
( 4) term : term '*' _ fact
|
|
249
|
-
|
|
250
|
-
NUM shift, and goto to state 5
|
|
251
|
-
'(' shift, and goto to state 1
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
----------
|
|
255
|
-
|
|
256
|
-
<<'----------',
|
|
257
|
-
I010 =
|
|
258
|
-
( 5) term : term '/' _ fact
|
|
259
|
-
|
|
260
|
-
NUM shift, and goto to state 5
|
|
261
|
-
'(' shift, and goto to state 1
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
----------
|
|
265
|
-
|
|
266
|
-
<<'----------',
|
|
267
|
-
I011 =
|
|
268
|
-
( 8) fact : '(' expr ')' _
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
$default reduce using rule 8 (fact) [after shift]
|
|
272
|
-
|
|
273
|
-
----------
|
|
274
|
-
|
|
275
|
-
<<'----------',
|
|
276
|
-
I012 =
|
|
277
|
-
( 1) expr : expr '+' term _
|
|
278
|
-
( 4) term : term _ '*' fact
|
|
279
|
-
( 5) term : term _ '/' fact
|
|
280
|
-
|
|
281
|
-
'*' shift, and goto to state 9
|
|
282
|
-
'/' shift, and goto to state 10
|
|
283
|
-
|
|
284
|
-
$default reduce using rule 1 (expr)
|
|
285
|
-
|
|
286
|
-
----------
|
|
287
|
-
|
|
288
|
-
<<'----------',
|
|
289
|
-
I013 =
|
|
290
|
-
( 2) expr : expr '-' term _
|
|
291
|
-
( 4) term : term _ '*' fact
|
|
292
|
-
( 5) term : term _ '/' fact
|
|
293
|
-
|
|
294
|
-
'*' shift, and goto to state 9
|
|
295
|
-
'/' shift, and goto to state 10
|
|
296
|
-
|
|
297
|
-
$default reduce using rule 2 (expr)
|
|
298
|
-
|
|
299
|
-
----------
|
|
300
|
-
|
|
301
|
-
<<'----------',
|
|
302
|
-
I014 =
|
|
303
|
-
( 4) term : term '*' fact _
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
$default reduce using rule 4 (term) [after shift]
|
|
307
|
-
|
|
308
|
-
----------
|
|
309
|
-
|
|
310
|
-
<<'----------',
|
|
311
|
-
I015 =
|
|
312
|
-
( 5) term : term '/' fact _
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
$default reduce using rule 5 (term) [after shift]
|
|
316
|
-
|
|
317
|
-
----------
|
|
318
|
-
]
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
Tables = [ reduce_table, nparams, action_table,
|
|
322
|
-
defred_table, defred_after_shift_table, goto_table,
|
|
323
|
-
t2i, i2t, nt2i, i2nt ]
|
|
324
|
-
|
|
325
|
-
def self.createDecoratedParser
|
|
326
|
-
TinyCalc.new()
|
|
327
|
-
end
|
|
328
|
-
|
|
329
|
-
### Inner Code
|
|
330
|
-
def lex
|
|
331
|
-
until @file.eof?
|
|
332
|
-
@line = @file.gets
|
|
333
|
-
until @line.empty? do
|
|
334
|
-
case @line
|
|
335
|
-
when /\A\s+/, /\A\#.*/, /\A\n/
|
|
336
|
-
#skip blank and comment
|
|
337
|
-
when /\A[0-9]+/
|
|
338
|
-
yield :NUM, $&
|
|
339
|
-
when /\A./
|
|
340
|
-
yield $&, $&
|
|
341
|
-
else
|
|
342
|
-
raise RuntimeError, "must not happen #{line}"
|
|
343
|
-
end
|
|
344
|
-
@line = $'
|
|
345
|
-
end
|
|
346
|
-
end
|
|
347
|
-
yield nil, nil
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
end
|
|
351
|
-
|
|
352
|
-
### Outer Code
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
def createDecoratedTinyCalc
|
|
356
|
-
TinyCalc.new()
|
|
357
|
-
end
|
|
358
|
-
|
|
359
|
-
### main
|
|
360
|
-
if __FILE__ == $0
|
|
361
|
-
### Main Code
|
|
362
|
-
parser = TinyCalc.new()
|
|
363
|
-
parser.parse(STDIN)
|
|
364
|
-
|
|
365
|
-
end
|