[antlr-interest] syntax predicate strange behavior
David Holroyd
dave at badgers-in-foil.co.uk
Tue May 1 00:53:52 PDT 2007
On Tue, May 01, 2007 at 02:03:37AM +0400, Ilia Kantor wrote:
> command_user_body:
> (LCURL) => LCURL command_arguments? RCURL -> ^(USER_COMMAND command_arguments?) |
> -> USER_COMMAND
> ;
>
> On input LCURL WS WORD WS MINUS GT...
> this gives me exception from DFA.noViableAlt at first WORD token.
Which decision is it trying to predict when it fails? That rule has a
'|' decision and a '?' decision. The command_arguments rule might be
significant to understanding the problem.
Also, why the predicate on LCURL? Probably makes sense in the wider
grammar, but we can't see that ;)
> By the way, this works fine:
>
> command_user_body
> options {backtrack=true;}:
> LCURL command_arguments? RCURL -> ^(USER_COMMAND command_arguments?) |
> -> USER_COMMAND
> ;
With backtracking (which I admit I don't wholly understand yet) I guess
if it fails on the first alt, it will back-off to the second, empty
alternative?
--
http://david.holroyd.me.uk/
More information about the antlr-interest
mailing list