[antlr-interest] Non-LL(*) with option backtrack=true

Martin Probst mail at martin-probst.com
Mon Mar 17 07:49:30 PDT 2008


Hi all,

after a long hiatus I'm doing some ANTLR work again. This times it's  
more or less just for fun, but whatever.

My problem is once again the XQuery grammar. I've simply converted the  
official grammar into ANTLR format and I'm trying to resolve the  
remaining errors starting from this. See the attached file for the  
grammar.

I have two problems with the grammar, both in areas where the grammar  
is non-deterministic.

ANTLR says that the rule pathExpr is non-LL(*). The rule goes like this:
pathExpr	:	('/' relativePathExpr?)  | ('//' relativePathExpr)  |  
relativePathExpr;
The problem is that the following statement is valid XQuery but  
ambiguous:
/ * foo
Which could mean (/*) foo (as in RootNode->AllChildElements followed  
by foo) or, alternatively, (/) * foo, as in RootNode TIMES foo. The  
specification says to treat this as in the earlier case, i.e. /*   foo.

Now the question: how do I tell this to ANTLR? It should be as easy as  
saying: "in doubt, prefer this branch". But as ANTLR should be greedy,  
this should already be the case, if I'm not mistaken?

The same issue happens with the sequenceType rule somewhere later in  
the file. Any ideas? I tried options { backtrack = true; } but that  
didn't help.

Best regards,
Martin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: XQuery.g
Type: application/octet-stream
Size: 10333 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080317/be69d36c/attachment-0001.obj 
-------------- next part --------------



More information about the antlr-interest mailing list