Hi,
In mail "Re: problems with racc: $end token"
"Luke A. Kanies" <luke / madstop.com> wrote:
> There is debugging in racc, and using racc -E to embed the parser and then
> manually setting @yydebug = true can turn it on. I'm sure there's a
> better way.
Set @yydebug=true in your "inner" and use racc -g.
% cat t.y
class MyParser
options no_result_var
rule
program: list
list : { [] }
| list ITEM { val[0].push val[1]; val[0] }
---- inner
def parse
@tokens = [
[:ITEM, '1'],
[:ITEM, '2'],
[:ITEM, '3']
]
@yydebug = true #####
do_parse
end
def next_token
@tokens.shift
end
---- footer
p MyParser.new.parse
~/tmp % racc -ot.rb t.y
~/tmp % ruby t.rb
["1", "2", "3"]
~/tmp % racc -g -ot.rb t.y
~/tmp % ruby t.rb
reduce <none> --> list
[ (list []) ]
goto 2
[ 0 2 ]
read :ITEM(ITEM) "1"
shift ITEM
(snip)
> Also, you must set 'return' manually, although it can be any type of
> variable.
Try this:
class MyParser
options no_result_var #### this line
rule
....
Regards,
Minero Aoki