racc 1.4.9-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/.gemtest +0 -0
  2. data/COPYING +515 -0
  3. data/ChangeLog +846 -0
  4. data/DEPENDS +4 -0
  5. data/Manifest.txt +105 -0
  6. data/README.ja.rdoc +96 -0
  7. data/README.rdoc +86 -0
  8. data/Rakefile +51 -0
  9. data/TODO +5 -0
  10. data/bin/racc +308 -0
  11. data/bin/racc2y +195 -0
  12. data/bin/y2racc +339 -0
  13. data/ext/racc/MANIFEST +4 -0
  14. data/ext/racc/cparse.c +824 -0
  15. data/ext/racc/depend +1 -0
  16. data/ext/racc/extconf.rb +5 -0
  17. data/fastcache/extconf.rb +2 -0
  18. data/fastcache/fastcache.c +185 -0
  19. data/lib/racc.rb +6 -0
  20. data/lib/racc/compat.rb +40 -0
  21. data/lib/racc/debugflags.rb +59 -0
  22. data/lib/racc/exception.rb +15 -0
  23. data/lib/racc/grammar.rb +1115 -0
  24. data/lib/racc/grammarfileparser.rb +559 -0
  25. data/lib/racc/info.rb +16 -0
  26. data/lib/racc/iset.rb +91 -0
  27. data/lib/racc/logfilegenerator.rb +211 -0
  28. data/lib/racc/parser-text.rb +479 -0
  29. data/lib/racc/parser.rb +474 -0
  30. data/lib/racc/parserfilegenerator.rb +512 -0
  31. data/lib/racc/pre-setup +13 -0
  32. data/lib/racc/sourcetext.rb +34 -0
  33. data/lib/racc/state.rb +971 -0
  34. data/lib/racc/statetransitiontable.rb +316 -0
  35. data/lib/racc/static.rb +5 -0
  36. data/misc/dist.sh +31 -0
  37. data/rdoc/en/NEWS.en.rdoc +282 -0
  38. data/rdoc/en/command.en.html +78 -0
  39. data/rdoc/en/debug.en.rdoc +20 -0
  40. data/rdoc/en/grammar.en.rdoc +230 -0
  41. data/rdoc/en/index.en.html +10 -0
  42. data/rdoc/en/parser.en.rdoc +74 -0
  43. data/rdoc/en/usage.en.rdoc +83 -0
  44. data/rdoc/ja/NEWS.ja.rdoc +307 -0
  45. data/rdoc/ja/command.ja.html +94 -0
  46. data/rdoc/ja/debug.ja.rdoc +36 -0
  47. data/rdoc/ja/grammar.ja.rdoc +348 -0
  48. data/rdoc/ja/index.ja.html +10 -0
  49. data/rdoc/ja/parser.ja.rdoc +125 -0
  50. data/rdoc/ja/usage.ja.html +414 -0
  51. data/sample/array.y +67 -0
  52. data/sample/array2.y +59 -0
  53. data/sample/calc-ja.y +66 -0
  54. data/sample/calc.y +65 -0
  55. data/sample/conflict.y +15 -0
  56. data/sample/hash.y +60 -0
  57. data/sample/lalr.y +17 -0
  58. data/sample/lists.y +57 -0
  59. data/sample/syntax.y +46 -0
  60. data/sample/yyerr.y +46 -0
  61. data/setup.rb +1587 -0
  62. data/tasks/doc.rb +12 -0
  63. data/tasks/email.rb +55 -0
  64. data/test/assets/chk.y +126 -0
  65. data/test/assets/conf.y +16 -0
  66. data/test/assets/digraph.y +29 -0
  67. data/test/assets/echk.y +118 -0
  68. data/test/assets/err.y +60 -0
  69. data/test/assets/expect.y +7 -0
  70. data/test/assets/firstline.y +4 -0
  71. data/test/assets/ichk.y +102 -0
  72. data/test/assets/intp.y +546 -0
  73. data/test/assets/mailp.y +437 -0
  74. data/test/assets/newsyn.y +25 -0
  75. data/test/assets/noend.y +4 -0
  76. data/test/assets/nonass.y +41 -0
  77. data/test/assets/normal.y +27 -0
  78. data/test/assets/norule.y +4 -0
  79. data/test/assets/nullbug1.y +25 -0
  80. data/test/assets/nullbug2.y +15 -0
  81. data/test/assets/opt.y +123 -0
  82. data/test/assets/percent.y +35 -0
  83. data/test/assets/recv.y +97 -0
  84. data/test/assets/rrconf.y +14 -0
  85. data/test/assets/scan.y +72 -0
  86. data/test/assets/syntax.y +50 -0
  87. data/test/assets/unterm.y +5 -0
  88. data/test/assets/useless.y +12 -0
  89. data/test/assets/yyerr.y +46 -0
  90. data/test/bench.y +36 -0
  91. data/test/helper.rb +91 -0
  92. data/test/infini.y +8 -0
  93. data/test/scandata/brace +7 -0
  94. data/test/scandata/gvar +1 -0
  95. data/test/scandata/normal +4 -0
  96. data/test/scandata/percent +18 -0
  97. data/test/scandata/slash +10 -0
  98. data/test/src.intp +34 -0
  99. data/test/start.y +20 -0
  100. data/test/test_chk_y.rb +51 -0
  101. data/test/test_grammar_file_parser.rb +15 -0
  102. data/test/test_racc_command.rb +155 -0
  103. data/test/test_scan_y.rb +51 -0
  104. data/test/testscanner.rb +51 -0
  105. data/web/racc.en.rhtml +42 -0
  106. data/web/racc.ja.rhtml +51 -0
  107. 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
+ )
@@ -0,0 +1,16 @@
1
+
2
+ class A
3
+ rule
4
+
5
+ a: A c C expr;
6
+
7
+ b: A B; # useless
8
+
9
+ c: A;
10
+ c: A;
11
+
12
+ expr: expr '+' expr
13
+ expr: expr '-' expr
14
+ expr: NUMBER
15
+
16
+ end
@@ -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
@@ -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
@@ -0,0 +1,7 @@
1
+ class E
2
+ expect 1
3
+ rule
4
+ list: inlist inlist
5
+ inlist:
6
+ | A
7
+ end
@@ -0,0 +1,4 @@
1
+ class T
2
+ rule
3
+ a: A B C
4
+ end
@@ -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])