racc 1.4.16-java → 1.6.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.ja.rdoc +0 -1
- data/README.rdoc +8 -11
- data/bin/racc +37 -23
- data/{rdoc → doc}/en/NEWS.en.rdoc +0 -0
- data/{rdoc → doc}/en/grammar.en.rdoc +27 -31
- data/doc/en/grammar2.en.rdoc +219 -0
- data/{rdoc → doc}/ja/NEWS.ja.rdoc +0 -0
- data/{rdoc → doc}/ja/command.ja.html +1 -1
- data/{rdoc → doc}/ja/debug.ja.rdoc +0 -0
- data/{rdoc → doc}/ja/grammar.ja.rdoc +0 -0
- data/{rdoc → doc}/ja/index.ja.html +0 -0
- data/{rdoc → doc}/ja/parser.ja.rdoc +0 -0
- data/{rdoc → doc}/ja/usage.ja.html +0 -0
- data/ext/racc/cparse/cparse.c +19 -17
- data/ext/racc/cparse/extconf.rb +2 -1
- data/lib/racc/compat.rb +5 -4
- data/lib/racc/cparse-jruby.jar +0 -0
- data/lib/racc/debugflags.rb +5 -4
- data/lib/racc/exception.rb +4 -1
- data/lib/racc/grammar.rb +22 -17
- data/lib/racc/grammarfileparser.rb +7 -6
- data/lib/racc/info.rb +5 -2
- data/lib/racc/iset.rb +5 -4
- data/lib/racc/logfilegenerator.rb +5 -4
- data/lib/racc/parser-text.rb +10 -16
- data/lib/racc/parser.rb +10 -16
- data/lib/racc/parserfilegenerator.rb +5 -47
- data/lib/racc/sourcetext.rb +5 -4
- data/lib/racc/state.rb +4 -1
- data/lib/racc/statetransitiontable.rb +9 -14
- metadata +18 -137
- data/DEPENDS +0 -4
- data/Manifest.txt +0 -146
- data/Rakefile +0 -58
- data/bin/racc2y +0 -195
- data/bin/y2racc +0 -339
- data/ext/racc/com/headius/racc/Cparse.java +0 -849
- data/fastcache/extconf.rb +0 -2
- data/fastcache/fastcache.c +0 -185
- data/lib/racc/pre-setup +0 -13
- data/misc/dist.sh +0 -31
- data/sample/array.y +0 -67
- data/sample/array2.y +0 -59
- data/sample/calc-ja.y +0 -66
- data/sample/calc.y +0 -65
- data/sample/conflict.y +0 -15
- data/sample/hash.y +0 -60
- data/sample/lalr.y +0 -17
- data/sample/lists.y +0 -57
- data/sample/syntax.y +0 -46
- data/sample/yyerr.y +0 -46
- data/setup.rb +0 -1587
- data/tasks/doc.rb +0 -12
- data/tasks/email.rb +0 -55
- data/test/assets/cadenza.y +0 -170
- data/test/assets/cast.y +0 -926
- data/test/assets/chk.y +0 -126
- data/test/assets/conf.y +0 -16
- data/test/assets/csspool.y +0 -729
- data/test/assets/digraph.y +0 -29
- data/test/assets/echk.y +0 -118
- data/test/assets/edtf.y +0 -583
- data/test/assets/err.y +0 -60
- data/test/assets/error_recovery.y +0 -35
- data/test/assets/expect.y +0 -7
- data/test/assets/firstline.y +0 -4
- data/test/assets/huia.y +0 -318
- data/test/assets/ichk.y +0 -102
- data/test/assets/intp.y +0 -546
- data/test/assets/journey.y +0 -47
- data/test/assets/liquor.y +0 -313
- data/test/assets/machete.y +0 -423
- data/test/assets/macruby.y +0 -2197
- data/test/assets/mailp.y +0 -437
- data/test/assets/mediacloth.y +0 -599
- data/test/assets/mof.y +0 -649
- data/test/assets/namae.y +0 -302
- data/test/assets/nasl.y +0 -626
- data/test/assets/newsyn.y +0 -25
- data/test/assets/noend.y +0 -4
- data/test/assets/nokogiri-css.y +0 -255
- data/test/assets/nonass.y +0 -41
- data/test/assets/normal.y +0 -27
- data/test/assets/norule.y +0 -4
- data/test/assets/nullbug1.y +0 -25
- data/test/assets/nullbug2.y +0 -15
- data/test/assets/opal.y +0 -1807
- data/test/assets/opt.y +0 -123
- data/test/assets/percent.y +0 -35
- data/test/assets/php_serialization.y +0 -98
- data/test/assets/recv.y +0 -97
- data/test/assets/riml.y +0 -665
- data/test/assets/rrconf.y +0 -14
- data/test/assets/ruby18.y +0 -1943
- data/test/assets/ruby19.y +0 -2174
- data/test/assets/ruby20.y +0 -2350
- data/test/assets/ruby21.y +0 -2359
- data/test/assets/ruby22.y +0 -2381
- data/test/assets/scan.y +0 -72
- data/test/assets/syntax.y +0 -50
- data/test/assets/tp_plus.y +0 -622
- data/test/assets/twowaysql.y +0 -278
- data/test/assets/unterm.y +0 -5
- data/test/assets/useless.y +0 -12
- data/test/assets/yyerr.y +0 -46
- data/test/bench.y +0 -36
- data/test/helper.rb +0 -115
- data/test/infini.y +0 -8
- data/test/regress/cadenza +0 -796
- data/test/regress/cast +0 -3425
- data/test/regress/csspool +0 -2318
- data/test/regress/edtf +0 -1794
- data/test/regress/huia +0 -1392
- data/test/regress/journey +0 -222
- data/test/regress/liquor +0 -885
- data/test/regress/machete +0 -833
- data/test/regress/mediacloth +0 -1463
- data/test/regress/mof +0 -1368
- data/test/regress/namae +0 -634
- data/test/regress/nasl +0 -2058
- data/test/regress/nokogiri-css +0 -836
- data/test/regress/opal +0 -6429
- data/test/regress/php_serialization +0 -336
- data/test/regress/riml +0 -3297
- data/test/regress/ruby18 +0 -6351
- data/test/regress/ruby22 +0 -7456
- data/test/regress/tp_plus +0 -1933
- data/test/regress/twowaysql +0 -556
- data/test/scandata/brace +0 -7
- data/test/scandata/gvar +0 -1
- data/test/scandata/normal +0 -4
- data/test/scandata/percent +0 -18
- data/test/scandata/slash +0 -10
- data/test/src.intp +0 -34
- data/test/start.y +0 -20
- data/test/test_chk_y.rb +0 -52
- data/test/test_grammar_file_parser.rb +0 -15
- data/test/test_racc_command.rb +0 -322
- data/test/test_scan_y.rb +0 -52
- data/test/testscanner.rb +0 -51
- data/web/racc.en.rhtml +0 -42
- data/web/racc.ja.rhtml +0 -51
data/bin/y2racc
DELETED
@@ -1,339 +0,0 @@
|
|
1
|
-
#!/usr/local/bin/ruby
|
2
|
-
#
|
3
|
-
# $Id$
|
4
|
-
#
|
5
|
-
# Copyright (c) 1999-2006 Minero Aoki
|
6
|
-
#
|
7
|
-
# This program is free software.
|
8
|
-
# You can distribute/modify this program under the terms of
|
9
|
-
# the GNU LGPL, Lesser General Public Lisence version 2.1.
|
10
|
-
# For details of the GNU LGPL, see the file "COPYING".
|
11
|
-
#
|
12
|
-
|
13
|
-
require 'racc/info'
|
14
|
-
require 'strscan'
|
15
|
-
require 'forwardable'
|
16
|
-
require 'optparse'
|
17
|
-
|
18
|
-
def main
|
19
|
-
@with_action = true
|
20
|
-
@with_header = false
|
21
|
-
@with_usercode = false
|
22
|
-
cname = 'MyParser'
|
23
|
-
input = nil
|
24
|
-
output = nil
|
25
|
-
parser = OptionParser.new
|
26
|
-
parser.banner = "Usage: #{File.basename($0)} [-Ahu] [-c <classname>] [-o <filename>] <input>"
|
27
|
-
parser.on('-o', '--output=FILENAME', 'output file name [<input>.racc]') {|name|
|
28
|
-
output = name
|
29
|
-
}
|
30
|
-
parser.on('-c', '--classname=NAME', "Name of the parser class. [#{cname}]") {|name|
|
31
|
-
cname = name
|
32
|
-
}
|
33
|
-
parser.on('-A', '--without-action', 'Does not include actions.') {
|
34
|
-
@with_action = false
|
35
|
-
}
|
36
|
-
parser.on('-h', '--with-header', 'Includes header (%{...%}).') {
|
37
|
-
@with_header = true
|
38
|
-
}
|
39
|
-
parser.on('-u', '--with-user-code', 'Includes user code.') {
|
40
|
-
@with_usercode = true
|
41
|
-
}
|
42
|
-
parser.on('--version', 'Prints version and quit.') {
|
43
|
-
puts "y2racc version #{Racc::Version}"
|
44
|
-
exit 0
|
45
|
-
}
|
46
|
-
parser.on('--copyright', 'Prints copyright and quit.') {
|
47
|
-
puts Racc::Copyright
|
48
|
-
exit 0
|
49
|
-
}
|
50
|
-
parser.on('--help', 'Prints this message and quit.') {
|
51
|
-
puts parser.help
|
52
|
-
exit 1
|
53
|
-
}
|
54
|
-
begin
|
55
|
-
parser.parse!
|
56
|
-
rescue OptionParser::ParseError => err
|
57
|
-
$stderr.puts err.message
|
58
|
-
$stderr.puts parser.help
|
59
|
-
exit 1
|
60
|
-
end
|
61
|
-
if ARGV.empty?
|
62
|
-
$stderr.puts 'no input'
|
63
|
-
exit 1
|
64
|
-
end
|
65
|
-
if ARGV.size > 1
|
66
|
-
$stderr.puts 'too many input'
|
67
|
-
exit 1
|
68
|
-
end
|
69
|
-
input = ARGV[0]
|
70
|
-
|
71
|
-
begin
|
72
|
-
result = YaccFileParser.parse_file(input)
|
73
|
-
File.open(output || "#{input}.racc", 'w') {|f|
|
74
|
-
convert cname, result, f
|
75
|
-
}
|
76
|
-
rescue SystemCallError => err
|
77
|
-
$stderr.puts err.message
|
78
|
-
exit 1
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def convert(classname, result, f)
|
83
|
-
init_indent = 'token'.size
|
84
|
-
f.puts %<# Converted from "#{result.filename}" by y2racc version #{Racc::Version}>
|
85
|
-
f.puts
|
86
|
-
f.puts "class #{classname}"
|
87
|
-
unless result.terminals.empty?
|
88
|
-
f.puts
|
89
|
-
f.print 'token'
|
90
|
-
columns = init_indent
|
91
|
-
result.terminals.each do |t|
|
92
|
-
if columns > 60
|
93
|
-
f.puts
|
94
|
-
f.print ' ' * init_indent
|
95
|
-
columns = init_indent
|
96
|
-
end
|
97
|
-
columns += f.write(" #{t}")
|
98
|
-
end
|
99
|
-
f.puts
|
100
|
-
end
|
101
|
-
unless result.precedence_table.empty?
|
102
|
-
f.puts
|
103
|
-
f.puts 'preclow'
|
104
|
-
result.precedence_table.each do |assoc, toks|
|
105
|
-
f.printf " %-8s %s\n", assoc, toks.join(' ') unless toks.empty?
|
106
|
-
end
|
107
|
-
f.puts 'prechigh'
|
108
|
-
end
|
109
|
-
if result.start
|
110
|
-
f.puts
|
111
|
-
f.puts "start #{@start}"
|
112
|
-
end
|
113
|
-
|
114
|
-
f.puts
|
115
|
-
f.puts 'rule'
|
116
|
-
texts = @with_action ? result.grammar : result.grammar_without_actions
|
117
|
-
texts.each do |text|
|
118
|
-
f.print text
|
119
|
-
end
|
120
|
-
|
121
|
-
if @with_header and result.header
|
122
|
-
f.puts
|
123
|
-
f.puts '---- header'
|
124
|
-
f.puts result.header
|
125
|
-
end
|
126
|
-
if @with_usercode and result.usercode
|
127
|
-
f.puts
|
128
|
-
f.puts '---- footer'
|
129
|
-
f.puts result.usercode
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
class ParseError < StandardError; end
|
134
|
-
|
135
|
-
class StringScanner_withlineno
|
136
|
-
def initialize(src)
|
137
|
-
@s = StringScanner.new(src)
|
138
|
-
@lineno = 1
|
139
|
-
end
|
140
|
-
|
141
|
-
extend Forwardable
|
142
|
-
def_delegator "@s", :eos?
|
143
|
-
def_delegator "@s", :rest
|
144
|
-
|
145
|
-
attr_reader :lineno
|
146
|
-
|
147
|
-
def scan(re)
|
148
|
-
advance_lineno(@s.scan(re))
|
149
|
-
end
|
150
|
-
|
151
|
-
def scan_until(re)
|
152
|
-
advance_lineno(@s.scan_until(re))
|
153
|
-
end
|
154
|
-
|
155
|
-
def skip(re)
|
156
|
-
str = advance_lineno(@s.scan(re))
|
157
|
-
str ? str.size : nil
|
158
|
-
end
|
159
|
-
|
160
|
-
def getch
|
161
|
-
advance_lineno(@s.getch)
|
162
|
-
end
|
163
|
-
|
164
|
-
private
|
165
|
-
|
166
|
-
def advance_lineno(str)
|
167
|
-
@lineno += str.count("\n") if str
|
168
|
-
str
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
class YaccFileParser
|
173
|
-
|
174
|
-
Result = Struct.new(:terminals, :precedence_table, :start,
|
175
|
-
:header, :grammar, :usercode, :filename)
|
176
|
-
class Result # reopen
|
177
|
-
def initialize
|
178
|
-
super
|
179
|
-
self.terminals = []
|
180
|
-
self.precedence_table = []
|
181
|
-
self.start = nil
|
182
|
-
self.grammar = []
|
183
|
-
self.header = nil
|
184
|
-
self.usercode = nil
|
185
|
-
self.filename = nil
|
186
|
-
end
|
187
|
-
|
188
|
-
def grammar_without_actions
|
189
|
-
grammar().map {|text| text[0,1] == '{' ? '{}' : text }
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
def YaccFileParser.parse_file(filename)
|
194
|
-
new().parse(File.read(filename), filename)
|
195
|
-
end
|
196
|
-
|
197
|
-
def parse(src, filename = '-')
|
198
|
-
@result = Result.new
|
199
|
-
@filename = filename
|
200
|
-
@result.filename = filename
|
201
|
-
s = StringScanner_withlineno.new(src)
|
202
|
-
parse_header s
|
203
|
-
parse_grammar s
|
204
|
-
@result
|
205
|
-
end
|
206
|
-
|
207
|
-
private
|
208
|
-
|
209
|
-
COMMENT = %r</\*[^*]*\*+(?:[^/*][^*]*\*+)*/>
|
210
|
-
CHAR = /'((?:[^'\\]+|\\.)*)'/
|
211
|
-
STRING = /"((?:[^"\\]+|\\.)*)"/
|
212
|
-
|
213
|
-
def parse_header(s)
|
214
|
-
skip_until_percent s
|
215
|
-
until s.eos?
|
216
|
-
case
|
217
|
-
when t = s.scan(/left/)
|
218
|
-
@result.precedence_table.push ['left', scan_symbols(s)]
|
219
|
-
when t = s.scan(/right/)
|
220
|
-
@result.precedence_table.push ['right', scan_symbols(s)]
|
221
|
-
when t = s.scan(/nonassoc/)
|
222
|
-
@result.precedence_table.push ['nonassoc', scan_symbols(s)]
|
223
|
-
when t = s.scan(/token/)
|
224
|
-
list = scan_symbols(s)
|
225
|
-
list.shift if /\A<(.*)>\z/ =~ list[0]
|
226
|
-
@result.terminals.concat list
|
227
|
-
when t = s.scan(/start/)
|
228
|
-
@result.start = scan_symbols(s)[0]
|
229
|
-
when s.skip(%r<(?:
|
230
|
-
type | union | expect | thong | binary |
|
231
|
-
semantic_parser | pure_parser | no_lines |
|
232
|
-
raw | token_table
|
233
|
-
)\b>x)
|
234
|
-
skip_until_percent s
|
235
|
-
when s.skip(/\{/) # header (%{...%})
|
236
|
-
str = s.scan_until(/\%\}/)
|
237
|
-
str.chop!
|
238
|
-
str.chop!
|
239
|
-
@result.header = str
|
240
|
-
skip_until_percent s
|
241
|
-
when s.skip(/\%/) # grammar (%%...)
|
242
|
-
return
|
243
|
-
else
|
244
|
-
raise ParseError, "#{@filename}:#{s.lineno}: scan error"
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
def skip_until_percent(s)
|
250
|
-
until s.eos?
|
251
|
-
s.skip /[^\%\/]+/
|
252
|
-
next if s.skip(COMMENT)
|
253
|
-
return if s.getch == '%'
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
def scan_symbols(s)
|
258
|
-
list = []
|
259
|
-
until s.eos?
|
260
|
-
s.skip /\s+/
|
261
|
-
if s.skip(COMMENT)
|
262
|
-
;
|
263
|
-
elsif t = s.scan(CHAR)
|
264
|
-
list.push t
|
265
|
-
elsif t = s.scan(STRING)
|
266
|
-
list.push t
|
267
|
-
elsif s.skip(/\%/)
|
268
|
-
break
|
269
|
-
elsif t = s.scan(/\S+/)
|
270
|
-
list.push t
|
271
|
-
else
|
272
|
-
raise ParseError, "#{@filename}:#{@lineno}: scan error"
|
273
|
-
end
|
274
|
-
end
|
275
|
-
list
|
276
|
-
end
|
277
|
-
|
278
|
-
def parse_grammar(s)
|
279
|
-
buf = []
|
280
|
-
until s.eos?
|
281
|
-
if t = s.scan(/[^%'"{\/]+/)
|
282
|
-
buf.push t
|
283
|
-
break if s.eos?
|
284
|
-
end
|
285
|
-
if s.skip(/\{/)
|
286
|
-
buf.push scan_action(s)
|
287
|
-
elsif t = s.scan(/'(?:[^'\\]+|\\.)*'/) then buf.push t
|
288
|
-
elsif t = s.scan(/"(?:[^"\\]+|\\.)*"/) then buf.push t
|
289
|
-
elsif t = s.scan(COMMENT) then buf.push t
|
290
|
-
elsif s.skip(/%prec\b/) then buf.push '='
|
291
|
-
elsif s.skip(/%%/)
|
292
|
-
@result.usercode = s.rest
|
293
|
-
break
|
294
|
-
else
|
295
|
-
buf.push s.getch
|
296
|
-
end
|
297
|
-
end
|
298
|
-
@result.grammar = buf
|
299
|
-
end
|
300
|
-
|
301
|
-
def scan_action(s)
|
302
|
-
buf = '{'
|
303
|
-
nest = 1
|
304
|
-
until s.eos?
|
305
|
-
if t = s.scan(%r<[^/{}'"]+>)
|
306
|
-
buf << t
|
307
|
-
break if s.eos?
|
308
|
-
elsif t = s.scan(COMMENT)
|
309
|
-
buf << t
|
310
|
-
elsif t = s.scan(CHAR)
|
311
|
-
buf << t
|
312
|
-
elsif t = s.scan(STRING)
|
313
|
-
buf << t
|
314
|
-
else
|
315
|
-
c = s.getch
|
316
|
-
buf << c
|
317
|
-
case c
|
318
|
-
when '{'
|
319
|
-
nest += 1
|
320
|
-
when '}'
|
321
|
-
nest -= 1
|
322
|
-
return buf if nest == 0
|
323
|
-
end
|
324
|
-
end
|
325
|
-
end
|
326
|
-
$stderr.puts "warning: unterminated action in #{@filename}"
|
327
|
-
buf
|
328
|
-
end
|
329
|
-
|
330
|
-
end
|
331
|
-
|
332
|
-
unless Object.method_defined?(:funcall)
|
333
|
-
class Object
|
334
|
-
alias funcall __send__
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
|
339
|
-
main
|