ed-precompiled_racc 1.8.1-arm64-darwin
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/BSDL +22 -0
- data/COPYING +56 -0
- data/ChangeLog +846 -0
- data/README.ja.rdoc +58 -0
- data/README.rdoc +60 -0
- data/TODO +5 -0
- data/bin/racc +320 -0
- data/doc/en/grammar.en.rdoc +218 -0
- data/doc/en/grammar2.en.rdoc +219 -0
- data/doc/ja/command.ja.html +99 -0
- data/doc/ja/debug.ja.rdoc +36 -0
- data/doc/ja/grammar.ja.rdoc +348 -0
- data/doc/ja/index.ja.html +10 -0
- data/doc/ja/parser.ja.rdoc +125 -0
- data/doc/ja/usage.ja.html +414 -0
- data/ext/racc/cparse/cparse.c +840 -0
- data/ext/racc/cparse/extconf.rb +8 -0
- data/lib/racc/3.0/cparse.bundle +0 -0
- data/lib/racc/3.1/cparse.bundle +0 -0
- data/lib/racc/3.2/cparse.bundle +0 -0
- data/lib/racc/3.3/cparse.bundle +0 -0
- data/lib/racc/3.4/cparse.bundle +0 -0
- data/lib/racc/compat.rb +33 -0
- data/lib/racc/debugflags.rb +60 -0
- data/lib/racc/exception.rb +16 -0
- data/lib/racc/grammar.rb +1191 -0
- data/lib/racc/grammarfileparser.rb +667 -0
- data/lib/racc/info.rb +18 -0
- data/lib/racc/iset.rb +92 -0
- data/lib/racc/logfilegenerator.rb +212 -0
- data/lib/racc/parser-text.rb +496 -0
- data/lib/racc/parser.rb +650 -0
- data/lib/racc/parserfilegenerator.rb +473 -0
- data/lib/racc/sourcetext.rb +35 -0
- data/lib/racc/state.rb +976 -0
- data/lib/racc/statetransitiontable.rb +311 -0
- data/lib/racc/static.rb +5 -0
- data/lib/racc.rb +6 -0
- metadata +99 -0
@@ -0,0 +1,311 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# Copyright (c) 1999-2006 Minero Aoki
|
6
|
+
#
|
7
|
+
# This program is free software.
|
8
|
+
# You can distribute/modify this program under the same terms of ruby.
|
9
|
+
# see the file "COPYING".
|
10
|
+
#
|
11
|
+
#++
|
12
|
+
|
13
|
+
require_relative 'parser'
|
14
|
+
|
15
|
+
module Racc
|
16
|
+
|
17
|
+
StateTransitionTable = Struct.new(:action_table,
|
18
|
+
:action_check,
|
19
|
+
:action_default,
|
20
|
+
:action_pointer,
|
21
|
+
:goto_table,
|
22
|
+
:goto_check,
|
23
|
+
:goto_default,
|
24
|
+
:goto_pointer,
|
25
|
+
:token_table,
|
26
|
+
:reduce_table,
|
27
|
+
:reduce_n,
|
28
|
+
:shift_n,
|
29
|
+
:nt_base,
|
30
|
+
:token_to_s_table,
|
31
|
+
:use_result_var,
|
32
|
+
:debug_parser)
|
33
|
+
class StateTransitionTable # reopen
|
34
|
+
def StateTransitionTable.generate(states)
|
35
|
+
StateTransitionTableGenerator.new(states).generate
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(states)
|
39
|
+
super()
|
40
|
+
@states = states
|
41
|
+
@grammar = states.grammar
|
42
|
+
self.use_result_var = true
|
43
|
+
self.debug_parser = true
|
44
|
+
end
|
45
|
+
|
46
|
+
attr_reader :states
|
47
|
+
attr_reader :grammar
|
48
|
+
|
49
|
+
def parser_class
|
50
|
+
ParserClassGenerator.new(@states).generate
|
51
|
+
end
|
52
|
+
|
53
|
+
def token_value_table
|
54
|
+
h = {}
|
55
|
+
token_table().each do |sym, i|
|
56
|
+
h[sym.value] = i
|
57
|
+
end
|
58
|
+
h
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
class StateTransitionTableGenerator
|
64
|
+
|
65
|
+
def initialize(states)
|
66
|
+
@states = states
|
67
|
+
@grammar = states.grammar
|
68
|
+
end
|
69
|
+
|
70
|
+
def generate
|
71
|
+
t = StateTransitionTable.new(@states)
|
72
|
+
gen_action_tables t, @states
|
73
|
+
gen_goto_tables t, @grammar
|
74
|
+
t.token_table = token_table(@grammar)
|
75
|
+
t.reduce_table = reduce_table(@grammar)
|
76
|
+
t.reduce_n = @states.reduce_n
|
77
|
+
t.shift_n = @states.shift_n
|
78
|
+
t.nt_base = @grammar.nonterminal_base
|
79
|
+
t.token_to_s_table = @grammar.symbols.map {|sym| sym.to_s }
|
80
|
+
t
|
81
|
+
end
|
82
|
+
|
83
|
+
def reduce_table(grammar)
|
84
|
+
t = [0, 0, :racc_error]
|
85
|
+
grammar.each_with_index do |rule, idx|
|
86
|
+
next if idx == 0
|
87
|
+
t.push rule.size
|
88
|
+
t.push rule.target.ident
|
89
|
+
t.push(if rule.action.empty? # and @params.omit_action_call?
|
90
|
+
then :_reduce_none
|
91
|
+
else "_reduce_#{idx}".intern
|
92
|
+
end)
|
93
|
+
end
|
94
|
+
t
|
95
|
+
end
|
96
|
+
|
97
|
+
def token_table(grammar)
|
98
|
+
h = {}
|
99
|
+
grammar.symboltable.terminals.each do |t|
|
100
|
+
h[t] = t.ident
|
101
|
+
end
|
102
|
+
h
|
103
|
+
end
|
104
|
+
|
105
|
+
def gen_action_tables(t, states)
|
106
|
+
t.action_table = yytable = []
|
107
|
+
t.action_check = yycheck = []
|
108
|
+
t.action_default = yydefact = []
|
109
|
+
t.action_pointer = yypact = []
|
110
|
+
e1 = []
|
111
|
+
e2 = []
|
112
|
+
states.each do |state|
|
113
|
+
yydefact.push act2actid(state.defact)
|
114
|
+
if state.action.empty?
|
115
|
+
yypact.push nil
|
116
|
+
next
|
117
|
+
end
|
118
|
+
vector = []
|
119
|
+
state.action.each do |tok, act|
|
120
|
+
vector[tok.ident] = act2actid(act)
|
121
|
+
end
|
122
|
+
addent e1, vector, state.ident, yypact
|
123
|
+
end
|
124
|
+
set_table e1, e2, yytable, yycheck, yypact
|
125
|
+
end
|
126
|
+
|
127
|
+
def gen_goto_tables(t, grammar)
|
128
|
+
t.goto_table = yytable2 = []
|
129
|
+
t.goto_check = yycheck2 = []
|
130
|
+
t.goto_pointer = yypgoto = []
|
131
|
+
t.goto_default = yydefgoto = []
|
132
|
+
e1 = []
|
133
|
+
e2 = []
|
134
|
+
grammar.each_nonterminal do |tok|
|
135
|
+
tmp = []
|
136
|
+
|
137
|
+
# decide default
|
138
|
+
freq = Array.new(@states.size, 0)
|
139
|
+
@states.each do |state|
|
140
|
+
st = state.goto_table[tok]
|
141
|
+
if st
|
142
|
+
st = st.ident
|
143
|
+
freq[st] += 1
|
144
|
+
end
|
145
|
+
tmp[state.ident] = st
|
146
|
+
end
|
147
|
+
max = freq.max
|
148
|
+
if max > 1
|
149
|
+
default = freq.index(max)
|
150
|
+
tmp.map! {|i| default == i ? nil : i }
|
151
|
+
else
|
152
|
+
default = nil
|
153
|
+
end
|
154
|
+
yydefgoto.push default
|
155
|
+
|
156
|
+
# delete default value
|
157
|
+
tmp.pop until tmp.last or tmp.empty?
|
158
|
+
if tmp.compact.empty?
|
159
|
+
# only default
|
160
|
+
yypgoto.push nil
|
161
|
+
next
|
162
|
+
end
|
163
|
+
|
164
|
+
addent e1, tmp, (tok.ident - grammar.nonterminal_base), yypgoto
|
165
|
+
end
|
166
|
+
set_table e1, e2, yytable2, yycheck2, yypgoto
|
167
|
+
end
|
168
|
+
|
169
|
+
def addent(all, arr, chkval, ptr)
|
170
|
+
max = arr.size
|
171
|
+
min = nil
|
172
|
+
arr.each_with_index do |item, idx|
|
173
|
+
if item
|
174
|
+
min ||= idx
|
175
|
+
end
|
176
|
+
end
|
177
|
+
ptr.push(-7777) # mark
|
178
|
+
arr = arr[min...max]
|
179
|
+
all.push [arr, chkval, mkmapexp(arr), min, ptr.size - 1]
|
180
|
+
end
|
181
|
+
|
182
|
+
n = 2 ** 16
|
183
|
+
begin
|
184
|
+
Regexp.compile("a{#{n}}")
|
185
|
+
RE_DUP_MAX = n
|
186
|
+
rescue RegexpError
|
187
|
+
n /= 2
|
188
|
+
retry
|
189
|
+
end
|
190
|
+
|
191
|
+
def mkmapexp(arr)
|
192
|
+
i = ii = 0
|
193
|
+
as = arr.size
|
194
|
+
map = String.new
|
195
|
+
maxdup = RE_DUP_MAX
|
196
|
+
curr = nil
|
197
|
+
while i < as
|
198
|
+
ii = i + 1
|
199
|
+
if arr[i]
|
200
|
+
ii += 1 while ii < as and arr[ii]
|
201
|
+
curr = '-'
|
202
|
+
else
|
203
|
+
ii += 1 while ii < as and not arr[ii]
|
204
|
+
curr = '.'
|
205
|
+
end
|
206
|
+
|
207
|
+
offset = ii - i
|
208
|
+
if offset == 1
|
209
|
+
map << curr
|
210
|
+
else
|
211
|
+
while offset > maxdup
|
212
|
+
map << "#{curr}{#{maxdup}}"
|
213
|
+
offset -= maxdup
|
214
|
+
end
|
215
|
+
map << "#{curr}{#{offset}}" if offset > 1
|
216
|
+
end
|
217
|
+
i = ii
|
218
|
+
end
|
219
|
+
Regexp.compile(map, Regexp::NOENCODING)
|
220
|
+
end
|
221
|
+
|
222
|
+
def set_table(entries, dummy, tbl, chk, ptr)
|
223
|
+
upper = 0
|
224
|
+
map = '-' * 10240
|
225
|
+
|
226
|
+
# sort long to short
|
227
|
+
entries.sort_by!.with_index {|a,i| [-a[0].size, i] }
|
228
|
+
|
229
|
+
entries.each do |arr, chkval, expr, min, ptri|
|
230
|
+
if upper + arr.size > map.size
|
231
|
+
map << '-' * (arr.size + 1024)
|
232
|
+
end
|
233
|
+
idx = map.index(expr)
|
234
|
+
ptr[ptri] = idx - min
|
235
|
+
arr.each_with_index do |item, i|
|
236
|
+
if item
|
237
|
+
i += idx
|
238
|
+
tbl[i] = item
|
239
|
+
chk[i] = chkval
|
240
|
+
map[i] = ?o
|
241
|
+
end
|
242
|
+
end
|
243
|
+
upper = idx + arr.size
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def act2actid(act)
|
248
|
+
case act
|
249
|
+
when Shift then act.goto_id
|
250
|
+
when Reduce then -act.ruleid
|
251
|
+
when Accept then @states.shift_n
|
252
|
+
when Error then @states.reduce_n * -1
|
253
|
+
else
|
254
|
+
raise "racc: fatal: wrong act type #{act.class} in action table"
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
|
261
|
+
class ParserClassGenerator
|
262
|
+
|
263
|
+
def initialize(states)
|
264
|
+
@states = states
|
265
|
+
@grammar = states.grammar
|
266
|
+
end
|
267
|
+
|
268
|
+
def generate
|
269
|
+
table = @states.state_transition_table
|
270
|
+
c = Class.new(::Racc::Parser)
|
271
|
+
c.const_set :Racc_arg, [table.action_table,
|
272
|
+
table.action_check,
|
273
|
+
table.action_default,
|
274
|
+
table.action_pointer,
|
275
|
+
table.goto_table,
|
276
|
+
table.goto_check,
|
277
|
+
table.goto_default,
|
278
|
+
table.goto_pointer,
|
279
|
+
table.nt_base,
|
280
|
+
table.reduce_table,
|
281
|
+
table.token_value_table,
|
282
|
+
table.shift_n,
|
283
|
+
table.reduce_n,
|
284
|
+
false]
|
285
|
+
c.const_set :Racc_token_to_s_table, table.token_to_s_table
|
286
|
+
c.const_set :Racc_debug_parser, true
|
287
|
+
define_actions c
|
288
|
+
c
|
289
|
+
end
|
290
|
+
|
291
|
+
private
|
292
|
+
|
293
|
+
def define_actions(c)
|
294
|
+
c.module_eval "def _reduce_none(vals, vstack) vals[0] end"
|
295
|
+
@grammar.each do |rule|
|
296
|
+
if rule.action.empty?
|
297
|
+
c.alias_method("_reduce_#{rule.ident}", :_reduce_none)
|
298
|
+
else
|
299
|
+
c.define_method("_racc_action_#{rule.ident}", &rule.action.proc)
|
300
|
+
c.module_eval(<<-End, __FILE__, __LINE__ + 1)
|
301
|
+
def _reduce_#{rule.ident}(vals, vstack)
|
302
|
+
_racc_action_#{rule.ident}(*vals)
|
303
|
+
end
|
304
|
+
End
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
end # module Racc
|
data/lib/racc/static.rb
ADDED
data/lib/racc.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ed-precompiled_racc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.8.1
|
5
|
+
platform: arm64-darwin
|
6
|
+
authors:
|
7
|
+
- Minero Aoki
|
8
|
+
- Aaron Patterson
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |
|
14
|
+
Racc is an LALR(1) parser generator.
|
15
|
+
It is written in Ruby itself, and generates Ruby program.
|
16
|
+
|
17
|
+
NOTE: Ruby 1.8.x comes with Racc runtime module. You
|
18
|
+
can run your parsers generated by racc 1.4.x out of the
|
19
|
+
box.
|
20
|
+
email:
|
21
|
+
-
|
22
|
+
- aaron@tenderlovemaking.com
|
23
|
+
executables:
|
24
|
+
- racc
|
25
|
+
extensions: []
|
26
|
+
extra_rdoc_files:
|
27
|
+
- README.ja.rdoc
|
28
|
+
- README.rdoc
|
29
|
+
files:
|
30
|
+
- BSDL
|
31
|
+
- COPYING
|
32
|
+
- ChangeLog
|
33
|
+
- README.ja.rdoc
|
34
|
+
- README.rdoc
|
35
|
+
- TODO
|
36
|
+
- bin/racc
|
37
|
+
- doc/en/grammar.en.rdoc
|
38
|
+
- doc/en/grammar2.en.rdoc
|
39
|
+
- doc/ja/command.ja.html
|
40
|
+
- doc/ja/debug.ja.rdoc
|
41
|
+
- doc/ja/grammar.ja.rdoc
|
42
|
+
- doc/ja/index.ja.html
|
43
|
+
- doc/ja/parser.ja.rdoc
|
44
|
+
- doc/ja/usage.ja.html
|
45
|
+
- ext/racc/cparse/cparse.c
|
46
|
+
- ext/racc/cparse/extconf.rb
|
47
|
+
- lib/racc.rb
|
48
|
+
- lib/racc/3.0/cparse.bundle
|
49
|
+
- lib/racc/3.1/cparse.bundle
|
50
|
+
- lib/racc/3.2/cparse.bundle
|
51
|
+
- lib/racc/3.3/cparse.bundle
|
52
|
+
- lib/racc/3.4/cparse.bundle
|
53
|
+
- lib/racc/compat.rb
|
54
|
+
- lib/racc/debugflags.rb
|
55
|
+
- lib/racc/exception.rb
|
56
|
+
- lib/racc/grammar.rb
|
57
|
+
- lib/racc/grammarfileparser.rb
|
58
|
+
- lib/racc/info.rb
|
59
|
+
- lib/racc/iset.rb
|
60
|
+
- lib/racc/logfilegenerator.rb
|
61
|
+
- lib/racc/parser-text.rb
|
62
|
+
- lib/racc/parser.rb
|
63
|
+
- lib/racc/parserfilegenerator.rb
|
64
|
+
- lib/racc/sourcetext.rb
|
65
|
+
- lib/racc/state.rb
|
66
|
+
- lib/racc/statetransitiontable.rb
|
67
|
+
- lib/racc/static.rb
|
68
|
+
homepage: https://github.com/ruby/racc
|
69
|
+
licenses:
|
70
|
+
- Ruby
|
71
|
+
- BSD-2-Clause
|
72
|
+
metadata:
|
73
|
+
homepage_uri: https://github.com/ruby/racc
|
74
|
+
source_code_uri: https://github.com/ruby/racc
|
75
|
+
documentation_uri: https://ruby.github.io/racc/
|
76
|
+
changelog_uri: https://github.com/ruby/racc/releases
|
77
|
+
rdoc_options:
|
78
|
+
- "--main"
|
79
|
+
- README.rdoc
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '3.0'
|
87
|
+
- - "<"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.5.dev
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubygems_version: 3.6.7
|
97
|
+
specification_version: 4
|
98
|
+
summary: Racc is an LALR(1) parser generator
|
99
|
+
test_files: []
|