[antlr-interest] empty tree assertion rule
whaefelinger
ora.et.labora at web.de
Wed Oct 13 07:25:29 PDT 2004
Hi,
being a newbee to antlr and it's abilities I'm always bit afraid to
"forget" to visit parts of a generated AST when formulating rules on
how to walk the tree within the tree parser.
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 rule would then be used like this:
expr returns [float r]
{
float a,b;
a=b=0;
r=0;
}
: #(PLUS a=expr b=expr nullp) { r = a+b; }
;
That means that my parser would generate an (unexpected)
expr like
(+ 1 2 3)
I would get this reported.
Of course the parser just generates this bad expr only
if there's something wrong with the grammar. So when
releasing the parser, the "nullp" rule should be removed
for efficency.
Now for the question:
Q1: does something like 'nullp' already exist and I'm just
not aware of?
Q2: is there absolutly no need for 'nullp' because I missed
the point?
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