racc 1.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/.gitattributes +2 -0
  2. data/.gitignore +7 -0
  3. data/COPYING +515 -0
  4. data/ChangeLog +846 -0
  5. data/DEPENDS +4 -0
  6. data/README.en.rdoc +86 -0
  7. data/README.ja.rdoc +96 -0
  8. data/Rakefile +15 -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/doc/en/NEWS.en.rdoc +282 -0
  14. data/doc/en/command.en.html +78 -0
  15. data/doc/en/debug.en.rdoc +20 -0
  16. data/doc/en/grammar.en.rdoc +230 -0
  17. data/doc/en/index.en.html +10 -0
  18. data/doc/en/parser.en.rdoc +74 -0
  19. data/doc/en/usage.en.html +92 -0
  20. data/doc/ja/NEWS.ja.rdoc +307 -0
  21. data/doc/ja/command.ja.html +94 -0
  22. data/doc/ja/debug.ja.rdoc +36 -0
  23. data/doc/ja/grammar.ja.rdoc +348 -0
  24. data/doc/ja/index.ja.html +10 -0
  25. data/doc/ja/parser.ja.rdoc +125 -0
  26. data/doc/ja/usage.ja.html +414 -0
  27. data/ext/racc/cparse/MANIFEST +4 -0
  28. data/ext/racc/cparse/cparse.c +824 -0
  29. data/ext/racc/cparse/depend +1 -0
  30. data/ext/racc/cparse/extconf.rb +7 -0
  31. data/fastcache/extconf.rb +2 -0
  32. data/fastcache/fastcache.c +185 -0
  33. data/lib/racc.rb +6 -0
  34. data/lib/racc/compat.rb +40 -0
  35. data/lib/racc/debugflags.rb +59 -0
  36. data/lib/racc/exception.rb +15 -0
  37. data/lib/racc/grammar.rb +1115 -0
  38. data/lib/racc/grammarfileparser.rb +559 -0
  39. data/lib/racc/info.rb +16 -0
  40. data/lib/racc/iset.rb +91 -0
  41. data/lib/racc/logfilegenerator.rb +214 -0
  42. data/lib/racc/parser.rb +439 -0
  43. data/lib/racc/parserfilegenerator.rb +511 -0
  44. data/lib/racc/pre-setup +13 -0
  45. data/lib/racc/sourcetext.rb +34 -0
  46. data/lib/racc/state.rb +971 -0
  47. data/lib/racc/statetransitiontable.rb +316 -0
  48. data/lib/racc/static.rb +5 -0
  49. data/misc/dist.sh +31 -0
  50. data/sample/array.y +67 -0
  51. data/sample/array2.y +59 -0
  52. data/sample/calc-ja.y +66 -0
  53. data/sample/calc.y +65 -0
  54. data/sample/conflict.y +15 -0
  55. data/sample/hash.y +60 -0
  56. data/sample/lalr.y +17 -0
  57. data/sample/lists.y +57 -0
  58. data/sample/syntax.y +46 -0
  59. data/sample/yyerr.y +46 -0
  60. data/setup.rb +1587 -0
  61. data/tasks/doc.rb +12 -0
  62. data/tasks/email.rb +55 -0
  63. data/tasks/file.rb +37 -0
  64. data/tasks/gem.rb +37 -0
  65. data/tasks/test.rb +16 -0
  66. data/test/assets/chk.y +126 -0
  67. data/test/assets/conf.y +16 -0
  68. data/test/assets/digraph.y +29 -0
  69. data/test/assets/echk.y +118 -0
  70. data/test/assets/err.y +60 -0
  71. data/test/assets/expect.y +7 -0
  72. data/test/assets/firstline.y +4 -0
  73. data/test/assets/ichk.y +102 -0
  74. data/test/assets/intp.y +546 -0
  75. data/test/assets/mailp.y +437 -0
  76. data/test/assets/newsyn.y +25 -0
  77. data/test/assets/noend.y +4 -0
  78. data/test/assets/nonass.y +41 -0
  79. data/test/assets/normal.y +27 -0
  80. data/test/assets/norule.y +4 -0
  81. data/test/assets/nullbug1.y +25 -0
  82. data/test/assets/nullbug2.y +15 -0
  83. data/test/assets/opt.y +123 -0
  84. data/test/assets/percent.y +35 -0
  85. data/test/assets/recv.y +97 -0
  86. data/test/assets/rrconf.y +14 -0
  87. data/test/assets/scan.y +72 -0
  88. data/test/assets/syntax.y +50 -0
  89. data/test/assets/unterm.y +5 -0
  90. data/test/assets/useless.y +12 -0
  91. data/test/assets/yyerr.y +46 -0
  92. data/test/bench.y +36 -0
  93. data/test/helper.rb +88 -0
  94. data/test/infini.y +8 -0
  95. data/test/scandata/brace +7 -0
  96. data/test/scandata/gvar +1 -0
  97. data/test/scandata/normal +4 -0
  98. data/test/scandata/percent +18 -0
  99. data/test/scandata/slash +10 -0
  100. data/test/src.intp +34 -0
  101. data/test/start.y +20 -0
  102. data/test/test_chk_y.rb +51 -0
  103. data/test/test_grammar_file_parser.rb +15 -0
  104. data/test/test_racc_command.rb +155 -0
  105. data/test/test_scan_y.rb +51 -0
  106. data/test/testscanner.rb +51 -0
  107. data/web/racc.en.rhtml +42 -0
  108. data/web/racc.ja.rhtml +51 -0
  109. metadata +166 -0
@@ -0,0 +1,4 @@
1
+ class MyParser
2
+ rule
3
+ input: A B C
4
+ end
@@ -0,0 +1,41 @@
1
+ #
2
+ # nonassoc test
3
+ #
4
+
5
+ class P
6
+
7
+ preclow
8
+ nonassoc N
9
+ left P
10
+ prechigh
11
+
12
+ rule
13
+
14
+ target : exp
15
+ exp : exp N exp
16
+ | exp P exp
17
+ | T
18
+
19
+ end
20
+
21
+ ---- inner
22
+
23
+ def parse
24
+ @src = [[:T,'T'], [:N,'N'], [:T,'T'], [:N,'N'], [:T,'T']]
25
+ do_parse
26
+ end
27
+
28
+ def next_token
29
+ @src.shift
30
+ end
31
+
32
+ ---- footer
33
+
34
+ begin
35
+ P.new.parse
36
+ rescue ParseError
37
+ exit 0
38
+ else
39
+ $stderr.puts 'parse error not raised: nonassoc not work'
40
+ exit 1
41
+ end
@@ -0,0 +1,27 @@
1
+
2
+ class Testp
3
+
4
+ convert
5
+ A '2'
6
+ B '3'
7
+ end
8
+
9
+ prechigh
10
+ left B
11
+ preclow
12
+
13
+ rule
14
+
15
+ /* comment */
16
+ target: A B C nonterminal { action "string" == /regexp/o
17
+ 1 /= 3 }
18
+ ; # comment
19
+
20
+ nonterminal: A '+' B = A;
21
+
22
+ /* end */
23
+ end
24
+
25
+ ---- driver
26
+
27
+ # driver is old name
@@ -0,0 +1,4 @@
1
+
2
+ class A
3
+ rule
4
+ end
@@ -0,0 +1,25 @@
1
+ #
2
+ # number of conflicts must be ZERO.
3
+ #
4
+
5
+ class T
6
+
7
+ rule
8
+
9
+ targ : dummy
10
+ | a b c
11
+
12
+ dummy : V v
13
+
14
+ V : E e
15
+ | F f
16
+ |
17
+ ;
18
+
19
+ E :
20
+ ;
21
+
22
+ F :
23
+ ;
24
+
25
+ end
@@ -0,0 +1,15 @@
1
+ #
2
+ # number of conflicts must be ZERO.
3
+ #
4
+
5
+ class A
6
+ rule
7
+ targ: operation voidhead
8
+ | variable
9
+
10
+ voidhead : void B
11
+ void:
12
+
13
+ operation: A
14
+ variable : A
15
+ end
@@ -0,0 +1,123 @@
1
+ #
2
+ # check options working
3
+ #
4
+
5
+ class Calcp
6
+
7
+ prechigh
8
+ left '*' '/'
9
+ left '+' '-'
10
+ preclow
11
+
12
+ convert
13
+ NUMBER 'Number'
14
+ end
15
+
16
+ options no_omit_action_call no_result_var
17
+
18
+ rule
19
+
20
+ target : exp | /* none */ { 0 } ;
21
+
22
+ exp : exp '+' exp { chk(val[0] + val[2]) }
23
+ | exp '-' exp { chk(val[0] - val[2]) }
24
+ | exp '*' exp { chk(val[0] * val[2]) }
25
+ | exp '/' exp { chk(val[0] / val[2]) }
26
+ | '(' { $emb = true } exp ')'
27
+ {
28
+ raise 'must not happen' unless $emb
29
+ val[2]
30
+ }
31
+ | '-' NUMBER { -val[1] }
32
+ | NUMBER
33
+ ;
34
+
35
+ end
36
+
37
+ ----header
38
+
39
+ class Number; end
40
+
41
+ ----inner
42
+
43
+ def parse( src )
44
+ @src = src
45
+ do_parse
46
+ end
47
+
48
+ def next_token
49
+ @src.shift
50
+ end
51
+
52
+ def initialize
53
+ @yydebug = true
54
+ end
55
+
56
+ def chk( i )
57
+ # p i
58
+ i
59
+ end
60
+
61
+ ----footer
62
+
63
+ $parser = Calcp.new
64
+ $test_number = 1
65
+
66
+ def chk( src, ans )
67
+ result = $parser.parse(src)
68
+ raise "test #{$test_number} failed" unless result == ans
69
+ $test_number += 1
70
+ end
71
+
72
+ chk(
73
+ [ [Number, 9],
74
+ [false, false],
75
+ [false, false] ], 9
76
+ )
77
+
78
+ chk(
79
+ [ [Number, 5],
80
+ ['*', nil],
81
+ [Number, 1],
82
+ ['-', nil],
83
+ [Number, 1],
84
+ ['*', nil],
85
+ [Number, 8],
86
+ [false, false],
87
+ [false, false] ], -3
88
+ )
89
+
90
+ chk(
91
+ [ [Number, 5],
92
+ ['+', nil],
93
+ [Number, 2],
94
+ ['-', nil],
95
+ [Number, 5],
96
+ ['+', nil],
97
+ [Number, 2],
98
+ ['-', nil],
99
+ [Number, 5],
100
+ [false, false],
101
+ [false, false] ], -1
102
+ )
103
+
104
+ chk(
105
+ [ ['-', nil],
106
+ [Number, 4],
107
+ [false, false],
108
+ [false, false] ], -4
109
+ )
110
+
111
+ chk(
112
+ [ [Number, 7],
113
+ ['*', nil],
114
+ ['(', nil],
115
+ [Number, 4],
116
+ ['+', nil],
117
+ [Number, 3],
118
+ [')', nil],
119
+ ['-', nil],
120
+ [Number, 9],
121
+ [false, false],
122
+ [false, false] ], 40
123
+ )
@@ -0,0 +1,35 @@
1
+ class ScannerChecker
2
+ rule
3
+ target: A
4
+ {
5
+ i = 7
6
+ i %= 4
7
+ raise 'assert failed' unless i == 3
8
+ tmp = %-This is percent string.-
9
+ raise 'assert failed' unless tmp == 'This is percent string.'
10
+ a = 5; b = 3
11
+ assert_equal(2,(a%b)) #A
12
+ # assert_equal(2,(a %b)) # is %-string
13
+ assert_equal(2,(a% b)) #B
14
+ assert_equal(2,(a % b)) #C
15
+ }
16
+ end
17
+
18
+ ---- inner ----
19
+
20
+ def parse
21
+ @q = [[:A, 'A'], [false, '$']]
22
+ do_parse
23
+ end
24
+
25
+ def next_token
26
+ @q.shift
27
+ end
28
+
29
+ def assert_equal( expect, real )
30
+ raise "expect #{expect.inspect} but #{real.inspect}" unless expect == real
31
+ end
32
+
33
+ ---- footer ----
34
+
35
+ parser = ScannerChecker.new.parse
@@ -0,0 +1,97 @@
1
+ # s/r 5, r/r 10
2
+ class A
3
+ rule
4
+
5
+ content: RecvH received
6
+ ;
7
+
8
+ datetime: day
9
+ ;
10
+
11
+ msgid: '<' spec '>';
12
+
13
+ day:
14
+ | ATOM ','
15
+ ;
16
+
17
+ received: recvitem_list recvdatetime
18
+ ;
19
+
20
+ recvitem_list:
21
+ | recvitem_list recvitem
22
+ ;
23
+
24
+ recvitem: by | via | with | for ;
25
+
26
+ by:
27
+ | BY domain
28
+ ;
29
+
30
+ via:
31
+ | VIA ATOM
32
+ ;
33
+
34
+ with: WITH ATOM
35
+ ;
36
+
37
+ for:
38
+ | FOR addr
39
+ ;
40
+
41
+ recvdatetime:
42
+ | ';' datetime
43
+ ;
44
+
45
+ addr: mbox | group ;
46
+
47
+ mboxes: mbox
48
+ | mboxes ',' mbox
49
+ ;
50
+
51
+ mbox: spec
52
+ | routeaddr
53
+ | phrase routeaddr
54
+ ;
55
+
56
+ group: phrase ':' mboxes ';'
57
+ ;
58
+
59
+ routeaddr: '<' route spec '>'
60
+ | '<' spec '>'
61
+ ;
62
+
63
+ route: at_domains ':' ;
64
+
65
+ at_domains: '@' domain
66
+ | at_domains ',' '@' domain
67
+ ;
68
+
69
+ spec: local '@' domain
70
+ | local
71
+ ;
72
+
73
+ local: word
74
+ | local '.' word
75
+ ;
76
+
77
+ domain: domword
78
+ | domain '.' domword
79
+ ;
80
+
81
+ domword: atom
82
+ | DOMLIT
83
+ | DIGIT
84
+ ;
85
+
86
+ phrase: word
87
+ | phrase word
88
+ ;
89
+
90
+ word: atom
91
+ | QUOTED
92
+ | DIGIT
93
+ ;
94
+
95
+ atom: ATOM | FROM | BY | VIA | WITH | ID | FOR ;
96
+
97
+ end
@@ -0,0 +1,14 @@
1
+ # 1 s/r conflict and 1 r/r conflict
2
+
3
+ class A
4
+ rule
5
+
6
+ target: a
7
+
8
+ a :
9
+ | a list
10
+
11
+ list :
12
+ | list ITEM
13
+
14
+ end
@@ -0,0 +1,72 @@
1
+ class P
2
+
3
+ rule
4
+
5
+ a: A
6
+ {
7
+ # comment test
8
+
9
+ # comment test
10
+
11
+ # string
12
+ @sstring = 'squote string'
13
+ @dstring = 'dquote string'
14
+
15
+ # regexp
16
+ @regexp = /some regexp with spaces/
17
+
18
+ # gvar
19
+ /regexp/ === 'some regexp matches to this string'
20
+ @pre_match = $`
21
+ @matched = $&
22
+ @post_match = $'
23
+ @m = $~
24
+
25
+ # braces
26
+ @array = []
27
+ [1,2,3].each {|i|
28
+ @array.push i
29
+ }
30
+ 3.times { @array.push 10 }
31
+ }
32
+
33
+ end
34
+
35
+ ---- inner
36
+
37
+ def parse
38
+ @sstring = @dstring = nil
39
+ @regexp = nil
40
+ @pre_match = @matched = @post_match = @m = nil
41
+
42
+ @src = [[:A, 'A'], [false, '$']]
43
+ do_parse
44
+
45
+ assert_equal 'squote string', @sstring
46
+ assert_equal 'dquote string', @dstring
47
+ assert_equal(/some regexp with spaces/, @regexp)
48
+ assert_equal 'some ', @pre_match
49
+ assert_equal 'regexp', @matched
50
+ assert_equal ' matches to this string', @post_match
51
+ assert_instance_of MatchData, @m
52
+ end
53
+
54
+ def assert_equal(ok, data)
55
+ unless ok == data
56
+ raise "expected <#{ok.inspect}> but is <#{data.inspect}>"
57
+ end
58
+ end
59
+
60
+ def assert_instance_of(klass, obj)
61
+ unless obj.instance_of?(klass)
62
+ raise "expected #{klass} but is #{obj.class}"
63
+ end
64
+ end
65
+
66
+ def next_token
67
+ @src.shift
68
+ end
69
+
70
+ ---- footer
71
+
72
+ P.new.parse