dcsimg
I want to compute the result of #(PLUS A B C D)
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, July 28, 2005 12:04 PM

I want to compute the result of #(PLUS A B C D)... In a binary tree where the above expression would be of the form : #(PLUS A #(PLUS B #(PLUS C D))), the rule : expr returns [float r] { float a,b; r=0; } : #(PLUS a=expr b=expr) {r = a+b;} | #(STAR a=expr b=expr) {r = a*b;} | i:INT {r = atof(i->getText().c_str());} ; would do. If I don't know how many children the root node has and that I want to store the result of each node in a vector cell, how can I proceed ? The rule would be something like : #(PLUS (expr)*) Plus, I have to pas   More>>

I want to compute the result of #(PLUS A B C D)...


In a binary tree where the above expression would be of the form :

			
#(PLUS A #(PLUS B #(PLUS C D))),


the rule :

			
expr returns [float r]
{
float a,b;
r=0;
}
: #(PLUS a=expr b=expr) {r = a+b;}
| #(STAR a=expr b=expr) {r = a*b;}
| i:INT {r = atof(i->getText().c_str());}
;


would do.


If I don't know how many children the root node has and that I want to store the result of each node in a vector cell, how can I proceed ?

The rule would be something like :

			
#(PLUS (expr)*)


Plus, I have to pass parameters to the expr subrule like :

			
#(PLUS a=expr[searchedKeywords]
b=expr[searchedKeywords])


Any info would be greatly appreciated !    <<Less
About | Sitemap | Contact