racc 1.4.9-java

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.
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
@@ -0,0 +1,50 @@
1
+ #
2
+ # racc syntax checker
3
+ #
4
+
5
+ class M1::M2::ParserClass < S1::S2::SuperClass
6
+
7
+ token A
8
+ | B C
9
+
10
+ convert
11
+ A '5'
12
+ end
13
+
14
+ prechigh
15
+ left B
16
+ preclow
17
+
18
+ start target
19
+
20
+ expect 0
21
+
22
+ rule
23
+
24
+ target: A B C
25
+ {
26
+ print 'abc'
27
+ }
28
+ | B C A
29
+ | C B A
30
+ {
31
+ print 'cba'
32
+ }
33
+ | cont
34
+
35
+ cont : A c2 B c2 C
36
+
37
+ c2 : C C C C C
38
+
39
+ end
40
+
41
+ ---- inner
42
+
43
+ junk code !!!!
44
+
45
+ kjaljlajrlaolanbla /// %%% (*((( token rule
46
+ akiurtlajluealjflaj @@@@ end end end end __END__
47
+ laieu2o879urkq96ga(Q#*&%Q#
48
+ #&lkji END
49
+
50
+ q395q?/// liutjqlkr7
@@ -0,0 +1,5 @@
1
+ # unterminated action
2
+
3
+ class A
4
+ rule
5
+ a: A {
@@ -0,0 +1,12 @@
1
+
2
+
3
+ class A
4
+ token A B C X
5
+ rule
6
+
7
+ targ : A list B
8
+ | A B C
9
+
10
+ list: list X
11
+
12
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # yyerror/yyerrok/yyaccept test
3
+ #
4
+
5
+ class A
6
+ rule
7
+
8
+ target: a b c
9
+
10
+ a:
11
+ {
12
+ yyerror
13
+ raise ArgumentError, "yyerror failed"
14
+ }
15
+ | error
16
+
17
+ b:
18
+ {
19
+ yyerrok
20
+ }
21
+
22
+ c:
23
+ {
24
+ yyaccept
25
+ raise ArgumentError, "yyaccept failed"
26
+ }
27
+
28
+ end
29
+
30
+ ---- inner
31
+
32
+ def parse
33
+ do_parse
34
+ end
35
+
36
+ def next_token
37
+ [false, '$end']
38
+ end
39
+
40
+ def on_error( *args )
41
+ $stderr.puts "on_error called: args=#{args.inspect}"
42
+ end
43
+
44
+ ---- footer
45
+
46
+ A.new.parse
data/test/bench.y ADDED
@@ -0,0 +1,36 @@
1
+ class BenchmarkParser
2
+
3
+ rule
4
+
5
+ target: a a a a a a a a a a;
6
+ a: b b b b b b b b b b;
7
+ b: c c c c c c c c c c;
8
+ c: d d d d d d d d d d;
9
+ d: e e e e e e e e e e;
10
+
11
+ end
12
+
13
+ ---- inner
14
+
15
+ def initialize
16
+ @old = [ :e, 'e' ]
17
+ @i = 0
18
+ end
19
+
20
+ def next_token
21
+ return [false, '$'] if @i >= 10_0000
22
+ @i += 1
23
+ @old
24
+ end
25
+
26
+ def parse
27
+ do_parse
28
+ end
29
+
30
+ ---- footer
31
+
32
+ require 'benchmark'
33
+
34
+ Benchmark.bm do |x|
35
+ x.report { BenchmarkParser.new.parse }
36
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,91 @@
1
+ $VERBOSE = true
2
+ require 'test/unit'
3
+ require 'racc/static'
4
+ require 'fileutils'
5
+ require 'tempfile'
6
+
7
+ module Racc
8
+ class TestCase < Test::Unit::TestCase
9
+ PROJECT_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..'))
10
+
11
+ TEST_DIR = File.join(PROJECT_DIR, 'test')
12
+
13
+ RACC = File.join(PROJECT_DIR, 'bin', 'racc')
14
+ OUT_DIR = File.join(TEST_DIR, 'out')
15
+ TAB_DIR = File.join(TEST_DIR, 'tab')
16
+ LOG_DIR = File.join(TEST_DIR, 'log')
17
+ ERR_DIR = File.join(TEST_DIR, 'err')
18
+ ASSET_DIR = File.join(TEST_DIR, 'assets')
19
+
20
+ INC = [
21
+ File.join(PROJECT_DIR, 'lib'),
22
+ File.join(PROJECT_DIR, 'ext'),
23
+ ].join(':')
24
+
25
+ unless RUBY_VERSION >= '1.9'
26
+ undef :default_test
27
+ end
28
+
29
+ def setup
30
+ [OUT_DIR, TAB_DIR, LOG_DIR, ERR_DIR].each do |dir|
31
+ FileUtils.mkdir_p(dir)
32
+ end
33
+ end
34
+
35
+ def teardown
36
+ [OUT_DIR, TAB_DIR, LOG_DIR, ERR_DIR].each do |dir|
37
+ FileUtils.rm_rf(dir)
38
+ end
39
+ end
40
+
41
+ def assert_compile asset, args = []
42
+ asset = File.basename(asset, '.y')
43
+ args = ([args].flatten) + [
44
+ "#{ASSET_DIR}/#{asset}.y",
45
+ '-Do',
46
+ "-O#{OUT_DIR}/#{asset}",
47
+ "-o#{TAB_DIR}/#{asset}",
48
+ ]
49
+ racc "#{args.join(' ')}"
50
+ end
51
+
52
+ def assert_debugfile asset, ok
53
+ name = File.basename(asset, '.y')
54
+ Dir.chdir(TEST_DIR) do
55
+ File.foreach("log/#{name}.y") do |line|
56
+ line.strip!
57
+ case line
58
+ when /sr/ then assert_equal "sr#{ok[0]}", line
59
+ when /rr/ then assert_equal "rr#{ok[1]}", line
60
+ when /un/ then assert_equal "un#{ok[2]}", line
61
+ when /ur/ then assert_equal "ur#{ok[3]}", line
62
+ when /ex/ then assert_equal "ex#{ok[4]}", line
63
+ else
64
+ raise TestFailed, 'racc outputs unknown debug report???'
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ def assert_exec file
71
+ file = File.basename(file, '.y')
72
+ Dir.chdir(TEST_DIR) do
73
+ ruby("tab/#{file}")
74
+ end
75
+ end
76
+
77
+ def racc arg
78
+ ruby "-S #{RACC} #{arg}"
79
+ end
80
+
81
+ def ruby arg
82
+ Dir.chdir(TEST_DIR) do
83
+ Tempfile.open 'test' do |io|
84
+ cmd = "#{ENV['_'] || Gem.ruby} -I #{INC} #{arg} 2>#{io.path}"
85
+ result = system(cmd)
86
+ assert(result, io.read)
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
data/test/infini.y ADDED
@@ -0,0 +1,8 @@
1
+
2
+ class I
3
+
4
+ rule
5
+
6
+ list: list X
7
+
8
+ end
@@ -0,0 +1,7 @@
1
+ { {
2
+ } { } {
3
+ { { { } } }
4
+ { { { {} } } }
5
+ {} {} {}
6
+ }
7
+ }
@@ -0,0 +1 @@
1
+ { $' $" $& $-a $/ $\ $( $1 $2 $3 $? $-i }
@@ -0,0 +1,4 @@
1
+ {
2
+ # comment
3
+ result = "string".match(/regexp/)[0]
4
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ 3 % 5 # mod
3
+ 3%5 # mod
4
+ 3% 5 # mod
5
+ i % 5 # mod
6
+ i%5 # mod
7
+ i% 5 # mod
8
+ call %{str} # string
9
+ call(%{str}) # string
10
+ %q{string} # string
11
+ %Q{string} # string
12
+ %r{string} # string
13
+ %w(array) # array
14
+ %x{array} # command string
15
+ %{string} # string
16
+ %_string_ # string
17
+ %/string/ # regexp
18
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ # here's many '/'s
3
+ i = 5/1 # div
4
+ re = /regex/ # regexp
5
+ i /= 5 # div
6
+ result = 5 / 1 # div
7
+ result = 5/ 1 # div
8
+ call(/regex/) # regexp
9
+ call /regex/ # regexp
10
+ }
data/test/src.intp ADDED
@@ -0,0 +1,34 @@
1
+ def assert( no, cond )
2
+ if cond then
3
+ else
4
+ raise( 'assert ' + to_s(no) + ' failed' )
5
+ end
6
+ end
7
+
8
+ assert( 1, concat(concat(concat('str=', 'a'), "b"), 'c') == 'str=abc' )
9
+ assert( 2, 'operator' + ' ok' == 'operator ok' )
10
+ assert( 3, 1 + 1 == 2 )
11
+ assert( 4, 4 * 1 + 10 * 1 == 14 )
12
+
13
+ if true then
14
+ assert( 5, true )
15
+ else
16
+ assert( 6, false )
17
+ end
18
+
19
+ i = 1
20
+ while i == 1 do
21
+ i = false
22
+ end
23
+ assert( 7, i == false )
24
+ assert( 8, nil == nil )
25
+
26
+ def func
27
+ assert( 9, true )
28
+ end
29
+ func
30
+
31
+ def argfunc( str )
32
+ assert( 10, str == 'ok' )
33
+ end
34
+ argfunc 'ok'
data/test/start.y ADDED
@@ -0,0 +1,20 @@
1
+ class S
2
+
3
+ start st
4
+
5
+ rule
6
+
7
+ n: D { result = 'no' }
8
+ st : A B C n { result = 'ok' }
9
+
10
+ end
11
+
12
+ ---- inner
13
+
14
+ def parse
15
+ do_parse
16
+ end
17
+
18
+ ---- footer
19
+
20
+ S.new.parse == 'ok' or raise 'start stmt not worked'
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
2
+
3
+ module Racc
4
+ class TestChkY < TestCase
5
+ def setup
6
+ file = File.join(ASSET_DIR, 'chk.y')
7
+ @debug_flags = Racc::DebugFlags.parse_option_string('o')
8
+ parser = Racc::GrammarFileParser.new(@debug_flags)
9
+ @result = parser.parse(File.read(file), File.basename(file))
10
+ @states = Racc::States.new(@result.grammar).nfa
11
+ @states.dfa
12
+ end
13
+
14
+ def test_compile_chk_y
15
+ generator = Racc::ParserFileGenerator.new(@states, @result.params.dup)
16
+
17
+ # it generates valid ruby
18
+ assert Module.new {
19
+ self.instance_eval(generator.generate_parser, __FILE__, __LINE__)
20
+ }
21
+
22
+ grammar = @states.grammar
23
+
24
+ assert_equal 0, @states.n_srconflicts
25
+ assert_equal 0, @states.n_rrconflicts
26
+ assert_equal 0, grammar.n_useless_nonterminals
27
+ assert_equal 0, grammar.n_useless_rules
28
+ assert_nil grammar.n_expected_srconflicts
29
+ end
30
+
31
+ def test_compile_chk_y_line_convert
32
+ params = @result.params.dup
33
+ params.convert_line_all = true
34
+
35
+ generator = Racc::ParserFileGenerator.new(@states, @result.params.dup)
36
+
37
+ # it generates valid ruby
38
+ assert Module.new {
39
+ self.instance_eval(generator.generate_parser, __FILE__, __LINE__)
40
+ }
41
+
42
+ grammar = @states.grammar
43
+
44
+ assert_equal 0, @states.n_srconflicts
45
+ assert_equal 0, @states.n_rrconflicts
46
+ assert_equal 0, grammar.n_useless_nonterminals
47
+ assert_equal 0, grammar.n_useless_rules
48
+ assert_nil grammar.n_expected_srconflicts
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
2
+
3
+ module Racc
4
+ class TestGrammarFileParser < TestCase
5
+ def test_parse
6
+ file = File.join(ASSET_DIR, 'yyerr.y')
7
+
8
+ debug_flags = Racc::DebugFlags.parse_option_string('o')
9
+ assert debug_flags.status_logging
10
+
11
+ parser = Racc::GrammarFileParser.new(debug_flags)
12
+ parser.parse(File.read(file), File.basename(file))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,155 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
2
+
3
+ module Racc
4
+ class TestRaccCommand < TestCase
5
+ def test_syntax_y
6
+ assert_compile 'syntax.y', '-v'
7
+ assert_debugfile 'syntax.y', [0,0,0,0,0]
8
+ end
9
+
10
+ def test_percent_y
11
+ assert_compile 'percent.y'
12
+ assert_debugfile 'percent.y', []
13
+ assert_exec 'percent.y'
14
+ end
15
+
16
+ def test_scan_y
17
+ assert_compile 'scan.y'
18
+ assert_debugfile 'scan.y', []
19
+ assert_exec 'scan.y'
20
+ end
21
+
22
+ def test_newsyn_y
23
+ assert_compile 'newsyn.y'
24
+ assert_debugfile 'newsyn.y', []
25
+ end
26
+
27
+ def test_normal_y
28
+ assert_compile 'normal.y'
29
+ assert_debugfile 'normal.y', []
30
+
31
+ assert_compile 'normal.y', '-vg'
32
+ assert_debugfile 'normal.y', []
33
+ end
34
+
35
+ def test_chk_y
36
+ assert_compile 'chk.y', '-vg'
37
+ assert_debugfile 'chk.y', []
38
+ assert_exec 'chk.y'
39
+
40
+ assert_compile 'chk.y', '--line-convert-all'
41
+ assert_debugfile 'chk.y', []
42
+ assert_exec 'chk.y'
43
+ end
44
+
45
+ def test_echk_y
46
+ assert_compile 'echk.y', '-E'
47
+ assert_debugfile 'echk.y', []
48
+ assert_exec 'echk.y'
49
+ end
50
+
51
+ def test_err_y
52
+ assert_compile 'err.y'
53
+ assert_debugfile 'err.y', []
54
+ assert_exec 'err.y'
55
+ end
56
+
57
+ def test_mailp_y
58
+ assert_compile 'mailp.y'
59
+ assert_debugfile 'mailp.y', []
60
+ end
61
+
62
+ def test_conf_y
63
+ assert_compile 'conf.y', '-v'
64
+ assert_debugfile 'conf.y', [4,1,1,2]
65
+ end
66
+
67
+ def test_rrconf_y
68
+ assert_compile 'rrconf.y'
69
+ assert_debugfile 'rrconf.y', [1,1,0,0]
70
+ end
71
+
72
+ def test_useless_y
73
+ assert_compile 'useless.y'
74
+ assert_debugfile 'useless.y', [0,0,1,2]
75
+ end
76
+
77
+ def test_opt_y
78
+ assert_compile 'opt.y'
79
+ assert_debugfile 'opt.y', []
80
+ assert_exec 'opt.y'
81
+ end
82
+
83
+ def test_yyerr_y
84
+ assert_compile 'yyerr.y'
85
+ assert_debugfile 'yyerr.y', []
86
+ assert_exec 'yyerr.y'
87
+ end
88
+
89
+ def test_recv_y
90
+ assert_compile 'recv.y'
91
+ assert_debugfile 'recv.y', [5,10,1,4]
92
+ end
93
+
94
+ def test_ichk_y
95
+ assert_compile 'ichk.y'
96
+ assert_debugfile 'ichk.y', []
97
+ assert_exec 'ichk.y'
98
+ end
99
+
100
+ def test_intp_y
101
+ assert_compile 'intp.y'
102
+ assert_debugfile 'intp.y', []
103
+ assert_exec 'intp.y'
104
+ end
105
+
106
+ def test_expect_y
107
+ assert_compile 'expect.y'
108
+ assert_debugfile 'expect.y', [1,0,0,0,1]
109
+ end
110
+
111
+ def test_nullbug1_y
112
+ assert_compile 'nullbug1.y'
113
+ assert_debugfile 'nullbug1.y', [0,0,0,0]
114
+ end
115
+
116
+ def test_nullbug2_y
117
+ assert_compile 'nullbug2.y'
118
+ assert_debugfile 'nullbug2.y', [0,0,0,0]
119
+ end
120
+
121
+ def test_firstline_y
122
+ assert_compile 'firstline.y'
123
+ assert_debugfile 'firstline.y', []
124
+ end
125
+
126
+ def test_nonass_y
127
+ assert_compile 'nonass.y'
128
+ assert_debugfile 'nonass.y', []
129
+ assert_exec 'nonass.y'
130
+ end
131
+
132
+ def test_digraph_y
133
+ assert_compile 'digraph.y'
134
+ assert_debugfile 'digraph.y', []
135
+ assert_exec 'digraph.y'
136
+ end
137
+
138
+ def test_noend_y
139
+ assert_compile 'noend.y'
140
+ assert_debugfile 'noend.y', []
141
+ end
142
+
143
+ def test_norule_y
144
+ assert_raises(MiniTest::Assertion) {
145
+ assert_compile 'norule.y'
146
+ }
147
+ end
148
+
149
+ def test_unterm_y
150
+ assert_raises(MiniTest::Assertion) {
151
+ assert_compile 'unterm.y'
152
+ }
153
+ end
154
+ end
155
+ end