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/test/assets/noend.y
ADDED
@@ -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
|
data/test/assets/opt.y
ADDED
@@ -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
|
data/test/assets/recv.y
ADDED
@@ -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
|
data/test/assets/scan.y
ADDED
@@ -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
|