ed-precompiled_racc 1.8.1

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.
@@ -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
@@ -0,0 +1,5 @@
1
+ require_relative '../racc'
2
+ require_relative 'parser'
3
+ require_relative 'grammarfileparser'
4
+ require_relative 'parserfilegenerator'
5
+ require_relative 'logfilegenerator'
data/lib/racc.rb ADDED
@@ -0,0 +1,6 @@
1
+ require_relative 'racc/compat'
2
+ require_relative 'racc/debugflags'
3
+ require_relative 'racc/grammar'
4
+ require_relative 'racc/state'
5
+ require_relative 'racc/exception'
6
+ require_relative 'racc/info'
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ed-precompiled_racc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.8.1
5
+ platform: ruby
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
+ - ext/racc/cparse/extconf.rb
27
+ extra_rdoc_files:
28
+ - README.ja.rdoc
29
+ - README.rdoc
30
+ files:
31
+ - BSDL
32
+ - COPYING
33
+ - ChangeLog
34
+ - README.ja.rdoc
35
+ - README.rdoc
36
+ - TODO
37
+ - bin/racc
38
+ - doc/en/grammar.en.rdoc
39
+ - doc/en/grammar2.en.rdoc
40
+ - doc/ja/command.ja.html
41
+ - doc/ja/debug.ja.rdoc
42
+ - doc/ja/grammar.ja.rdoc
43
+ - doc/ja/index.ja.html
44
+ - doc/ja/parser.ja.rdoc
45
+ - doc/ja/usage.ja.html
46
+ - ext/racc/cparse/cparse.c
47
+ - ext/racc/cparse/extconf.rb
48
+ - lib/racc.rb
49
+ - lib/racc/compat.rb
50
+ - lib/racc/debugflags.rb
51
+ - lib/racc/exception.rb
52
+ - lib/racc/grammar.rb
53
+ - lib/racc/grammarfileparser.rb
54
+ - lib/racc/info.rb
55
+ - lib/racc/iset.rb
56
+ - lib/racc/logfilegenerator.rb
57
+ - lib/racc/parser-text.rb
58
+ - lib/racc/parser.rb
59
+ - lib/racc/parserfilegenerator.rb
60
+ - lib/racc/sourcetext.rb
61
+ - lib/racc/state.rb
62
+ - lib/racc/statetransitiontable.rb
63
+ - lib/racc/static.rb
64
+ homepage: https://github.com/ruby/racc
65
+ licenses:
66
+ - Ruby
67
+ - BSD-2-Clause
68
+ metadata:
69
+ homepage_uri: https://github.com/ruby/racc
70
+ source_code_uri: https://github.com/ruby/racc
71
+ documentation_uri: https://ruby.github.io/racc/
72
+ changelog_uri: https://github.com/ruby/racc/releases
73
+ rdoc_options:
74
+ - "--main"
75
+ - README.rdoc
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '2.5'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.6.7
90
+ specification_version: 4
91
+ summary: Racc is an LALR(1) parser generator
92
+ test_files: []