On Nov 28, 2:59 pm, "wbsurf... / yahoo.com" <wbsurf... / gmail.com> wrote:
> =begin
> I got this recursive decent parser from:http://www.rubyinside.com/recursive-descent-parser-for-ruby-300.html
>
> I get this syntax error:
> C:/rb-play/parser/try.rb:13: syntax error, unexpected ']', expecting
> kEND
>   g.operation           /[+-*/]/
>
> if I change that line to:
>   g.operation           /[+-]/
> that line no longer has an error, so the / and * threw it off
>
> then I get an error on another line:
>
>   g.string              %r(["'](.*?[^\]|.*?)["'])
> C:/rb-play/parser/try.rb:15: warning: character class has `[' without
> escape
> C:/rb-play/parser/try.rb:15: unmatched (: /["'](.*?[^\]|.*?)["']/
>

In the first, you need the - at the beginning of the (or escaped with
a backslash) or Ruby interprets it as a character range. You also need
to escape the first forward slash or Ruby interprets it as the end of
the Regex. So:

/[-+*\/]/

In the second, the backslash needs to be escaped. If it isn't, then it
is used to escape the following ] so the character class isn't closed
until the final ] which is just wrong. So:

%r(["'](.*?[^\\]|.*?)["'])

Consider both issues were due to missing backslashes, they were
probably originally correct. I guess somewhere along the way the
backslashes were interpreted as escape characters and didn't make it
to the final page.

Jeremy