[antlr-interest] Problems with Antlr3 rewrite rules

Shmuel Siegel ssiegel at finjan.com
Sun Jun 17 01:58:26 PDT 2007


Thanks Jim,

You motivated me to look at the theoretical meaning behind what I was
trying to do. Obviously, despite what my code asked for, one can't make
a subtree the root of another subtree. Where will the new children be
placed? That said, I believe that the old behavior was better, i.e., it
is better to put the new nodes at the end of the subtree of the old head
than to replace the subtree. So I would call this a low priority bug;
antlr did something which I consider wrong when I do something that
confuses it.

But now that I understand what is happening, there is a workaround. I
can make a new subtree that has the old subtree and the new nodes as
children. Thanks again for helping me think.

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jim Idle
Sent: Wednesday, June 06, 2007 6:29 PM
To: shmuel siegel; antlr-interest at antlr.org
Subject: Re: [antlr-interest] Problems with Antlr3 rewrite rules

....

The best thing to do is to debug the generated code in say Netbeans, so
you can see why you are getting the null pointers and where the tree is
being replaced by the imaginary token. Sometimes you can make things go
away by experimenting with your grammar as in 1) below, so I presume you
can work with that for a while? It may will be that the behavior you are
seeing in 2) is actually what you should expect and what you were
getting previously was an accident.

....

Jim



> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of shmuel siegel
> Sent: Wednesday, June 06, 2007 4:45 AM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Problems with Antlr3 rewrite rules
> 
> We've been told that this mail list is the triage for bug reports.
This
> patient has been languishing in triage for three days. There hasn't
> even
> been any placebos offered. Has there been a specification change? Is
> there one or more bugs here? As I stated, I have a workaround for the
> first issue but none for the second issue.
> 
> I would really like to move up to the release version but these two
> issues are standing in my way. Can I get some help.
> 
> shmuel siegel wrote:
> > It seems that the problems were introduced with the move to
> > RewriteRuleSubtreeStream. I don't see any other substantive changes
> in
> > the generated parser code.
> >
> > Shmuel Siegel wrote:
> >>
> >> I have upgraded my production grammar from 3.0b6 to the release
> >> version. I am having two problems with the rewrite rules. Hopefully
> I
> >> just missed a specification change.
> >>
> >>
> >>
> >>     * Problem 1: When I have subclauses that do rewrites, the final
> >>       rewrite gets a null pointer exception. The following rule
used
> >>       to work but now throws an exception. I avoid the exception if
> I
> >>       extract the parenthesized sub-rule and make it a named rule.
> >>
> >> assignEntityAttr:
> >>
> >>             (
> >>
> >>                         thisNode->thisNode
> >>
> >>                   |     symbolTableElement->symbolTableElement
> >>
> >>                   |     positionalElement->positionalElement
> >>
> >>             )
> >>
> >>             '.' a='attr' op='=' attr=attrValue
> >>             -> ^(ASSIGN[$op] ^($assignEntityAttr PROPERTY[$a])
> $attr)
> >>
> >>             ;
> >>
> >>
> >>
> >>     * Problem 2: Tree construction seems to have changed. I used to
> be
> >>       able to write
> >>           o ^($ent PROPERTY[$a]) where $ent was itself a tree. When
> I
> >>             do it now, I keep the head of the $ent tree but its
> >>             children are replaced by the PROPERTY token.
> >>
> >>
> >>
> >>
> >>
> >> What has changed since b6?
> >>
> >>
> >>
> >> Shmuel
> >>
> >
> >
> 




More information about the antlr-interest mailing list