[antlr-interest] Grammar generation results in exception

Jim Idle jimi at temporal-wave.com
Mon Jun 25 09:16:00 PDT 2007


Only use backtracking and memoizing when you are producing a prototype
or you really do not care at all about speed. It makes things easy but
the best thing to do for a production grammar is get rid of the
ambiguities. 

It is going to execute as a predicate each possible rule in order, then
select the first one that matches up correctly. Of course this can be a
lot of overhead. That will normally select the option you want, but you
can see that the fact you have to ask this question tends to indicate
that this is prototyping option (and a good one at that) as you won't
remember the answer in 18 months time when you come back to fix
something :-)

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Johannes Luber
> Sent: Monday, June 25, 2007 6:00 AM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Grammar generation results in exception
> 
> Thomas Brandon wrote:
> > This error is because you have mixed rewrites and AST building
> > operators (! and ^) in a single rule. In this case the error is
> > because you have used '^' (as an operator on a token, not in the
> > rewrite itself) as well as rewrites in your element element rule.
> Your
> > atom and ebnf rules also mix rewrites and AST operators.
> > Due to the lack of location information these errors can be tricky
to
> > track down. Slowly removing (or adding to a new grammar) rules until
> > you find the error can help. Though due to dependencies between
rules
> > this can be tricky.
> > Another trick is to introduce the other sort of error, either a !
> > (tokenRefBangTrack.st error) or a ^ (tokenRefRuleRootTrack.st error)
> > in a rule with rewrites. For instance, as you have a ^ error adding
a
> > ! to a rule before the (first) rule giving the error will change the
> > error given to a tokenRefBangTrack.st error, by moving the location
> > where you insert the error through your grammar until the message
> does
> > not change you can locate the error.
> > I assume these errors will be better dealt with when Ter migrates to
> > an ANTLR 3 grammar in the tool.
> >
> > Tom.
> >
> 
> Thanks! That was it. Now only ambiguities have to be dealt with. Is it
> guaranteed that with backtracking and memoization the correct parse
> tree
> will be generated, or do exist situations where things have be
manually
> solved?
> 
> Best regards,
> Johannes Luber


More information about the antlr-interest mailing list