[antlr-interest] How can a syntactic predicate not be satisfied if the input matches it?
Martijn Reuvers
martijn.reuvers at gmail.com
Mon Dec 19 08:31:33 PST 2011
Hello Gavin,
It may have something to do with a token that is the 'largest' token
which is consumed first and automatically 'enforces' the other rule
(making the predicate fail).
E.g. this very simple grammer:
grammar Test;
a: (r1)=>r1
| r2;
r1 : Y Z;
r2: X;
X: 'ab';
Y: 'a';
Z: 'b';
If you provide this grammar with 'ab'. This will always end up in r2,
as the token X is always matched first (returned by the lexer). That's
how the antlrs lexer works by default.
Regards,
Martijn
On Sat, Dec 17, 2011 at 1:54 AM, Gavin King <gavin.king at gmail.com> wrote:
> Hi folks,
>
> I have a large grammar with a rule like this:
>
> z: (x)=>x | y
>
> And I have some input that I know matches x. I know this for sure,
> because when I change z to read:
>
> z: x
>
> Then ANTLR parses that input successfully with no errors.
>
> To my surprise, the input does not match z, and the errors generated
> come from attempting to match y. So apparently the syntactic predicate
> (x)=> failed to match the input, even though I'm quite certain that x
> does match it. I even tried changing z to:
>
> z options { backtrack=true; } : x | y
>
> which, unsurprisingly, failed to help.
>
> What could possibly be the cause of this?
>
> Thanks,
> Gavin
>
> --
> Gavin King
> gavin.king at gmail.com
> http://in.relation.to/Bloggers/Gavin
> http://ceylon-lang.org
> http://hibernate.org
> http://seamframework.org
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list