[antlr-interest] Failed Predicate Infinite Loop

Mark Mandel mark.mandel at gmail.com
Sun Jan 23 22:05:18 PST 2011


Reading through the (great) ANTLR book, I see there is code in there to use
if you want to exit the recogniser on first error. It's not 100% ideal (in
case I want to ever report more than 1 error in a row in the future), but I
may try that out shortly.

I would still be interested to work out how to avoid this issue in future
grammars.

Mark

On Mon, Jan 24, 2011 at 4:44 PM, Mark Mandel <mark.mandel at gmail.com> wrote:

> Hey guys,
>
> My grammar can be seen here:
>
> http://coldspring.git.sourceforge.net/git/gitweb.cgi?p=coldspring/coldspring;a=blob;f=antlr/com/coldspring/aop/expression/AopExpression.g;h=b80ef8a7ddd854458791e4e044a8f09461b66c50;hb=HEAD
>
> It's a parser for a subset of AspectJ expressions, with some minor
> modifications (if anyone cares ;o) ).
>
> An example expression would be:
> @annotation(dostuff='true')
>
> I've used predicate in my lexer to work pick up the first item in the
> expression, i.e. an expression should always start with 'target', '@target',
> 'execution', 'within' or '@annotation'
>
> If I have a typo in the expression that is being entered, e.g.
>
> @annotaion(dostuff='true')
>
> I get the following output:
> line 1:7 mismatched character 'i' expecting 't'
> line 1:8 rule DESCRIPTOR failed predicate: {expressionStart}?
> line 1:8 rule DESCRIPTOR failed predicate: {expressionStart}?
> line 1:8 rule DESCRIPTOR failed predicate: {expressionStart}?
> line 1:8 rule DESCRIPTOR failed predicate: {expressionStart}?
> line 1:8 rule DESCRIPTOR failed predicate: {expressionStart}?
> line 1:8 rule DESCRIPTOR failed predicate: {expressionStart}?
> line 1:8 rule DESCRIPTOR failed predicate: {expressionStart}?
> line 1:8 rule DESCRIPTOR failed predicate: {expressionStart}?
> line 1:8 rule DESCRIPTOR failed predicate: {expressionStart}?
> line 1:8 rule DESCRIPTOR failed predicate: {expressionStart}?
> line 1:8 rule DESCRIPTOR failed predicate: {expressionStart}?
> .... (infinite loop) ....
>
> The errors are perfectly correct, but the infinite loop is a bit of a
> problem, as I'm sure you can understand.
>
> Is this a bug in ANTLR, or is there a way I can fix/change my grammar (or
> add in some custom code), so that I don't fall into the infinite loop? (or
> escape out of it)
>
> I'm guessing this is because ANTLR tries to recover from an error whenever
> it encounters one. (Which I would also be happy to turn off, I only need the
> 1st error for my purposes at the moment).
>
> Any help would be appreciated.
>
> Mark
>
>
> --
> E: mark.mandel at gmail.com
> T: http://www.twitter.com/neurotic
> W: www.compoundtheory.com
>
> cf.Objective(ANZ) - Nov 18, 19 - Melbourne Australia
> http://www.cfobjective.com.au
>
> Hands-on ColdFusion ORM Training
> www.ColdFusionOrmTraining.com
>



-- 
E: mark.mandel at gmail.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

cf.Objective(ANZ) - Nov 18, 19 - Melbourne Australia
http://www.cfobjective.com.au

Hands-on ColdFusion ORM Training
www.ColdFusionOrmTraining.com


More information about the antlr-interest mailing list