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.
- 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
@@ -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.
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<h1>Racc User Manual</h1>
|
2
|
+
<p>updated for version 1.4</p>
|
3
|
+
<ul>
|
4
|
+
<li><a href="usage.html">Usage</a>
|
5
|
+
<li><a href="command.html">Racc Command Reference</a>
|
6
|
+
<li><a href="grammar.html">Racc Grammar File Reference</a>
|
7
|
+
<li><a href="parser.html">Racc::Parser class Reference</a>
|
8
|
+
<li><a href="debug.html">Debugging Parser</a>
|
9
|
+
<li><a href="NEWS.html">Release Note</a>
|
10
|
+
</ul>
|
@@ -0,0 +1,74 @@
|
|
1
|
+
= class Racc::Parser
|
2
|
+
|
3
|
+
== Super Class
|
4
|
+
|
5
|
+
Object
|
6
|
+
|
7
|
+
== Instance Methods
|
8
|
+
|
9
|
+
: do_parse -> Object
|
10
|
+
The entry point of parser. This method is used with #next_token.
|
11
|
+
If Racc wants to get token (and its value), calls next_token.
|
12
|
+
|
13
|
+
--
|
14
|
+
# Example
|
15
|
+
---- inner
|
16
|
+
def parse
|
17
|
+
@q = [[1,1],
|
18
|
+
[2,2],
|
19
|
+
[3,3],
|
20
|
+
[false, '$']]
|
21
|
+
do_parse
|
22
|
+
end
|
23
|
+
|
24
|
+
def next_token
|
25
|
+
@q.shift
|
26
|
+
end
|
27
|
+
--
|
28
|
+
|
29
|
+
: next_token -> [Symbol, Object]
|
30
|
+
[abstract method]
|
31
|
+
|
32
|
+
The method to fetch next token. If you use #do_parse method,
|
33
|
+
you must implement #next_token. The format of return value is
|
34
|
+
[TOKEN_SYMBOL, VALUE]. token-symbol is represented by Ruby's symbol
|
35
|
+
by default, e.g. :IDENT for 'IDENT'. ";" (String) for ';'.
|
36
|
+
|
37
|
+
The final symbol (End of file) must be false.
|
38
|
+
|
39
|
+
: yyparse( receiver, method_id )
|
40
|
+
The another entry point of parser.
|
41
|
+
If you use this method, you must implement RECEIVER#METHOD_ID method.
|
42
|
+
|
43
|
+
RECEIVER#METHOD_ID is a method to get next token.
|
44
|
+
It must 'yield's token, which format is [TOKEN-SYMBOL, VALUE].
|
45
|
+
|
46
|
+
: on_error( error_token_id, error_value, value_stack )
|
47
|
+
This method is called when parse error is found.
|
48
|
+
|
49
|
+
ERROR_TOKEN_ID is an internal ID of token which caused error.
|
50
|
+
You can get string replesentation of this ID by calling
|
51
|
+
#token_to_str.
|
52
|
+
|
53
|
+
ERROR_VALUE is a value of error token.
|
54
|
+
|
55
|
+
value_stack is a stack of symbol values.
|
56
|
+
DO NOT MODIFY this object.
|
57
|
+
|
58
|
+
This method raises ParseError by default.
|
59
|
+
|
60
|
+
If this method returns, parsers enter "error recovering mode".
|
61
|
+
|
62
|
+
: token_to_str( t ) -> String
|
63
|
+
Convert internal ID of token symbol to the string.
|
64
|
+
|
65
|
+
: yyerror
|
66
|
+
Enter error recovering mode.
|
67
|
+
This method does not call #on_error.
|
68
|
+
|
69
|
+
: yyerrok
|
70
|
+
Leave error recovering mode.
|
71
|
+
|
72
|
+
: yyaccept
|
73
|
+
Exit parser.
|
74
|
+
Return value is Symbol_Value_Stack[0].
|
@@ -0,0 +1,83 @@
|
|
1
|
+
= Usage
|
2
|
+
|
3
|
+
== Generating Parser Using Racc
|
4
|
+
|
5
|
+
To compile Racc grammar file, simply type:
|
6
|
+
|
7
|
+
$ racc parse.y
|
8
|
+
|
9
|
+
This creates ruby script file "parse.tab.y". The -o option can change the output filename.
|
10
|
+
|
11
|
+
== Writing A Racc Grammar File
|
12
|
+
|
13
|
+
If you want your own parser, you have to write a grammar file.
|
14
|
+
A grammar file contains the name of your parser class, grammar for the parser,
|
15
|
+
user code, and anything else.
|
16
|
+
When writing a grammar file, yacc's knowledge is helpful.
|
17
|
+
If you have not used yacc before, Racc is not too difficult.
|
18
|
+
|
19
|
+
Here's an example Racc grammar file.
|
20
|
+
|
21
|
+
class Calcparser
|
22
|
+
rule
|
23
|
+
target: exp { print val[0] }
|
24
|
+
|
25
|
+
exp: exp '+' exp
|
26
|
+
| exp '*' exp
|
27
|
+
| '(' exp ')'
|
28
|
+
| NUMBER
|
29
|
+
end
|
30
|
+
|
31
|
+
Racc grammar files resemble yacc files.
|
32
|
+
But (of course), this is Ruby code.
|
33
|
+
yacc's $$ is the 'result', $0, $1... is
|
34
|
+
an array called 'val', and $-1, $-2... is an array called '_values'.
|
35
|
+
|
36
|
+
== Parser
|
37
|
+
|
38
|
+
Then you must prepare the parse entry method. There are two types of
|
39
|
+
parse methods in Racc, Racc::Parser#do_parse and Racc::Parser#yyparse
|
40
|
+
|
41
|
+
Racc::Parser#do_parse is simple.
|
42
|
+
|
43
|
+
It's yyparse() of yacc, and Racc::Parser#next_token is yylex().
|
44
|
+
This method must returns an array like [TOKENSYMBOL, ITS_VALUE].
|
45
|
+
EOF is [false, false].
|
46
|
+
(TOKENSYMBOL is a Ruby symbol (taken from String#intern) by default.
|
47
|
+
If you want to change this, see the grammar reference.
|
48
|
+
|
49
|
+
Racc::Parser#yyparse is little complicated, but useful.
|
50
|
+
It does not use Racc::Parser#next_token, instead it gets tokens from any iterator.
|
51
|
+
|
52
|
+
For example, <code>yyparse(obj, :scan)</code> causes
|
53
|
+
calling +obj#scan+, and you can return tokens by yielding them from +obj#scan+.
|
54
|
+
|
55
|
+
== Debugging
|
56
|
+
|
57
|
+
When debugging, "-v" or/and the "-g" option is helpful.
|
58
|
+
|
59
|
+
"-v" creates verbose log file (.output).
|
60
|
+
"-g" creates a "Verbose Parser".
|
61
|
+
Verbose Parser prints the internal status when parsing.
|
62
|
+
But it's _not_ automatic.
|
63
|
+
You must use -g option and set +@yydebug+ to +true+ in order to get output.
|
64
|
+
-g option only creates the verbose parser.
|
65
|
+
|
66
|
+
== Re-distributing Racc runtime
|
67
|
+
|
68
|
+
A parser, which is created by Racc, requires the Racc runtime module;
|
69
|
+
racc/parser.rb.
|
70
|
+
|
71
|
+
Ruby 1.8.x comes with Racc runtime module,
|
72
|
+
you need NOT distribute Racc runtime files.
|
73
|
+
|
74
|
+
If you want to include the Racc runtime module with your parser.
|
75
|
+
This can be done by using '-E' option:
|
76
|
+
|
77
|
+
$ racc -E -omyparser.rb myparser.y
|
78
|
+
|
79
|
+
This command creates myparser.rb which `includes' Racc runtime.
|
80
|
+
Only you must do is to distribute your parser file (myparser.rb).
|
81
|
+
|
82
|
+
Note: parser.rb is LGPL, but your parser is not.
|
83
|
+
Your own parser is completely yours.
|