[antlr-interest] Fundamental tree parsing question

Ted Villalba ted.villalba at gmail.com
Wed Jul 11 08:55:35 PDT 2007


Wow. Thanks Benjamin. That gave me a lot of new insight into the rewrite
rules.
It builds a nice parse tree, but fails with a NullPointerException when
trying to generate the AST.
Although I've been avoiding it, maybe it's time for me to start stepping
through the java code. Would this be your approach to resolving this, or how
would one go about debugging this particular issue?
The exception:
08:37:45] java.lang.NullPointerException
    at org.antlr.works.debugger.tree.DBASTModel$ASTNode.becomeParent(Unknown
Source)
    at org.antlr.works.debugger.tree.DBASTModel.becomeRoot(Unknown Source)
    at org.antlr.works.debugger.Debugger.playerBecomeRoot(Unknown Source)
    at org.antlr.works.debugger.tivo.DBPlayer.playBecomeRoot(Unknown Source)
    at org.antlr.works.debugger.tivo.DBPlayer.playEvent(Unknown Source)
    at org.antlr.works.debugger.tivo.DBPlayer.playEvents(Unknown Source)
    at org.antlr.works.debugger.Debugger.playEvents(Unknown Source)
    at org.antlr.works.debugger.tivo.DBRecorder.playEvents(Unknown Source)
    at org.antlr.works.debugger.tivo.DBRecorder$PlayEventRunnable.run(Unknown
Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)


Thanks a millionX for the assistance.

Ted

On 7/11/07, Benjamin Niemann <pink at odahoda.de> wrote:
>
> Benjamin Niemann wrote:
>
> > Ted Villalba wrote:
> >
> >> I thought I would reuse this thread since it seems a similar issue, or
> >> misunderstanding on my part...
> >>  When I add a rewrite specification to my grammar rule it suddenly
> fails
> >> with a .RewriteEmptyStreamException.
> >>  The full grammar is below, but here is what I think it boils down to -
> >>  I'm
> >> not sure how to represent zero or more instances in the rewrite of an
> >> operator when it is the root node .
> >> For example, the following grammar is parsed successfully and
> ANTLRWorks
> >> builds a flat tree.
> >> value   : terms ((WS)+ operator^ (WS)+ value)*
> >>
> >> But when I try to add the following rewrite specification, I get the
> >> exception:
> >> value : terms ((WS)+ operator (WS)+ value)* -> ^(operator ^(TERMS
> terms)
> >> ^(VALUE value)*)
> >
> > The correct way to translate these AST operators to rewrite rules should
> > be:
> >
> > value:
> >    (terms -> terms)
> >    (
> >      (WS)+ operator (WS)+ v=value
> >      -> ^(operator $value $v)
> >    )*
> >    ;
> >
> > The first $value refers to the current tree as it has been built so far.
> > Upon each iteration of the loop a tree is built using the current tree
> as
> > the first child and $v as the second. The result becomes the first child
> > in the next iteration and so on...
>
> And then add your imaginary nodes:
>
> value:
>    (terms -> ^(TERMS terms))
>    (
>      (WS)+ operator (WS)+ v=value
>      -> ^(operator $value ^(VALUE $v))
>    )*
>    ;
>
> --
> Benjamin Niemann
> Email: pink at odahoda dot de
> WWW: http://pink.odahoda.de/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070711/91ab7c1c/attachment.html 


More information about the antlr-interest mailing list