From: Steven Jenkins Date: 2005-04-25T08:30:02+09:00 Subject: Re: Racc Peter Suk wrote: > I need help using Racc. I've been trying to go through the basic > calculator example, but no go. The grammar is processed without any > shift-reduce conflicts. It appears I am feeding the wrong kind of > tokens to it. I keep getting: > > > Parsing file: > /usr/local/lib/ruby/site_ruby/1.8/racc/parser.rb:377:in `on_error': > (Racc::ParseError) > parse error on value 1 (NUMBER) from > /usr/local/lib/ruby/site_ruby/1.8/racc/parser.rb:104:in `_racc_do_parse_c' > from /usr/local/lib/ruby/site_ruby/1.8/racc/parser.rb:104:in > `__send__' > from /usr/local/lib/ruby/site_ruby/1.8/racc/parser.rb:104:in > `do_parse' > from racc-calc-2.y:47:in `parse' > from ruby_calc_test.rb:20 That means there's no rule that matches the input. > I am feeding it tokens that are two-element arrays, as stated in the > documentation. But it > is not at all clear what should be in the second element. Racc doesn't care. As long as the lexer and your productions agree on the type (or on the duck-typing), it's OK. Your understanding appears to be fine. You just have a simple bug--see below. > [snip] > -------- FakeLexer.rb -------- > require 'RubyCalcParser' > > class FakeLexer > > def initialize(tokens) > @tokens = tokens > @index = 0 > end > > def reset() > @index = 0 > end > > def yylex() > rval = @tokens[@index] > @index += @index @index += 1 > return rval > end > > end > -------- end -------- It's returning two NUMBERS in a row, which is a syntax error in your grammar. Don't you love bugs like this? If you didn't suspect your understanding of Racc, you'd probably have found in in two minutes. HTH. Steve