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/sample/array.y ADDED
@@ -0,0 +1,67 @@
1
+ # $Id$
2
+ #
3
+ # convert Array-like string into Ruby's Array.
4
+
5
+ class ArrayParser
6
+
7
+ rule
8
+
9
+ array : '[' contents ']'
10
+ {
11
+ result = val[1]
12
+ }
13
+ | '[' ']'
14
+ {
15
+ result = []
16
+ }
17
+
18
+ contents: ITEM
19
+ {
20
+ result = val
21
+ }
22
+ | contents ',' ITEM
23
+ {
24
+ result.push val[2]
25
+ }
26
+
27
+ ---- inner
28
+
29
+ def parse(str)
30
+ str = str.strip
31
+ @q = []
32
+ until str.empty?
33
+ case str
34
+ when /\A\s+/
35
+ str = $'
36
+ when /\A\w+/
37
+ @q.push [:ITEM, $&]
38
+ str = $'
39
+ else
40
+ c = str[0,1]
41
+ @q.push [c, c]
42
+ str = str[1..-1]
43
+ end
44
+ end
45
+ @q.push [false, '$'] # is optional from Racc 1.3.7
46
+ do_parse
47
+ end
48
+
49
+ def next_token
50
+ @q.shift
51
+ end
52
+
53
+ ---- footer
54
+
55
+ if $0 == __FILE__
56
+ src = <<EOS
57
+ [
58
+ a, b, c,
59
+ d,
60
+ e ]
61
+ EOS
62
+ puts 'parsing:'
63
+ print src
64
+ puts
65
+ puts 'result:'
66
+ p ArrayParser.new.parse(src)
67
+ end
data/sample/array2.y ADDED
@@ -0,0 +1,59 @@
1
+ # $Id$
2
+ #
3
+ # Converting Array-like string into Ruby's Array, version 2.
4
+ # This grammer uses no_result_var.
5
+
6
+ class ArrayParser2
7
+ options no_result_var
8
+ rule
9
+ array : '[' contents ']' { val[1] }
10
+ | '[' ']' { [] }
11
+
12
+ contents: ITEM { val }
13
+ | contents ',' ITEM { val[0].push val[2]; val[0] }
14
+ end
15
+
16
+ ---- inner
17
+
18
+ def parse(str)
19
+ @str = str
20
+ yyparse self, :scan
21
+ end
22
+
23
+ def scan
24
+ str = @str.strip
25
+ until str.empty?
26
+ case str
27
+ when /\A\s+/
28
+ str = $'
29
+ when /\A\w+/
30
+ yield :ITEM, $&
31
+ str = $'
32
+ else
33
+ c = str[0,1]
34
+ yield c, c
35
+ str = str[1..-1]
36
+ end
37
+ end
38
+ yield false, '$' # is optional from Racc 1.3.7
39
+ end
40
+
41
+ def next_token
42
+ @q.shift
43
+ end
44
+
45
+ ---- footer
46
+
47
+ if $0 == __FILE__
48
+ src = <<EOS
49
+ [
50
+ a, b, c,
51
+ d,
52
+ e ]
53
+ EOS
54
+ puts 'parsing:'
55
+ print src
56
+ puts
57
+ puts 'result:'
58
+ p ArrayParser2.new.parse(src)
59
+ end
data/sample/calc-ja.y ADDED
@@ -0,0 +1,66 @@
1
+ # $Id$
2
+ #
3
+ # A simple calculator, version 2.
4
+ # This file contains Japanese characters (encoding=EUC-JP).
5
+
6
+ class Calculator2
7
+ prechigh
8
+ nonassoc UMINUS
9
+ left '*' '/'
10
+ left '+' '-'
11
+ preclow
12
+ options no_result_var
13
+ rule
14
+ target : exp
15
+ | /* none */ { 0 }
16
+
17
+ exp : exp '+' exp { val[0] + val[2] }
18
+ | exp '-' exp { val[0] - val[2] }
19
+ | exp '*' exp { val[0] * val[2] }
20
+ | exp '/' exp { val[0] / val[2] }
21
+ | '(' exp ')' { val[1] }
22
+ | '-' NUMBER =UMINUS { -(val[1]) }
23
+ | NUMBER
24
+ end
25
+
26
+ ---- header
27
+ # $Id$
28
+ ---- inner
29
+
30
+ def evaluate(str)
31
+ @tokens = []
32
+ until str.empty?
33
+ case str
34
+ when /\A\s+/
35
+ ;
36
+ when /\A\d+/
37
+ @tokens.push [:NUMBER, $&.to_i]
38
+ when /\A.|\n/
39
+ s = $&
40
+ @tokens.push [s, s]
41
+ end
42
+ str = $'
43
+ end
44
+ @tokens.push [false, '$']
45
+ do_parse
46
+ end
47
+
48
+ def next_token
49
+ @tokens.shift
50
+ end
51
+
52
+ ---- footer
53
+
54
+ puts 'Ķ������� 2 �浡'
55
+ puts 'Q �ǽ�λ���ޤ�'
56
+ calc = Calculator2.new
57
+ while true
58
+ print '>>> '; $stdout.flush
59
+ str = $stdin.gets.strip
60
+ break if /q/i =~ str
61
+ begin
62
+ p calc.evaluate(str)
63
+ rescue ParseError
64
+ puts 'parse error'
65
+ end
66
+ end
data/sample/calc.y ADDED
@@ -0,0 +1,65 @@
1
+ # $Id$
2
+ #
3
+ # Very simple calculater.
4
+
5
+ class Calcp
6
+ prechigh
7
+ nonassoc UMINUS
8
+ left '*' '/'
9
+ left '+' '-'
10
+ preclow
11
+ rule
12
+ target: exp
13
+ | /* none */ { result = 0 }
14
+
15
+ exp: exp '+' exp { result += val[2] }
16
+ | exp '-' exp { result -= val[2] }
17
+ | exp '*' exp { result *= val[2] }
18
+ | exp '/' exp { result /= val[2] }
19
+ | '(' exp ')' { result = val[1] }
20
+ | '-' NUMBER =UMINUS { result = -val[1] }
21
+ | NUMBER
22
+ end
23
+
24
+ ---- header
25
+ # $Id$
26
+ ---- inner
27
+
28
+ def parse(str)
29
+ @q = []
30
+ until str.empty?
31
+ case str
32
+ when /\A\s+/
33
+ when /\A\d+/
34
+ @q.push [:NUMBER, $&.to_i]
35
+ when /\A.|\n/o
36
+ s = $&
37
+ @q.push [s, s]
38
+ end
39
+ str = $'
40
+ end
41
+ @q.push [false, '$end']
42
+ do_parse
43
+ end
44
+
45
+ def next_token
46
+ @q.shift
47
+ end
48
+
49
+ ---- footer
50
+
51
+ parser = Calcp.new
52
+ puts
53
+ puts 'type "Q" to quit.'
54
+ puts
55
+ while true
56
+ puts
57
+ print '? '
58
+ str = gets.chop!
59
+ break if /q/i =~ str
60
+ begin
61
+ puts "= #{parser.parse(str)}"
62
+ rescue ParseError
63
+ puts $!
64
+ end
65
+ end
data/sample/conflict.y ADDED
@@ -0,0 +1,15 @@
1
+ # $Id$
2
+ #
3
+ # Example of conflicted grammer.
4
+ # This grammer contains 1 Shift/Reduce conflict and 1 Reduce/Reduce conflict.
5
+
6
+ class A
7
+ rule
8
+ target : outer
9
+
10
+ outer :
11
+ | outer inner
12
+
13
+ inner :
14
+ | inner ITEM
15
+ end
data/sample/hash.y ADDED
@@ -0,0 +1,60 @@
1
+ # $Id$
2
+ #
3
+ # Converting Hash-like string into Ruby's Hash.
4
+
5
+ class HashParser
6
+ options no_result_var
7
+ rule
8
+ hash : '{' contents '}' { val[1] }
9
+ | '{' '}' { Hash.new }
10
+
11
+ # Racc can handle string over 2 bytes.
12
+ contents: IDENT '=>' IDENT { {val[0] => val[2]} }
13
+ | contents ',' IDENT '=>' IDENT { val[0][val[2]] = val[4]; val[0] }
14
+ end
15
+
16
+ ---- inner
17
+
18
+ def parse(str)
19
+ @str = str
20
+ yyparse self, :scan
21
+ end
22
+
23
+ private
24
+
25
+ def scan
26
+ str = @str
27
+ until str.empty?
28
+ case str
29
+ when /\A\s+/
30
+ str = $'
31
+ when /\A\w+/
32
+ yield :IDENT, $&
33
+ str = $'
34
+ when /\A=>/
35
+ yield '=>', '=>'
36
+ str = $'
37
+ else
38
+ c = str[0,1]
39
+ yield c, c
40
+ str = str[1..-1]
41
+ end
42
+ end
43
+ yield false, '$' # is optional from Racc 1.3.7
44
+ end
45
+
46
+ ---- footer
47
+
48
+ if $0 == __FILE__
49
+ src = <<EOS
50
+ {
51
+ name => MyName,
52
+ id => MyIdent
53
+ }
54
+ EOS
55
+ puts 'Parsing (String):'
56
+ print src
57
+ puts
58
+ puts 'Result (Ruby Object):'
59
+ p HashParser.new.parse(src)
60
+ end
data/sample/lalr.y ADDED
@@ -0,0 +1,17 @@
1
+ # $Id$
2
+ #
3
+ # This is LALR grammer, and not LL/SLR.
4
+
5
+ class A
6
+ rule
7
+ A : L '=' E
8
+
9
+ L : i
10
+ | R '^' i
11
+
12
+ E : E '+' R
13
+ | R
14
+ | '@' L
15
+
16
+ R : i
17
+ end
data/sample/lists.y ADDED
@@ -0,0 +1,57 @@
1
+ # $Id$
2
+ #
3
+ # Rules for verious lists.
4
+ # This file is just an example, you cannot compile this file.
5
+
6
+ class ExampleOnly
7
+ rule
8
+
9
+ # a list, which minimum number of items is 0
10
+ list0 :
11
+ {
12
+ result = []
13
+ }
14
+ | list0 item
15
+ {
16
+ result.push val[1]
17
+ }
18
+
19
+ # a list, which minimum number of items is 1
20
+ list1 : item
21
+ {
22
+ result = val
23
+ }
24
+ | list1 item
25
+ {
26
+ result.push val[1]
27
+ }
28
+
29
+ # a list, separated by comma
30
+ clist : item
31
+ {
32
+ result = val
33
+ }
34
+ | clist ',' item
35
+ {
36
+ result.push val[2]
37
+ }
38
+
39
+ # a hash. see also "hash.y".
40
+ hash : '{' hash_contents '}'
41
+ {
42
+ result = val[1]
43
+ }
44
+ | '{' '}'
45
+ {
46
+ result = {}
47
+ }
48
+
49
+ hash_contents
50
+ : item "=>" item
51
+ {
52
+ result = { val[0] => val[2] }
53
+ }
54
+ | hash_contents ',' item "=>" item
55
+ {
56
+ result[val[2]] = val[4]
57
+ }
data/sample/syntax.y ADDED
@@ -0,0 +1,46 @@
1
+ # $Id$
2
+ #
3
+ # Racc syntax checker. This grammer file generates
4
+ # invalid ruby program, you cannot run this parser.
5
+
6
+ class P
7
+ token A B C
8
+
9
+ convert
10
+ A '5'
11
+ end
12
+
13
+ prechigh
14
+ left B
15
+ preclow
16
+
17
+ options omit_action_call
18
+
19
+ start target
20
+ rule
21
+ target: A B C
22
+ {
23
+ print 'abc'
24
+ }
25
+ | B C A
26
+ | C B A
27
+ {
28
+ print 'cba'
29
+ }
30
+ | cont
31
+
32
+ cont : A c2 B c2 C
33
+
34
+ c2 : C C C C C
35
+ end
36
+
37
+ ---- inner
38
+
39
+ junk code !!!!
40
+
41
+ kjaljlajrlaolanbla /// %%% (*((( token rule
42
+ akiurtlajluealjflaj @@@@ end end end end __END__
43
+ laieu2o879urkq96ga(Q#*&%Q#
44
+ #&lkji END
45
+
46
+ q395q?/// liutjqlkr7