[antlr-interest] Tree grammar rule attributes

Peter Piper peterpiper797 at hotmail.com
Tue Feb 7 01:32:33 PST 2012


To workaround another problem (posted yesterday), I'm trying to get access to the CommonTree from within a rule inside my tree grammar.

The ANTLR rule:

            myRule : subRule1 subRule2  { doSomething($arguments.tree); } ;

compiles OK in ANTLR but produces an error in the C# compiler because it has declared arguments like this in the C#:

            TreeRuleReturnScope<CommonTree> arguments = ....

but it tries to use it like this:

   doSomething( (arguments!=null?((CommonTree)arguments.Tree):default(CommonTree)) );

Unfortunately, TreeRuleReturnScope<> only has properties called Start and Stop, not a property called Tree.

Surely this system must have worked at some point? How do you guys do this stuff?

Dan

 		 	   		  


More information about the antlr-interest mailing list