[antlr-interest] Grouping the parsed data

Monty Zukowski monty at codetransform.com
Mon Mar 7 08:20:45 PST 2005


Marcel Cerveny wrote:
> Hello there!
> 
> After a while of really pleasant work with antlr I bumped into one problem.
> I do a parsing of quite general source files, which describe
> interfaces. However one of the requirements is to have a freedom of
> placing say other used interfaces, meaning one interface source could
> look like:
> public interface ITest {
>   using John, Paul;
>   const int aaa = 1;
>   int bbb;
>   using George, Ringo;
>   int ccc();
> }
> 

I'm sure the syntax isn't right, but you should get the idea.  In your 
interface rule create a tree to populate and pass it as an argument to 
the using rule:

interface:
	{AST usingTree = #(USING);}
	...
	| using[usingTree]
	...
;

using[AST usingTree]!:
	"using" i:ID {#usingTree.append(#i);} //not sure of actual method to 
append a node off the top of my head

;

MOnty


More information about the antlr-interest mailing list