[antlr-interest] empty tree assertion rule
Bryan Ewbank
ewbank at synopsys.com
Thu Oct 14 08:23:19 PDT 2004
> > So I came up with the idea to write a tree parser rule to ensure
> > that given input tree is empty:
> >
> > 001 nullp
> > 002 {
> > 003 if( #nullp != null ) {
> > 004 System.err.println("error: tree not empty!");
> > 005 System.exit(1);
> > 006 else {
> > 007 return;
> > 008 }
> > 009 }
> > 010 : #(INT INT)
> > 011 ;
This is marvelous! I will be using this to ensure total tree match, instead
of
partial. What I have is a production called <and_nothing_else> that looks
like
this:
251 and_nothing_else
252 :
253 ( node:.
254 {
255 cerr << "spurious node of type "
256 << node->getType()
257 << " ("
258 << getTokenName(node->getType())
259 << ") w/ text='"
260 << node->getText()
261 << "' detected in tree" << endl;
262 }
263 )*
264 ;
Now I just need to get the parent linkages, and I'll be able to show the
context in which the problem occurs.
Tree audits, here I come. In conjunction with adding a wildcard production
to the topmost rule (and ignoring the ambiguity) to detect unimplemented
node types, I think I can do this pretty cleanly.
Thanks again!
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list