racc 1.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitattributes +2 -0
- data/.gitignore +7 -0
- data/COPYING +515 -0
- data/ChangeLog +846 -0
- data/DEPENDS +4 -0
- data/README.en.rdoc +86 -0
- data/README.ja.rdoc +96 -0
- data/Rakefile +15 -0
- data/TODO +5 -0
- data/bin/racc +308 -0
- data/bin/racc2y +195 -0
- data/bin/y2racc +339 -0
- data/doc/en/NEWS.en.rdoc +282 -0
- data/doc/en/command.en.html +78 -0
- data/doc/en/debug.en.rdoc +20 -0
- data/doc/en/grammar.en.rdoc +230 -0
- data/doc/en/index.en.html +10 -0
- data/doc/en/parser.en.rdoc +74 -0
- data/doc/en/usage.en.html +92 -0
- data/doc/ja/NEWS.ja.rdoc +307 -0
- data/doc/ja/command.ja.html +94 -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/MANIFEST +4 -0
- data/ext/racc/cparse/cparse.c +824 -0
- data/ext/racc/cparse/depend +1 -0
- data/ext/racc/cparse/extconf.rb +7 -0
- data/fastcache/extconf.rb +2 -0
- data/fastcache/fastcache.c +185 -0
- data/lib/racc.rb +6 -0
- data/lib/racc/compat.rb +40 -0
- data/lib/racc/debugflags.rb +59 -0
- data/lib/racc/exception.rb +15 -0
- data/lib/racc/grammar.rb +1115 -0
- data/lib/racc/grammarfileparser.rb +559 -0
- data/lib/racc/info.rb +16 -0
- data/lib/racc/iset.rb +91 -0
- data/lib/racc/logfilegenerator.rb +214 -0
- data/lib/racc/parser.rb +439 -0
- data/lib/racc/parserfilegenerator.rb +511 -0
- data/lib/racc/pre-setup +13 -0
- data/lib/racc/sourcetext.rb +34 -0
- data/lib/racc/state.rb +971 -0
- data/lib/racc/statetransitiontable.rb +316 -0
- data/lib/racc/static.rb +5 -0
- data/misc/dist.sh +31 -0
- data/sample/array.y +67 -0
- data/sample/array2.y +59 -0
- data/sample/calc-ja.y +66 -0
- data/sample/calc.y +65 -0
- data/sample/conflict.y +15 -0
- data/sample/hash.y +60 -0
- data/sample/lalr.y +17 -0
- data/sample/lists.y +57 -0
- data/sample/syntax.y +46 -0
- data/sample/yyerr.y +46 -0
- data/setup.rb +1587 -0
- data/tasks/doc.rb +12 -0
- data/tasks/email.rb +55 -0
- data/tasks/file.rb +37 -0
- data/tasks/gem.rb +37 -0
- data/tasks/test.rb +16 -0
- data/test/assets/chk.y +126 -0
- data/test/assets/conf.y +16 -0
- data/test/assets/digraph.y +29 -0
- data/test/assets/echk.y +118 -0
- data/test/assets/err.y +60 -0
- data/test/assets/expect.y +7 -0
- data/test/assets/firstline.y +4 -0
- data/test/assets/ichk.y +102 -0
- data/test/assets/intp.y +546 -0
- data/test/assets/mailp.y +437 -0
- data/test/assets/newsyn.y +25 -0
- data/test/assets/noend.y +4 -0
- data/test/assets/nonass.y +41 -0
- data/test/assets/normal.y +27 -0
- data/test/assets/norule.y +4 -0
- data/test/assets/nullbug1.y +25 -0
- data/test/assets/nullbug2.y +15 -0
- data/test/assets/opt.y +123 -0
- data/test/assets/percent.y +35 -0
- data/test/assets/recv.y +97 -0
- data/test/assets/rrconf.y +14 -0
- data/test/assets/scan.y +72 -0
- data/test/assets/syntax.y +50 -0
- data/test/assets/unterm.y +5 -0
- data/test/assets/useless.y +12 -0
- data/test/assets/yyerr.y +46 -0
- data/test/bench.y +36 -0
- data/test/helper.rb +88 -0
- data/test/infini.y +8 -0
- data/test/scandata/brace +7 -0
- data/test/scandata/gvar +1 -0
- data/test/scandata/normal +4 -0
- data/test/scandata/percent +18 -0
- data/test/scandata/slash +10 -0
- data/test/src.intp +34 -0
- data/test/start.y +20 -0
- data/test/test_chk_y.rb +51 -0
- data/test/test_grammar_file_parser.rb +15 -0
- data/test/test_racc_command.rb +155 -0
- data/test/test_scan_y.rb +51 -0
- data/test/testscanner.rb +51 -0
- data/web/racc.en.rhtml +42 -0
- data/web/racc.ja.rhtml +51 -0
- metadata +166 -0
data/tasks/doc.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rake/rdoctask'
|
2
|
+
|
3
|
+
Rake::RDocTask.new(:docs) do |rd|
|
4
|
+
rd.main = "README.en.rdoc"
|
5
|
+
rd.rdoc_files.include(SPEC.files.find_all { |file_name|
|
6
|
+
file_name =~ /^(bin|lib|ext)/ || file_name !~ /\//
|
7
|
+
})
|
8
|
+
|
9
|
+
title = "#{SPEC.name}-#{SPEC.version} Documentation"
|
10
|
+
|
11
|
+
rd.options << "-t #{title}"
|
12
|
+
end
|
data/tasks/email.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
class EmailTask
|
2
|
+
def initialize language, readme, changelog
|
3
|
+
@language = language
|
4
|
+
@readme = readme
|
5
|
+
@changelog = changelog
|
6
|
+
@languages = {
|
7
|
+
:en => {
|
8
|
+
:release => 'release',
|
9
|
+
:released => 'has been released',
|
10
|
+
},
|
11
|
+
:ja => {
|
12
|
+
:release => 'リリース',
|
13
|
+
:released => 'はリリースしました',
|
14
|
+
}
|
15
|
+
}
|
16
|
+
define_tasks
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def define_tasks
|
21
|
+
namespace :email do
|
22
|
+
task @language do
|
23
|
+
subject = "#{SPEC.name} #{SPEC.version} #{@languages[@language][:release]}"
|
24
|
+
title = "#{SPEC.name} #{SPEC.version} #{@languages[@language][:released]}!"
|
25
|
+
readme = Hash[*(File.read(@readme).split(/^(=+ .*)$/)[1..-1])]
|
26
|
+
description = readme[readme.keys.find { |x| x =~ /description/i }]
|
27
|
+
description = description.split(/\n\n+/).find { |x|
|
28
|
+
x.length > 0
|
29
|
+
}.gsub(/^\s*/, '')
|
30
|
+
urls = readme[readme.keys.find { |x| x =~ /#{SPEC.name}/i }]
|
31
|
+
urls = urls.strip.gsub(/\*\s/, '').split(/\n/).map { |s| "* <#{s}>" }
|
32
|
+
File.open("email.#{@language}.txt", "wb") { |file|
|
33
|
+
file.puts(<<-eomail)
|
34
|
+
Subject: [ANN] #{subject}
|
35
|
+
|
36
|
+
#{title}
|
37
|
+
|
38
|
+
#{urls.join("\n")}
|
39
|
+
|
40
|
+
#{description}
|
41
|
+
|
42
|
+
Changes:
|
43
|
+
|
44
|
+
#{File.read(@changelog).split(/^(===.*)/)[1..2].join.strip.gsub(/=/, '#')}
|
45
|
+
|
46
|
+
#{urls.join("\n")}
|
47
|
+
eomail
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
EmailTask.new(:en, 'README.en.rdoc', 'doc/en/NEWS.en.rdoc')
|
55
|
+
EmailTask.new(:ja, 'README.ja.rdoc', 'doc/ja/NEWS.ja.rdoc')
|
data/tasks/file.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
kind = Config::CONFIG['DLEXT']
|
2
|
+
|
3
|
+
EXT = "ext/racc/cparse/cparse.#{kind}"
|
4
|
+
[
|
5
|
+
EXT,
|
6
|
+
'lib/racc/parser-text.rb',
|
7
|
+
'ext/racc/cparse/Makefile',
|
8
|
+
'ext/racc/cparse/*.o',
|
9
|
+
].each { |f| Dir[f].each { |file| CLEAN << file } }
|
10
|
+
|
11
|
+
file 'lib/racc/parser.rb'
|
12
|
+
|
13
|
+
file 'lib/racc/parser-text.rb' => ['lib/racc/parser.rb'] do |t|
|
14
|
+
File.open(t.name, 'wb') { |file|
|
15
|
+
file.write(<<-eorb)
|
16
|
+
module Racc
|
17
|
+
PARSER_TEXT = <<'__end_of_file__'
|
18
|
+
#{File.read(t.prerequisites.first)}
|
19
|
+
__end_of_file__
|
20
|
+
end
|
21
|
+
eorb
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
task 'ext/racc/cparse/Makefile' do
|
26
|
+
Dir.chdir('ext/racc/cparse') do
|
27
|
+
ruby "extconf.rb"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
task EXT => 'ext/racc/cparse/Makefile' do
|
32
|
+
Dir.chdir('ext/racc/cparse') do
|
33
|
+
sh 'make'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
task :build => ['lib/racc/parser-text.rb', EXT]
|
data/tasks/gem.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
SPEC = Gem::Specification.new do |s|
|
2
|
+
s.platform = Gem::Platform::RUBY
|
3
|
+
s.summary = "Racc is a LALR(1) parser generator."
|
4
|
+
s.name = 'racc'
|
5
|
+
s.authors << 'Aoki Minero'
|
6
|
+
s.authors << 'Aaron Patterson'
|
7
|
+
s.email = 'aaronp@rubyforge.org'
|
8
|
+
s.version = Racc::Parser::Racc_Runtime_Version
|
9
|
+
s.require_paths = Dir['{lib,ext}']
|
10
|
+
s.extensions = ['ext/racc/cparse/extconf.rb']
|
11
|
+
s.files = `git ls-files`.split("\n") + ['lib/racc/parser-text.rb']
|
12
|
+
s.homepage = 'http://racc.rubyforge.org/'
|
13
|
+
s.rdoc_options = ['--main', 'README.en.rdoc']
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.rubyforge_project = s.name
|
16
|
+
s.executables = s.files.grep(/^bin/) { |f| File.basename(f) }
|
17
|
+
s.bindir = "bin"
|
18
|
+
s.description = <<EOF
|
19
|
+
Racc is a LALR(1) parser generator.
|
20
|
+
It is written in Ruby itself, and generates Ruby program.
|
21
|
+
EOF
|
22
|
+
end
|
23
|
+
|
24
|
+
namespace :gem do
|
25
|
+
namespace :dev do
|
26
|
+
task :spec => SPEC.files do
|
27
|
+
File.open("#{SPEC.name}.gemspec", 'w') do |f|
|
28
|
+
SPEC.version = "#{SPEC.version}.#{Time.now.strftime("%Y%m%d%H%M%S")}"
|
29
|
+
f.write(SPEC.to_ruby)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Rake::GemPackageTask.new(SPEC) do |pkg|
|
36
|
+
pkg.need_tar = true
|
37
|
+
end
|
data/tasks/test.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
namespace :test do
|
2
|
+
task :multi do
|
3
|
+
sh 'multiruby -S rake clean test'
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
%w[ ext lib ].each do |dir|
|
9
|
+
t.libs << dir
|
10
|
+
end
|
11
|
+
|
12
|
+
t.test_files = FileList['test/test_*.rb']
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
Rake::Task[:test].prerequisites << :build
|
data/test/assets/chk.y
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
#
|
2
|
+
# racc tester
|
3
|
+
#
|
4
|
+
|
5
|
+
class Calcp
|
6
|
+
|
7
|
+
prechigh
|
8
|
+
left '*' '/'
|
9
|
+
left '+' '-'
|
10
|
+
preclow
|
11
|
+
|
12
|
+
convert
|
13
|
+
NUMBER 'Number'
|
14
|
+
end
|
15
|
+
|
16
|
+
rule
|
17
|
+
|
18
|
+
target : exp | /* none */ { result = 0 } ;
|
19
|
+
|
20
|
+
exp : exp '+' exp { result += val[2]; @plus = 'plus' }
|
21
|
+
| exp '-' exp { result -= val[2]; @str = "string test" }
|
22
|
+
| exp '*' exp { result *= val[2] }
|
23
|
+
| exp '/' exp { result /= val[2] }
|
24
|
+
| '(' { $emb = true } exp ')'
|
25
|
+
{
|
26
|
+
raise 'must not happen' unless $emb
|
27
|
+
result = val[2]
|
28
|
+
}
|
29
|
+
| '-' NUMBER { result = -val[1] }
|
30
|
+
| NUMBER
|
31
|
+
;
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
----header
|
36
|
+
|
37
|
+
class Number; end
|
38
|
+
|
39
|
+
----inner
|
40
|
+
|
41
|
+
def parse( src )
|
42
|
+
$emb = false
|
43
|
+
@plus = nil
|
44
|
+
@str = nil
|
45
|
+
@src = src
|
46
|
+
result = do_parse
|
47
|
+
if @plus
|
48
|
+
raise 'string parse failed' unless @plus == 'plus'
|
49
|
+
end
|
50
|
+
if @str
|
51
|
+
raise 'string parse failed' unless @str == 'string test'
|
52
|
+
end
|
53
|
+
result
|
54
|
+
end
|
55
|
+
|
56
|
+
def next_token
|
57
|
+
@src.shift
|
58
|
+
end
|
59
|
+
|
60
|
+
def initialize
|
61
|
+
@yydebug = true
|
62
|
+
end
|
63
|
+
|
64
|
+
----footer
|
65
|
+
|
66
|
+
$parser = Calcp.new
|
67
|
+
$test_number = 1
|
68
|
+
|
69
|
+
def chk( src, ans )
|
70
|
+
result = $parser.parse(src)
|
71
|
+
raise "test #{$test_number} fail" unless result == ans
|
72
|
+
$test_number += 1
|
73
|
+
end
|
74
|
+
|
75
|
+
chk(
|
76
|
+
[ [Number, 9],
|
77
|
+
[false, false],
|
78
|
+
[false, false] ], 9
|
79
|
+
)
|
80
|
+
|
81
|
+
chk(
|
82
|
+
[ [Number, 5],
|
83
|
+
['*', nil],
|
84
|
+
[Number, 1],
|
85
|
+
['-', nil],
|
86
|
+
[Number, 1],
|
87
|
+
['*', nil],
|
88
|
+
[Number, 8],
|
89
|
+
[false, false],
|
90
|
+
[false, false] ], -3
|
91
|
+
)
|
92
|
+
|
93
|
+
chk(
|
94
|
+
[ [Number, 5],
|
95
|
+
['+', nil],
|
96
|
+
[Number, 2],
|
97
|
+
['-', nil],
|
98
|
+
[Number, 5],
|
99
|
+
['+', nil],
|
100
|
+
[Number, 2],
|
101
|
+
['-', nil],
|
102
|
+
[Number, 5],
|
103
|
+
[false, false],
|
104
|
+
[false, false] ], -1
|
105
|
+
)
|
106
|
+
|
107
|
+
chk(
|
108
|
+
[ ['-', nil],
|
109
|
+
[Number, 4],
|
110
|
+
[false, false],
|
111
|
+
[false, false] ], -4
|
112
|
+
)
|
113
|
+
|
114
|
+
chk(
|
115
|
+
[ [Number, 7],
|
116
|
+
['*', nil],
|
117
|
+
['(', nil],
|
118
|
+
[Number, 4],
|
119
|
+
['+', nil],
|
120
|
+
[Number, 3],
|
121
|
+
[')', nil],
|
122
|
+
['-', nil],
|
123
|
+
[Number, 9],
|
124
|
+
[false, false],
|
125
|
+
[false, false] ], 40
|
126
|
+
)
|
data/test/assets/conf.y
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# ? detect digraph bug
|
2
|
+
|
3
|
+
class P
|
4
|
+
token A B C D
|
5
|
+
rule
|
6
|
+
target : a b c d
|
7
|
+
a : A
|
8
|
+
|
|
9
|
+
b : B
|
10
|
+
|
|
11
|
+
c : C
|
12
|
+
|
|
13
|
+
d : D
|
14
|
+
|
|
15
|
+
end
|
16
|
+
|
17
|
+
---- inner
|
18
|
+
|
19
|
+
def parse
|
20
|
+
do_parse
|
21
|
+
end
|
22
|
+
|
23
|
+
def next_token
|
24
|
+
[false, '$']
|
25
|
+
end
|
26
|
+
|
27
|
+
---- footer
|
28
|
+
|
29
|
+
P.new.parse
|
data/test/assets/echk.y
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
#
|
2
|
+
# racc tester
|
3
|
+
#
|
4
|
+
|
5
|
+
class Calcp
|
6
|
+
|
7
|
+
prechigh
|
8
|
+
left '*' '/'
|
9
|
+
left '+' '-'
|
10
|
+
preclow
|
11
|
+
|
12
|
+
convert
|
13
|
+
NUMBER 'Number'
|
14
|
+
end
|
15
|
+
|
16
|
+
rule
|
17
|
+
|
18
|
+
target : exp | /* none */ { result = 0 } ;
|
19
|
+
|
20
|
+
exp : exp '+' exp { result += val[2]; a = 'plus' }
|
21
|
+
| exp '-' exp { result -= val[2]; "string test" }
|
22
|
+
| exp '*' exp { result *= val[2] }
|
23
|
+
| exp '/' exp { result /= val[2] }
|
24
|
+
| '(' { $emb = true } exp ')'
|
25
|
+
{
|
26
|
+
raise 'must not happen' unless $emb
|
27
|
+
result = val[2]
|
28
|
+
}
|
29
|
+
| '-' NUMBER { result = -val[1] }
|
30
|
+
| NUMBER
|
31
|
+
;
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
----header
|
36
|
+
|
37
|
+
class Number ; end
|
38
|
+
|
39
|
+
----inner
|
40
|
+
|
41
|
+
def parse( src )
|
42
|
+
@src = src
|
43
|
+
do_parse
|
44
|
+
end
|
45
|
+
|
46
|
+
def next_token
|
47
|
+
@src.shift
|
48
|
+
end
|
49
|
+
|
50
|
+
def initialize
|
51
|
+
@yydebug = true
|
52
|
+
end
|
53
|
+
|
54
|
+
----footer
|
55
|
+
|
56
|
+
$parser = Calcp.new
|
57
|
+
$tidx = 1
|
58
|
+
|
59
|
+
def chk( src, ans )
|
60
|
+
ret = $parser.parse( src )
|
61
|
+
unless ret == ans then
|
62
|
+
bug! "test #{$tidx} fail"
|
63
|
+
end
|
64
|
+
$tidx += 1
|
65
|
+
end
|
66
|
+
|
67
|
+
chk(
|
68
|
+
[ [Number, 9],
|
69
|
+
[false, false],
|
70
|
+
[false, false] ], 9
|
71
|
+
)
|
72
|
+
|
73
|
+
chk(
|
74
|
+
[ [Number, 5],
|
75
|
+
['*', nil],
|
76
|
+
[Number, 1],
|
77
|
+
['-', nil],
|
78
|
+
[Number, 1],
|
79
|
+
['*', nil],
|
80
|
+
[Number, 8],
|
81
|
+
[false, false],
|
82
|
+
[false, false] ], -3
|
83
|
+
)
|
84
|
+
|
85
|
+
chk(
|
86
|
+
[ [Number, 5],
|
87
|
+
['+', nil],
|
88
|
+
[Number, 2],
|
89
|
+
['-', nil],
|
90
|
+
[Number, 5],
|
91
|
+
['+', nil],
|
92
|
+
[Number, 2],
|
93
|
+
['-', nil],
|
94
|
+
[Number, 5],
|
95
|
+
[false, false],
|
96
|
+
[false, false] ], -1
|
97
|
+
)
|
98
|
+
|
99
|
+
chk(
|
100
|
+
[ ['-', nil],
|
101
|
+
[Number, 4],
|
102
|
+
[false, false],
|
103
|
+
[false, false] ], -4
|
104
|
+
)
|
105
|
+
|
106
|
+
chk(
|
107
|
+
[ [Number, 7],
|
108
|
+
['*', nil],
|
109
|
+
['(', nil],
|
110
|
+
[Number, 4],
|
111
|
+
['+', nil],
|
112
|
+
[Number, 3],
|
113
|
+
[')', nil],
|
114
|
+
['-', nil],
|
115
|
+
[Number, 9],
|
116
|
+
[false, false],
|
117
|
+
[false, false] ], 40
|
118
|
+
)
|