[antlr-interest] Why this grammar doesn't work?

Jim Idle jimi at temporal-wave.com
Tue Oct 23 09:53:10 PDT 2007


Cristian,

 

It is likely that the true error here is part of the larger grammar
structure. When you ‘overuse’ (if there is such a thing) the backtrack=true
option, you are masking ambiguities in your grammar that really, should be
teased out of it. This option is great for smaller grammars or where you
don’t really care that much about the performance, but in the end it can get
you into trouble if you just use it to get rid of warnings/errors you would
otherwise get.

 

At least as an exercise, I would try turning off backtracking/memoizing, and
see what ANTLR tells you about the grammar then. Though you may get more
warnings and errors than you care to fix at this point, you might be able to
see what is truly going on and at least fix that part. After that, you can
turn backtracking on again and ignore the other warnings of course if you
wish, though personally I would recommend that you try to construct your
grammar such that the global use of backtracking is no required.

 

I hope that this is of some help to you,

 

Jim

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Cristian Peraferrer
Sent: Tuesday, October 23, 2007 8:12 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Why this grammar doesn't work?

 

Hi, I've picked up a part of my grammar to ask you what I am doing wrong:

grammar Test1;

options {k = 2; backtrack = true; memoize=true; output = AST; ASTLabelType =
CommonTree;}

type    :    primitiveType ('[' ']')* ; 
primitiveType
    :    'bool'
        |    'char'
        |    'short'
        |    'int'
        |    'long'
        |    'float'
        |    'double' 
    ;

I test it in ANTLRWorks interpreter, and gives me a
"FailedPredicateException(type,{synpred1}?)"

Anyone can explain why it occurs? and how I can solve it?

Thanks in advance, 

Cris

-- 
GPG Key-ID: 0x564903FA - JID: HYPERLINK
"mailto:corellian at swissjabber.ch"corellian at swissjabber.ch 

No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.15.6/1086 - Release Date: 10/22/2007
7:57 PM


No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.488 / Virus Database: 269.15.6/1086 - Release Date: 10/22/2007
7:57 PM
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071023/68554c61/attachment-0001.html 


More information about the antlr-interest mailing list