racc 1.4.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitattributes +2 -0
- data/.gitignore +7 -0
- data/COPYING +515 -0
- data/ChangeLog +846 -0
- data/DEPENDS +4 -0
- data/README.en.rdoc +86 -0
- data/README.ja.rdoc +96 -0
- data/Rakefile +15 -0
- data/TODO +5 -0
- data/bin/racc +308 -0
- data/bin/racc2y +195 -0
- data/bin/y2racc +339 -0
- data/doc/en/NEWS.en.rdoc +282 -0
- data/doc/en/command.en.html +78 -0
- data/doc/en/debug.en.rdoc +20 -0
- data/doc/en/grammar.en.rdoc +230 -0
- data/doc/en/index.en.html +10 -0
- data/doc/en/parser.en.rdoc +74 -0
- data/doc/en/usage.en.html +92 -0
- data/doc/ja/NEWS.ja.rdoc +307 -0
- data/doc/ja/command.ja.html +94 -0
- data/doc/ja/debug.ja.rdoc +36 -0
- data/doc/ja/grammar.ja.rdoc +348 -0
- data/doc/ja/index.ja.html +10 -0
- data/doc/ja/parser.ja.rdoc +125 -0
- data/doc/ja/usage.ja.html +414 -0
- data/ext/racc/cparse/MANIFEST +4 -0
- data/ext/racc/cparse/cparse.c +824 -0
- data/ext/racc/cparse/depend +1 -0
- data/ext/racc/cparse/extconf.rb +7 -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 +214 -0
- data/lib/racc/parser.rb +439 -0
- data/lib/racc/parserfilegenerator.rb +511 -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/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/tasks/file.rb +37 -0
- data/tasks/gem.rb +37 -0
- data/tasks/test.rb +16 -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 +88 -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 +166 -0
data/doc/en/NEWS.en.rdoc
ADDED
@@ -0,0 +1,282 @@
|
|
1
|
+
= NEWS
|
2
|
+
|
3
|
+
=== 1.4.6
|
4
|
+
|
5
|
+
* Bugfixes
|
6
|
+
|
7
|
+
* bin/racc -g option renamed to -t
|
8
|
+
* racc/compiler.rb is removed
|
9
|
+
* '|' is allowed with meta rules
|
10
|
+
* Ruby 1.8.7 compatibility fixes
|
11
|
+
* Ruby 1.9 compatibility fixes
|
12
|
+
|
13
|
+
=== 1.4.5 (2005-11-21)
|
14
|
+
* [FEATURE CHANGE] --no-extensions option was removed.
|
15
|
+
* [fix] racc command should not depend on `raccrt' package.
|
16
|
+
* [fix] --no-omit-actions did not work.
|
17
|
+
* setup.rb 3.4.1.
|
18
|
+
|
19
|
+
=== 1.4.4 (2003-10-12)
|
20
|
+
* document changed.
|
21
|
+
* -all packages does not include amstd and strscan.
|
22
|
+
* setup.rb 3.2.1.
|
23
|
+
|
24
|
+
=== 1.4.3 (2002-11-14)
|
25
|
+
* [fix] reduce ruby 1.8 warnings.
|
26
|
+
|
27
|
+
=== 1.4.2 (2002-01-29)
|
28
|
+
* [new] new option --no-extentions
|
29
|
+
|
30
|
+
=== 1.4.1 (2001-12-02)
|
31
|
+
* now Racc does not depend on amstd library.
|
32
|
+
* update y2racc and racc2y for racc 1.4.1
|
33
|
+
|
34
|
+
=== 1.4.0 (2001-11-30)
|
35
|
+
* minor version up for checking in runtime library into ruby CVS repositry.
|
36
|
+
* RaccParser, RaccScanner -> GrammarFileParser, GrammarFileScanner
|
37
|
+
* modify typo (grammer -> grammar)
|
38
|
+
|
39
|
+
=== 1.3.12 (2001-11-22)
|
40
|
+
* modify installer bug (thanks Tanaka Akira)
|
41
|
+
* enhance regexp/%-strings/gvar detection in action block
|
42
|
+
|
43
|
+
=== 1.3.11 (2001-08-28)
|
44
|
+
* modify scan error on $' $` $/ etc.
|
45
|
+
|
46
|
+
=== 1.3.10 (2001-08-12)
|
47
|
+
* modify prototype missmatch in cparse.c
|
48
|
+
|
49
|
+
=== 1.3.9 (2001-04-07)
|
50
|
+
* support Ruby 1.4 again.
|
51
|
+
|
52
|
+
=== 1.3.8 (2001-03-17)
|
53
|
+
* output symbol name when error
|
54
|
+
* Racc::Parser#token_to_str
|
55
|
+
|
56
|
+
=== 1.3.7 (2001-02-04)
|
57
|
+
* allow nil for EndOfInput (experimental)
|
58
|
+
* more sample grammar files
|
59
|
+
|
60
|
+
=== 1.3.6 (2001-01-22)
|
61
|
+
* modify cparse.so for static link
|
62
|
+
|
63
|
+
=== 1.3.5 (2001-01-18)
|
64
|
+
* %-string scanning was wrong
|
65
|
+
* new directive "expect"
|
66
|
+
|
67
|
+
=== 1.3.4 (2001-01-11)
|
68
|
+
* cparse: add type checks
|
69
|
+
* cparse: rm depend
|
70
|
+
* cparse: does not pass non-VALUE object to rb_iterate()
|
71
|
+
|
72
|
+
=== 1.3.3 (2000-12-25)
|
73
|
+
* <em>critical bug</em> in generator (from 1.3.1)
|
74
|
+
* racc --runtime-version
|
75
|
+
|
76
|
+
=== 1.3.2 (2000-12-21)
|
77
|
+
* bug with racc -E
|
78
|
+
* package strscan togather (again)
|
79
|
+
|
80
|
+
=== 1.3.1 (2000-12-17)
|
81
|
+
* dynamically determine RE_DUP_MAX
|
82
|
+
* ruby version routine was used always
|
83
|
+
|
84
|
+
=== 1.3.0 (2000-11-30)
|
85
|
+
* can yield(sym,val) from scanner (Parser#yyparse)
|
86
|
+
|
87
|
+
=== 1.2.6 (2000-11-28)
|
88
|
+
* class M::C
|
89
|
+
|
90
|
+
=== 1.2.5 (2000-11-20)
|
91
|
+
* big changes in option; -h -f -p -i -n -c -A are incompatible
|
92
|
+
* support long options
|
93
|
+
* y2racc, racc2y leaves actions as default
|
94
|
+
|
95
|
+
=== 1.2.4 (2000-09-13)
|
96
|
+
* updates installer and documents
|
97
|
+
|
98
|
+
=== 1.2.3 (2000-08-14)
|
99
|
+
* output useless rules and nonterminals (version 2)
|
100
|
+
* nonassoc makes error (never shift/reduce)
|
101
|
+
|
102
|
+
=== 1.2.2 (2000-08-12)
|
103
|
+
* internal changes
|
104
|
+
|
105
|
+
=== 1.2.1 (2000-08-05)
|
106
|
+
* racc2y, y2racc
|
107
|
+
|
108
|
+
=== 1.2.0 (2000-08-02)
|
109
|
+
* uses bison's lookahead algorithm
|
110
|
+
|
111
|
+
=== 1.1.6 (2000-07-25)
|
112
|
+
* new keyword "options" and its parameter "no_result_var"
|
113
|
+
|
114
|
+
=== 1.1.5 (2000-07-21)
|
115
|
+
* [IMPORTANT] change keyword "token" to "convert"
|
116
|
+
* NEW keyword "token" for token declearation
|
117
|
+
|
118
|
+
=== 1.1.4 (2000-07-13)
|
119
|
+
* update installer
|
120
|
+
* samples had bugs
|
121
|
+
|
122
|
+
=== 1.1.3 (2000-06-30)
|
123
|
+
* new option -a; does not omit void action call
|
124
|
+
|
125
|
+
=== 1.1.2 (2000-06-29)
|
126
|
+
* now racc does not use strscan.so
|
127
|
+
* ScanError -> Racc::ScanError, ParseError -> Racc::ParseError
|
128
|
+
* more friendly error messages
|
129
|
+
|
130
|
+
=== 1.1.1 (2000-06-15)
|
131
|
+
* require miss
|
132
|
+
* conflicts were not reported with -v
|
133
|
+
|
134
|
+
=== 1.1.0 (2000-06-12)
|
135
|
+
* use other algolithm for generating state table
|
136
|
+
|
137
|
+
=== 1.0.4 (2000-06-04)
|
138
|
+
* S/R conflict & -v flag causes unexpected exception (reported by Tosh)
|
139
|
+
* output useless nonterminals/rules
|
140
|
+
|
141
|
+
=== 1.0.3 (2000-06-03)
|
142
|
+
* use Array#collect! instead of #filter.
|
143
|
+
|
144
|
+
=== 1.0.2 (2000-05-16)
|
145
|
+
* update installer (setup.rb)
|
146
|
+
|
147
|
+
=== 1.0.1 (2000-05-12)
|
148
|
+
* state.rb: faster lookahead & debug lalr code
|
149
|
+
* refine code
|
150
|
+
* update amstd package (1.7.0)
|
151
|
+
|
152
|
+
=== 1.0.0 (2000-05-06)
|
153
|
+
* version 1.0
|
154
|
+
|
155
|
+
=== 0.14.6 (2000-05-05)
|
156
|
+
* much more debug output
|
157
|
+
|
158
|
+
=== 0.14.5 (2000-05-01)
|
159
|
+
|
160
|
+
=== 0.14.4 (2000-04-09)
|
161
|
+
* Racc_* are included in Racc_arg
|
162
|
+
* faster state generation (a little)
|
163
|
+
|
164
|
+
=== 0.14.3 (2000-04-04)
|
165
|
+
* check both of SYM2ID and ID2SYM (thanks Katsuyuki Komatsu)
|
166
|
+
|
167
|
+
=== 0.14.2 (2000-04-03)
|
168
|
+
* "class" on first line causes parse error (thanks Yoshiki Wada)
|
169
|
+
* new option "racc -V"
|
170
|
+
|
171
|
+
=== 0.14.1 (2000-03-31)
|
172
|
+
|
173
|
+
=== 0.14.0 (2000-03-21)
|
174
|
+
* implement "fast" table (same to bison)
|
175
|
+
* stop line no. conversion temporaliry because of ruby bug
|
176
|
+
|
177
|
+
=== 0.13.1 (2000-03-21)
|
178
|
+
* racc --version --copyright did not work (thanks Tadayoshi Funaba)
|
179
|
+
|
180
|
+
=== 0.13.0 (2000-03-20)
|
181
|
+
* implement yyerror/yyerrok/yyaccept
|
182
|
+
|
183
|
+
=== 0.12.2 (2000-03-19)
|
184
|
+
* -E flag had bug
|
185
|
+
|
186
|
+
=== 0.12.1 (2000-03-16)
|
187
|
+
* modify the way to decide default action
|
188
|
+
|
189
|
+
=== 0.12.0 (2000-03-15)
|
190
|
+
* implement real LALR
|
191
|
+
* use both SLR and LALR to resolve conflicts
|
192
|
+
|
193
|
+
=== 0.11.3 (2000-03-09)
|
194
|
+
* modify lookahead routine again
|
195
|
+
|
196
|
+
=== 0.11.2 (2000-03-09)
|
197
|
+
* bug in lookahead routine
|
198
|
+
* modify cparse.so for Symbol class of ruby 1.5
|
199
|
+
|
200
|
+
=== 0.11.1 (2000-03-08)
|
201
|
+
* modify for Symbol
|
202
|
+
* update strscan
|
203
|
+
|
204
|
+
=== 0.11.0 (2000-02-19)
|
205
|
+
* if error is occured in action, ruby print line number of grammar file
|
206
|
+
|
207
|
+
=== 0.10.9 (2000-01-19)
|
208
|
+
* change package/setup
|
209
|
+
|
210
|
+
=== 0.10.8 (2000-01-03)
|
211
|
+
* (1-17 re-packed) add/modify documents
|
212
|
+
|
213
|
+
=== 0.10.7 (2000-01-03)
|
214
|
+
* modify setup.rb, compile.rb, amstd/inst. (thanks: Koji Arai)
|
215
|
+
|
216
|
+
=== 0.10.6 (1999-12-24)
|
217
|
+
* racc -e ruby
|
218
|
+
* omit void action call
|
219
|
+
|
220
|
+
=== 0.10.5 (1999-12-21)
|
221
|
+
* critical bug in embedded action implement
|
222
|
+
* bug in setup.rb
|
223
|
+
* modify calc[2].y for 0.10
|
224
|
+
|
225
|
+
=== 0.10.4 (1999-12-19)
|
226
|
+
* support error recover ('error' token)
|
227
|
+
* can embed runtime by "racc -E"
|
228
|
+
* Racc is module
|
229
|
+
|
230
|
+
=== 0.10.3 (1999-12-01)
|
231
|
+
* support embedded action
|
232
|
+
* modify .output bug
|
233
|
+
|
234
|
+
=== 0.10.2 (1999-11-27)
|
235
|
+
* update document
|
236
|
+
* separate libracc.rb
|
237
|
+
|
238
|
+
=== 0.10.1 (1999-11-19)
|
239
|
+
* rewrite runtime routine in C
|
240
|
+
* once next_token returns [false, *], not call next_token
|
241
|
+
* action is only default, not call next_token
|
242
|
+
* $end is obsolute
|
243
|
+
* LALRactionTable
|
244
|
+
|
245
|
+
=== 0.10.0 (1999-11-06)
|
246
|
+
* next_value, peep_token is obsolute
|
247
|
+
* @__debug__ -> @yydebug
|
248
|
+
* class...rule...end
|
249
|
+
* refine libracc.rb
|
250
|
+
* unify strscan library
|
251
|
+
* *.rb are installed in lib/ruby/VERSION/racc/
|
252
|
+
|
253
|
+
=== 0.9.5 (1999-10-03)
|
254
|
+
* too few arguments for __show_stack__
|
255
|
+
* could not scan $end
|
256
|
+
* typo in d.format.rb
|
257
|
+
|
258
|
+
=== 0.9.4 (1999-09-??)
|
259
|
+
|
260
|
+
=== 0.9.3 (1999-09-03)
|
261
|
+
|
262
|
+
=== 0.9.2 (1999-06-26)
|
263
|
+
|
264
|
+
=== 0.9.1 (1999-06-08)
|
265
|
+
|
266
|
+
=== 0.9.0 (1999-06-03)
|
267
|
+
|
268
|
+
=== 0.8.11 (?)
|
269
|
+
|
270
|
+
=== 0.8.10 (?)
|
271
|
+
|
272
|
+
=== 0.8.9 (1999-03-21)
|
273
|
+
|
274
|
+
=== 0.8.8 (1999-03-20)
|
275
|
+
|
276
|
+
=== 0.8.7 (1999-03-01)
|
277
|
+
|
278
|
+
=== 0.8.0 (1999-01-16)
|
279
|
+
|
280
|
+
=== 0.5.0 (1999-01-07)
|
281
|
+
|
282
|
+
=== 0.1.0 (1999-01-01)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
<h1>Racc Command Reference</h1>
|
2
|
+
<p>
|
3
|
+
racc [-o<var>filename</var>] [--output-file=<var>filename</var>]
|
4
|
+
[-e<var>rubypath</var>] [--embedded=<var>rubypath</var>]
|
5
|
+
[-v] [--verbose]
|
6
|
+
[-O<var>filename</var>] [--log-file=<var>filename</var>]
|
7
|
+
[-g] [--debug]
|
8
|
+
[-E] [--embedded]
|
9
|
+
[-l] [--no-line-convert]
|
10
|
+
[-c] [--line-convert-all]
|
11
|
+
[-a] [--no-omit-actions]
|
12
|
+
[-C] [--check-only]
|
13
|
+
[-S] [--output-status]
|
14
|
+
[--version] [--copyright] [--help] <var>grammarfile</var>
|
15
|
+
</p>
|
16
|
+
|
17
|
+
<dl>
|
18
|
+
<dt><var>filename</var>
|
19
|
+
<dd>
|
20
|
+
Racc grammar file. Any extention is permitted.
|
21
|
+
</dd>
|
22
|
+
<dt>-o<var>outfile</var>, --output-file=<var>outfile</var>
|
23
|
+
<dd>
|
24
|
+
A filename for output. default is <filename>.tab.rb
|
25
|
+
</dd>
|
26
|
+
<dt>-O<var>filename</var>, --log-file=<var>filename</var>
|
27
|
+
<dd>
|
28
|
+
Place logging output in file <var>filename</var>.
|
29
|
+
Default log file name is <var>filename</var>.output.
|
30
|
+
</dd>
|
31
|
+
<dt>-e<var>rubypath</var>, --executable=<var>rubypath</var>
|
32
|
+
<dd>
|
33
|
+
output executable file(mode 755). <var>path</var> is a path of ruby interpreter.
|
34
|
+
</dd>
|
35
|
+
<dt>-v, --verbose
|
36
|
+
<dd>
|
37
|
+
verbose mode. create <filename>.output file, like yacc's y.output file.
|
38
|
+
</dd>
|
39
|
+
<dt>-g, --debug
|
40
|
+
<dd>
|
41
|
+
add debug code to parser class. To display debuggin information,
|
42
|
+
use this '-g' option and set @yydebug true in parser class.
|
43
|
+
</dd>
|
44
|
+
<dt>-E, --embedded
|
45
|
+
<dd>
|
46
|
+
Output parser which doesn't need runtime files (racc/parser.rb).
|
47
|
+
</dd>
|
48
|
+
<dt>-C, --check-only
|
49
|
+
<dd>
|
50
|
+
Check syntax of racc grammer file and quit.
|
51
|
+
</dd>
|
52
|
+
<dt>-S, --output-status
|
53
|
+
<dd>
|
54
|
+
Print messages time to time while compiling.
|
55
|
+
</dd>
|
56
|
+
<dt>-l, --no-line-convert
|
57
|
+
<dd>
|
58
|
+
turns off line number converting.
|
59
|
+
</dd>
|
60
|
+
<dt>-c, --line-convert-all
|
61
|
+
<dd>
|
62
|
+
Convert line number of actions, inner, header and footer.
|
63
|
+
<dt>-a, --no-omit-actions
|
64
|
+
<dd>
|
65
|
+
Call all actions, even if an action is empty.
|
66
|
+
</dd>
|
67
|
+
<dt>--version
|
68
|
+
<dd>
|
69
|
+
print Racc version and quit.
|
70
|
+
</dd>
|
71
|
+
<dt>--copyright
|
72
|
+
<dd>
|
73
|
+
Print copyright and quit.
|
74
|
+
<dt>--help
|
75
|
+
<dd>
|
76
|
+
Print usage and quit.
|
77
|
+
</dd>
|
78
|
+
</dl>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
= Debugging
|
2
|
+
|
3
|
+
== Racc reported syntax error.
|
4
|
+
|
5
|
+
Isn't there too many "end"?
|
6
|
+
grammar of racc file is changed in v0.10.
|
7
|
+
|
8
|
+
Racc does not use '%' mark, while yacc uses huge number of '%' marks..
|
9
|
+
|
10
|
+
== Racc reported "XXXX conflicts".
|
11
|
+
|
12
|
+
Try "racc -v xxxx.y".
|
13
|
+
It causes producing racc's internal log file, xxxx.output.
|
14
|
+
|
15
|
+
== Generated parsers does not work correctly
|
16
|
+
|
17
|
+
Try "racc -g xxxx.y".
|
18
|
+
This command let racc generate "debugging parser".
|
19
|
+
Then set @yydebug=true in your parser.
|
20
|
+
It produces a working log of your parser.
|
@@ -0,0 +1,230 @@
|
|
1
|
+
= Racc Grammar File Reference
|
2
|
+
|
3
|
+
== Global Structure
|
4
|
+
|
5
|
+
== Class Block and User Code Block
|
6
|
+
|
7
|
+
There's two block on toplevel.
|
8
|
+
one is 'class' block, another is 'user code' block. 'user code' block MUST
|
9
|
+
places after 'class' block.
|
10
|
+
|
11
|
+
== Comment
|
12
|
+
|
13
|
+
You can insert comment about all places. Two style comment can be used,
|
14
|
+
Ruby style (#.....) and C style (/*......*/) .
|
15
|
+
|
16
|
+
== Class Block
|
17
|
+
|
18
|
+
The class block is formed like this:
|
19
|
+
--
|
20
|
+
class CLASS_NAME
|
21
|
+
[precedance table]
|
22
|
+
[token declearations]
|
23
|
+
[expected number of S/R conflict]
|
24
|
+
[options]
|
25
|
+
[semantic value convertion]
|
26
|
+
[start rule]
|
27
|
+
rule
|
28
|
+
GRAMMARS
|
29
|
+
--
|
30
|
+
CLASS_NAME is a name of parser class.
|
31
|
+
This is the name of generating parser class.
|
32
|
+
|
33
|
+
If CLASS_NAME includes '::', Racc outputs module clause.
|
34
|
+
For example, writing "class M::C" causes creating the code bellow:
|
35
|
+
--
|
36
|
+
module M
|
37
|
+
class C
|
38
|
+
:
|
39
|
+
:
|
40
|
+
end
|
41
|
+
end
|
42
|
+
--
|
43
|
+
|
44
|
+
== Grammar Block
|
45
|
+
|
46
|
+
The grammar block discripts grammar which is able
|
47
|
+
to be understood by parser. Syntax is:
|
48
|
+
--
|
49
|
+
(token): (token) (token) (token).... (action)
|
50
|
+
|
51
|
+
(token): (token) (token) (token).... (action)
|
52
|
+
| (token) (token) (token).... (action)
|
53
|
+
| (token) (token) (token).... (action)
|
54
|
+
--
|
55
|
+
(action) is an action which is executed when its (token)s are found.
|
56
|
+
(action) is a ruby code block, which is surrounded by braces:
|
57
|
+
--
|
58
|
+
{ print val[0]
|
59
|
+
puts val[1] }
|
60
|
+
--
|
61
|
+
Note that you cannot use '%' string, here document, '%r' regexp in action.
|
62
|
+
|
63
|
+
Actions can be omitted.
|
64
|
+
When it is omitted, '' (empty string) is used.
|
65
|
+
|
66
|
+
A return value of action is a value of left side value ($$).
|
67
|
+
It is value of result, or returned value by "return" statement.
|
68
|
+
|
69
|
+
Here is an example of whole grammar block.
|
70
|
+
--
|
71
|
+
rule
|
72
|
+
goal: definition ruls source { result = val }
|
73
|
+
|
74
|
+
definition: /* none */ { result = [] }
|
75
|
+
| definition startdesig { result[0] = val[1] }
|
76
|
+
| definition
|
77
|
+
precrule # this line continue from upper line
|
78
|
+
{
|
79
|
+
result[1] = val[1]
|
80
|
+
}
|
81
|
+
|
82
|
+
startdesig: START TOKEN
|
83
|
+
--
|
84
|
+
You can use following special local variables in action.
|
85
|
+
|
86
|
+
* result ($$)
|
87
|
+
|
88
|
+
The value of left-hand side (lhs). A default value is val[0].
|
89
|
+
|
90
|
+
* val ($1,$2,$3...)
|
91
|
+
|
92
|
+
An array of value of right-hand side (rhs).
|
93
|
+
|
94
|
+
* _values (...$-2,$-1,$0)
|
95
|
+
|
96
|
+
A stack of values.
|
97
|
+
DO NOT MODIFY this stack unless you know what you are doing.
|
98
|
+
|
99
|
+
== Operator Precedance
|
100
|
+
|
101
|
+
This function is equal to '%prec' in yacc.
|
102
|
+
To designate this block:
|
103
|
+
--
|
104
|
+
prechigh
|
105
|
+
nonassoc '++'
|
106
|
+
left '*' '/'
|
107
|
+
left '+' '-'
|
108
|
+
right '='
|
109
|
+
preclow
|
110
|
+
--
|
111
|
+
`right' is yacc's %right, `left' is yacc's %left.
|
112
|
+
|
113
|
+
`=' + (symbol) means yacc's %prec:
|
114
|
+
--
|
115
|
+
prechigh
|
116
|
+
nonassoc UMINUS
|
117
|
+
left '*' '/'
|
118
|
+
left '+' '-'
|
119
|
+
preclow
|
120
|
+
|
121
|
+
rule
|
122
|
+
exp: exp '*' exp
|
123
|
+
| exp '-' exp
|
124
|
+
| '-' exp =UMINUS # equals to "%prec UMINUS"
|
125
|
+
:
|
126
|
+
:
|
127
|
+
--
|
128
|
+
|
129
|
+
== expect
|
130
|
+
|
131
|
+
Racc has bison's "expect" directive.
|
132
|
+
--
|
133
|
+
# Example
|
134
|
+
|
135
|
+
class MyParser
|
136
|
+
rule
|
137
|
+
expect 3
|
138
|
+
:
|
139
|
+
:
|
140
|
+
--
|
141
|
+
This directive declears "expected" number of shift/reduce conflict.
|
142
|
+
If "expected" number is equal to real number of conflicts,
|
143
|
+
racc does not print confliction warning message.
|
144
|
+
|
145
|
+
== Declaring Tokens
|
146
|
+
|
147
|
+
By declaring tokens, you can avoid many meanless bugs.
|
148
|
+
If decleared token does not exist/existing token does not decleared,
|
149
|
+
Racc output warnings. Declearation syntax is:
|
150
|
+
--
|
151
|
+
token TOKEN_NAME AND_IS_THIS
|
152
|
+
ALSO_THIS_IS AGAIN_AND_AGAIN THIS_IS_LAST
|
153
|
+
--
|
154
|
+
|
155
|
+
== Options
|
156
|
+
|
157
|
+
You can write options for racc command in your racc file.
|
158
|
+
--
|
159
|
+
options OPTION OPTION ...
|
160
|
+
--
|
161
|
+
Options are:
|
162
|
+
|
163
|
+
* omit_action_call
|
164
|
+
|
165
|
+
omit empty action call or not.
|
166
|
+
|
167
|
+
* result_var
|
168
|
+
|
169
|
+
use/does not use local variable "result"
|
170
|
+
|
171
|
+
You can use 'no_' prefix to invert its meanings.
|
172
|
+
|
173
|
+
== Converting Token Symbol
|
174
|
+
|
175
|
+
Token symbols are, as default,
|
176
|
+
|
177
|
+
* naked token string in racc file (TOK, XFILE, this_is_token, ...)
|
178
|
+
--> symbol (:TOK, :XFILE, :this_is_token, ...)
|
179
|
+
* quoted string (':', '.', '(', ...)
|
180
|
+
--> same string (':', '.', '(', ...)
|
181
|
+
|
182
|
+
You can change this default by "convert" block.
|
183
|
+
Here is an example:
|
184
|
+
--
|
185
|
+
convert
|
186
|
+
PLUS 'PlusClass' # We use PlusClass for symbol of `PLUS'
|
187
|
+
MIN 'MinusClass' # We use MinusClass for symbol of `MIN'
|
188
|
+
end
|
189
|
+
--
|
190
|
+
We can use almost all ruby value can be used by token symbol,
|
191
|
+
except 'false' and 'nil'. These are causes unexpected parse error.
|
192
|
+
|
193
|
+
If you want to use String as token symbol, special care is required.
|
194
|
+
For example:
|
195
|
+
--
|
196
|
+
convert
|
197
|
+
class '"cls"' # in code, "cls"
|
198
|
+
PLUS '"plus\n"' # in code, "plus\n"
|
199
|
+
MIN "\"minus#{val}\"" # in code, \"minus#{val}\"
|
200
|
+
end
|
201
|
+
--
|
202
|
+
|
203
|
+
== Start Rule
|
204
|
+
|
205
|
+
'%start' in yacc. This changes start rule.
|
206
|
+
--
|
207
|
+
start real_target
|
208
|
+
--
|
209
|
+
This statement will not be used forever, I think.
|
210
|
+
|
211
|
+
== User Code Block
|
212
|
+
|
213
|
+
"User Code Block" is a Ruby source code which is copied to output.
|
214
|
+
There are three user code block, "header" "inner" and "footer".
|
215
|
+
|
216
|
+
Format of user code is like this:
|
217
|
+
--
|
218
|
+
---- header
|
219
|
+
ruby statement
|
220
|
+
ruby statement
|
221
|
+
ruby statement
|
222
|
+
|
223
|
+
---- inner
|
224
|
+
ruby statement
|
225
|
+
:
|
226
|
+
:
|
227
|
+
--
|
228
|
+
If four '-' exist on line head,
|
229
|
+
racc treat it as beginning of user code block.
|
230
|
+
A name of user code must be one word.
|