[antlr-interest] Qes: How to control AST- Combine multi-rules into one

Charlie Yang Cyang at infobal.com
Thu Jun 15 14:45:07 PDT 2006


Hi, All, I get a problem with AST handling:

for parsing a general function call like:
	......
	Foo("first", "2ndpara", 3);
	......

I can use rules like:
	...
	functioncall_paras :
		    OPEN_PAREN  (one_argu ( COMMA one_argu )*)? CLOSE_PAREN!
	...
 
the rule works fine. 

However, i don't know how to concatenate all argus text together in the AST.
I want all argument combine to single leaf node rather than one argu on leaf
node.
I can use "oa" and oc.getText() to get first argument's text. but how to get
the rest of "ob" , can between 0 to n?

 functioncall_paras! :
    OPEN_PAREN!  ( oa:one_argu ( COMMA ob:one_argu )*)? CLOSE_PAREN!	
    {
    	String rtn="";
    	if(#oa!=null){
    		rtn = "(" + #ae.getText() ;
	    	if(#ob != null){
			//????????? Qestion Here ????????????
	    		rtn=rtn +","+#ae2.getText();
	    	}

    	}
    	oa.setText(rtn);
    	#functioncall_paras=#oa;
    }
    ;

Thanks,

Charlie


More information about the antlr-interest mailing list