Fwd: [antlr-interest] Qes: How to control AST- Combine multi-rules
into one
Jose Ventura
jose.ventura.roda at gmail.com
Fri Jun 16 00:19:43 PDT 2006
Try this:
functioncall_paras :
OPEN_PAREN!
{String rtn="";}
: ( oa:one_argu! {rtn = "(" + #oa.getText() ;}
( COMMA! ob:one_argu! {rtn=rtn +","+#ob.getText();}
)*
)?
CLOSE_PAREN!
{
if (#oa!=null)
## = #( #[FUNCTIONCALL_PARAS, rtn] ,##);
}
}
;
I believe this will be ok.
Regards
---------- Forwarded message ----------
From: Charlie Yang <Cyang at infobal.com>
Date: Jun 15, 2006 11:45 PM
Subject: [antlr-interest] Qes: How to control AST- Combine multi-rules into
one
To: "antlr-interest at antlr.org" <antlr-interest at antlr.org>
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060616/3d287f3f/attachment.html
More information about the antlr-interest
mailing list