[antlr-interest] Lexer gives FailedPredicateException in a gated semantic predicate followed by an infinite loop

dermot_1 at astrodrive.com dermot_1 at astrodrive.com
Tue Aug 26 04:12:00 PDT 2008


I've got a simple XML parser/lexer and the lexer rules are structured
something like this:

 

PCDATA : {tagMode == 0}?=> (~'<')+ {$channel=HIDDEN;};

 

This scarfs all PCDATA upto a starting tag symbol.

 

However, the code generated is this:

 

if ( !((tagMode == 0)) ) {throw new FailedPredicateException(input,
"PCDATA", "tagMode == 0");}

 

with the normal code following.

 

The problem is that if the rule is invoked and the tagMode isn't zero I get
a FailedPredicateException. This then causes an infinite loop as the PCDATA
rule is then invoked by Antlr again and so on ad infinitum.

 

The grammar works well if I have a reasonably correct file - but it doesn't
work if the file is (for example) a C code file instead of an XML file.

 

The Antlr book seems to say that I should not get a FailedPredicateException
with a gated semantic predicate (p286).

 

Looking at the DFA code, the PCDATA rule is being selected there.

 

I'm a bit confused as to what's going on - all I want is for the rule not to
be invoked when tagMode isn't zero.

 

I can always trap the FailedPredicateException and exit - but it seems to me
that the code shouldn't be producing an infinite loop.

 

Dermot

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080826/ab6700f8/attachment.html 


More information about the antlr-interest mailing list