racc 1.4.9-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/COPYING +515 -0
- data/ChangeLog +846 -0
- data/DEPENDS +4 -0
- data/Manifest.txt +105 -0
- data/README.ja.rdoc +96 -0
- data/README.rdoc +86 -0
- data/Rakefile +51 -0
- data/TODO +5 -0
- data/bin/racc +308 -0
- data/bin/racc2y +195 -0
- data/bin/y2racc +339 -0
- data/ext/racc/MANIFEST +4 -0
- data/ext/racc/cparse.c +824 -0
- data/ext/racc/depend +1 -0
- data/ext/racc/extconf.rb +5 -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 +211 -0
- data/lib/racc/parser-text.rb +479 -0
- data/lib/racc/parser.rb +474 -0
- data/lib/racc/parserfilegenerator.rb +512 -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/rdoc/en/NEWS.en.rdoc +282 -0
- data/rdoc/en/command.en.html +78 -0
- data/rdoc/en/debug.en.rdoc +20 -0
- data/rdoc/en/grammar.en.rdoc +230 -0
- data/rdoc/en/index.en.html +10 -0
- data/rdoc/en/parser.en.rdoc +74 -0
- data/rdoc/en/usage.en.rdoc +83 -0
- data/rdoc/ja/NEWS.ja.rdoc +307 -0
- data/rdoc/ja/command.ja.html +94 -0
- data/rdoc/ja/debug.ja.rdoc +36 -0
- data/rdoc/ja/grammar.ja.rdoc +348 -0
- data/rdoc/ja/index.ja.html +10 -0
- data/rdoc/ja/parser.ja.rdoc +125 -0
- data/rdoc/ja/usage.ja.html +414 -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/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 +91 -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 +233 -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/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
|
+
)
|
data/test/assets/err.y
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
|
2
|
+
class ErrTestp
|
3
|
+
|
4
|
+
rule
|
5
|
+
|
6
|
+
target: lines
|
7
|
+
;
|
8
|
+
|
9
|
+
lines: line
|
10
|
+
| lines line
|
11
|
+
;
|
12
|
+
|
13
|
+
line: A B C D E
|
14
|
+
| error E
|
15
|
+
;
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
---- inner
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@yydebug = false
|
23
|
+
@q = [
|
24
|
+
[:A, 'a'],
|
25
|
+
# [:B, 'b'],
|
26
|
+
[:C, 'c'],
|
27
|
+
[:D, 'd'],
|
28
|
+
[:E, 'e'],
|
29
|
+
|
30
|
+
[:A, 'a'],
|
31
|
+
[:B, 'b'],
|
32
|
+
[:C, 'c'],
|
33
|
+
[:D, 'd'],
|
34
|
+
[:E, 'e'],
|
35
|
+
|
36
|
+
[:A, 'a'],
|
37
|
+
[:B, 'b'],
|
38
|
+
# [:C, 'c'],
|
39
|
+
[:D, 'd'],
|
40
|
+
[:E, 'e'],
|
41
|
+
[false, nil]
|
42
|
+
]
|
43
|
+
end
|
44
|
+
|
45
|
+
def next_token
|
46
|
+
@q.shift
|
47
|
+
end
|
48
|
+
|
49
|
+
def on_error( t, val, values )
|
50
|
+
$stderr.puts "error on token '#{val}'(#{t})"
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse
|
54
|
+
do_parse
|
55
|
+
end
|
56
|
+
|
57
|
+
---- footer
|
58
|
+
|
59
|
+
p = ErrTestp.new
|
60
|
+
p.parse
|
data/test/assets/ichk.y
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
class Calculator
|
2
|
+
|
3
|
+
prechigh
|
4
|
+
left '*' '/'
|
5
|
+
left '+' '-'
|
6
|
+
preclow
|
7
|
+
|
8
|
+
convert
|
9
|
+
NUMBER 'Number'
|
10
|
+
end
|
11
|
+
|
12
|
+
rule
|
13
|
+
|
14
|
+
target : exp
|
15
|
+
| /* none */ { result = 0 }
|
16
|
+
|
17
|
+
exp : exp '+' exp { result += val[2]; a = 'plus' }
|
18
|
+
| exp '-' exp { result -= val[2]; a = "string test" }
|
19
|
+
| exp '*' exp { result *= val[2] }
|
20
|
+
| exp '/' exp { result /= val[2] }
|
21
|
+
| '(' { $emb = true } exp ')'
|
22
|
+
{
|
23
|
+
raise 'must not happen' unless $emb
|
24
|
+
result = val[2]
|
25
|
+
}
|
26
|
+
| '-' NUMBER { result = -val[1] }
|
27
|
+
| NUMBER
|
28
|
+
|
29
|
+
----header
|
30
|
+
|
31
|
+
class Number
|
32
|
+
end
|
33
|
+
|
34
|
+
----inner
|
35
|
+
|
36
|
+
def initialize
|
37
|
+
@racc_debug_out = $stdout
|
38
|
+
@yydebug = false
|
39
|
+
end
|
40
|
+
|
41
|
+
def validate(expected, src)
|
42
|
+
result = parse(src)
|
43
|
+
unless result == expected
|
44
|
+
raise "test #{@test_number} fail"
|
45
|
+
end
|
46
|
+
@test_number += 1
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse(src)
|
50
|
+
@src = src
|
51
|
+
@test_number = 1
|
52
|
+
yyparse self, :scan
|
53
|
+
end
|
54
|
+
|
55
|
+
def scan(&block)
|
56
|
+
@src.each(&block)
|
57
|
+
end
|
58
|
+
|
59
|
+
----footer
|
60
|
+
|
61
|
+
calc = Calculator.new
|
62
|
+
|
63
|
+
calc.validate(9, [[Number, 9], nil])
|
64
|
+
|
65
|
+
calc.validate(-3,
|
66
|
+
[[Number, 5],
|
67
|
+
['*', '*'],
|
68
|
+
[Number, 1],
|
69
|
+
['-', '*'],
|
70
|
+
[Number, 1],
|
71
|
+
['*', '*'],
|
72
|
+
[Number, 8],
|
73
|
+
nil])
|
74
|
+
|
75
|
+
calc.validate(-1,
|
76
|
+
[[Number, 5],
|
77
|
+
['+', '+'],
|
78
|
+
[Number, 2],
|
79
|
+
['-', '-'],
|
80
|
+
[Number, 5],
|
81
|
+
['+', '+'],
|
82
|
+
[Number, 2],
|
83
|
+
['-', '-'],
|
84
|
+
[Number, 5],
|
85
|
+
nil])
|
86
|
+
|
87
|
+
calc.validate(-4,
|
88
|
+
[['-', 'UMINUS'],
|
89
|
+
[Number, 4],
|
90
|
+
nil])
|
91
|
+
|
92
|
+
calc.validate(40,
|
93
|
+
[[Number, 7],
|
94
|
+
['*', '*'],
|
95
|
+
['(', '('],
|
96
|
+
[Number, 4],
|
97
|
+
['+', '+'],
|
98
|
+
[Number, 3],
|
99
|
+
[')', ')'],
|
100
|
+
['-', '-'],
|
101
|
+
[Number, 9],
|
102
|
+
nil])
|