Optional parameterList

Mar 7, 2012 at 5:50 PM
Edited Mar 7, 2012 at 5:53 PM

Hello

I am implementing a function call syntax with a variable number of parameters as input, like this:

f(1), f(1,2), f(1,2,3), and so on

this is my implementation:

firstParameter.Rule = simpleExpression;
additionalParameters.Rule = MakeStarRule(additionalParameters, "," + simpleExpression);
parameterList.Rule = "(" + firstParameter + additionalParameters + ")";
nAryExpression.Rule = nAryOperator + parameterList;

It works, but in the AST i find several "UnnamedX" nodes i would like to mark as transient.
How can i do that?
Thank you very much!!!
 Esteban.
Coordinator
Mar 8, 2012 at 4:07 PM

why you do all these "firstParameter", "additionalParameter", etc? why not simply a plus-list of a parameter?

Mar 8, 2012 at 6:57 PM
Edited Mar 9, 2012 at 4:42 AM

Esteban,

To Roman's point,

The MakeStarRule is for 0 or More expressions, while the MakePlusRule is for 1 or More.  So, you can consolidate your logic to something like the following:

parameterList.Rule = MakeStarRule(parameters, ",", simpleExpression);  // If I recall correctly, the delimiter (",") is a parameter for the MakeStarRule & MakePlusRule functions - my order may be wrong
nAryExpression.Rule = nAryOperator + "(" + parameterList + ")";

Regards,

MindCore