This project has moved and is read-only. For the latest updates, please go here.

Optional parameterList

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


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!!!
Mar 8, 2012 at 5:07 PM

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

Mar 8, 2012 at 7:57 PM
Edited Mar 9, 2012 at 5:42 AM


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 + ")";