[antlr-interest] nullAST

Chris Black cblack0 at yahoo.com
Thu May 13 14:22:00 PDT 2004


I've been looking at the examples from:
http://wwwhome.cs.utwente.nl/~klaren/antlr/treebuilding.txt

and notice syntax like:
r1_manual:!	{ ## = nullAST; }
		e1:x { ## = #(nullAST,##,#e1); } // add x as a sibling
		e2:y { ## = #(nullAST,##,#e2); } // add y as a sibling
		e3:z { ## = #(nullAST,##,#e3); } // add z as a sibling

but when I try to use nullAST, it fails. I am also unable to do:
dataStanza:! FIELD DELIM dt:FIELD! NEWLINE
	a:recordLine { ## = #a; } 
        (b:recordLine { ##->addChild(#b); } )+ 
	{ 
		if(dt.getText().equals("Foo")) 
			## = #([STANZA, dt.getText()], ##);
	}
	;

Because AST->addChild(AST) doesn't compile correctly.
(I get: Exception in thread "main" java.lang.Error: Unresolved
compilation problem: Invalid expression as statement)

What I am trying to do is only construct a dataStanza tree when the
dt:FIELD token has a certain string.

I don't see a way other than building up the (foo)+ parts of the tree
during match (since it is not just one token), and then having a
conditional at the end of the rule that either returns a null tree or
a slight modification of the tree that has been constructed so far.

Maybe I should just construct a full tree and skip over it in the tree
parser, but I thought this might be better.



 
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