public static SteExpression ResetAsOperator(this SteExpression expr, SteOperatorSpecs opHeadSpecs, params SteExpression[] args) { var headSpecs = opHeadSpecs; expr.Reset(headSpecs, args); return(expr); }
public static SteExpression ResetAsOperator(this SteExpression expr, SteOperatorSpecs opHeadSpecs, IEnumerable <SteExpression> args) { var headSpecs = opHeadSpecs; expr.Reset(headSpecs, args); return(expr); }
public static SteExpression ResetAsArrayAccess(this SteExpression expr, string arrayName, IEnumerable <SteExpression> args) { var headSpecs = new SteArrayAccessHeadSpecs(arrayName); expr.Reset(headSpecs, args); return(expr); }
public static SteExpression ResetAsFunction(this SteExpression expr, string funcName, IEnumerable <SteExpression> args) { var headSpecs = new SteFunctionHeadSpecs(funcName); expr.Reset(headSpecs, args); return(expr); }
/// <summary> /// Add the given argument to this expression /// </summary> /// <param name="arg"></param> /// <returns>The argument that was added to this expression</returns> public SteExpression AddArgument(SteExpression arg) { if (ReferenceEquals(_argsList, null)) { throw new InvalidOperationException("Cannot add an argument to an atomic expression"); } _argsList.Add(arg); return(this); }
/// <summary> /// Insert a copy of the given argument into this expression /// </summary> /// <param name="index"></param> /// <param name="expr"></param> /// <returns>The argument that was added to this expression</returns> public SteExpression InsertCopy(int index, SteExpression expr) { if (ReferenceEquals(_argsList, null)) { throw new InvalidOperationException("Cannot add an argument to an atomic expression"); } var arg = expr.CreateCopy(); _argsList.Insert(index, arg); return(arg); }
/// <summary> /// Insert the given argument into this expression /// </summary> /// <param name="index"></param> /// <param name="arg">The argument that was inserted into this expression</param> /// <returns></returns> public SteExpression InsertArgument(int index, SteExpression arg) { if (ReferenceEquals(_argsList, null)) { throw new InvalidOperationException("Cannot add an argument to an atomic expression"); } _argsList.Insert( index, arg ); return(arg); }
public static SteExpression ResetAsOperator(this SteExpression expr, SteOperatorSpecs opHeadSpecs, bool clearArgs = true) { var headSpecs = opHeadSpecs; if (clearArgs) { expr.Reset(headSpecs); } else { expr.ResetHead(headSpecs); } return(expr); }
public static SteExpression ResetAsArrayAccess(this SteExpression expr, string arrayName, bool clearArgs = true) { var headSpecs = new SteArrayAccessHeadSpecs(arrayName); if (clearArgs) { expr.Reset(headSpecs); } else { expr.ResetHead(headSpecs); } return(expr); }
public static SteExpression ResetAsFunction(this SteExpression expr, string funcName, bool clearArgs = true) { var headSpecs = new SteFunctionHeadSpecs(funcName); if (clearArgs) { expr.Reset(headSpecs); } else { expr.ResetHead(headSpecs); } return(expr); }
/// <summary> /// Find all instances of the given oldExpr inside this text expression tree /// and replace them with a variable symbol expression of newVarName. The search is done once and /// only instances near the leaf of the tree are replaced (i.e. one search-replace iteration over the tree) /// </summary> /// <param name="oldExpr"></param> /// <param name="newVarName"></param> public SteExpression ReplaceAllByVariableInPlace(SteExpression oldExpr, string newVarName) { if (this == oldExpr) { return(this.ResetAsVariable(newVarName)); } if (IsAtomic) { return(this); } foreach (var subExpr in _argsList) { subExpr.ReplaceAllByVariableInPlace(oldExpr, newVarName); } return(this); }
/// <summary> /// Find all instances of the given oldExpr inside this text expression tree /// and replace them with a copy of newExpr. The search is done once and only instances near the /// leaf of the tree are replaced (i.e. one search-replace iteration over the tree) /// </summary> /// <param name="oldExpr"></param> /// <param name="newExpr"></param> /// <returns></returns> public SteExpression ReplaceAllInPlace(SteExpression oldExpr, SteExpression newExpr) { if (SyntaxTreeUtils.Equals(this, oldExpr)) { ResetAsCopy(newExpr); return(this); } if (IsAtomic) { return(this); } foreach (var subExpr in _argsList) { subExpr.ReplaceAllInPlace(oldExpr, newExpr); } return(this); }
/// <summary> /// Reset the head and arguments of this expression as a copy of the given expression /// </summary> /// <param name="expr"></param> /// <returns></returns> public SteExpression ResetAsCopy(SteExpression expr) { HeadSpecs = expr.HeadSpecs; if (expr.IsAtomic) { _argsList = null; return(this); } _argsList = new List <SteExpression>(expr._argsList.Count); for (var i = 0; i < expr._argsList.Count; i++) { _argsList.Add( expr._argsList[i].CreateCopy() ); } return(this); }
public static SteExpression AddLiteralNumbers(this SteExpression expr, params float[] numbersList) { return(expr.AddArguments(numbersList.Select(CreateLiteralNumber))); }
public static SteExpression InsertOperator(this SteExpression expr, int index, SteOperatorSpecs head, IEnumerable <SteExpression> args) { return(expr.InsertArgument(index, CreateOperator(head, args))); }
public static SteExpression InsertFunction(this SteExpression expr, int index, string head, IEnumerable <SteExpression> args) { return(expr.InsertArgument(index, CreateFunction(head, args))); }
public static SteExpression InsertFunction(this SteExpression expr, int index, string head) { return(expr.InsertArgument(index, CreateFunction(head))); }
public static SteExpression AddArrayAccess(this SteExpression expr, string head, IEnumerable <SteExpression> args) { return(expr.AddArgument(CreateArrayAccess(head, args))); }
public static SteExpression InsertLiteralNumbers(this SteExpression expr, int index, IEnumerable <double> numbersList) { return(expr.InsertArguments(index, numbersList.Select(CreateLiteralNumber))); }
public static SteExpression InsertVariables(this SteExpression expr, int index, params string[] varNamesList) { return(expr.InsertArguments(index, varNamesList.Select(CreateVariable))); }
public static SteExpression InsertLiteralNumber(this SteExpression expr, int index, string numberText) { return(expr.InsertArgument(index, CreateLiteralNumber(numberText))); }
public static SteExpression AddFunction(this SteExpression expr, string head, params SteExpression[] args) { return(expr.AddArgument(CreateFunction(head, args))); }
public static SteExpression AddOperator(this SteExpression expr, SteOperatorSpecs head, IEnumerable <SteExpression> args) { return(expr.AddArgument(CreateOperator(head, args))); }
public static SteExpression AddOperator(this SteExpression expr, SteOperatorSpecs head, params SteExpression[] args) { return(expr.AddArgument(CreateOperator(head, args))); }
public static SteExpression AddLiteralNumber(this SteExpression expr, float number) { return(expr.AddArgument(CreateLiteralNumber(number))); }
public static SteExpression InsertLiteralNumber(this SteExpression expr, int index, float number) { return(expr.InsertArgument(index, CreateLiteralNumber(number))); }
public static SteExpression AddLiteralNumbers(this SteExpression expr, IEnumerable <double> numbersList) { return(expr.AddArguments(numbersList.Select(CreateLiteralNumber))); }
public static SteExpression InsertLiteralNumbers(this SteExpression expr, int index, params float[] numbersList) { return(expr.InsertArguments(index, numbersList.Select(CreateLiteralNumber))); }
public static SteExpression InsertVariable(this SteExpression expr, int index, string varName) { return(expr.InsertArgument(index, CreateVariable(varName))); }
public static SteExpression AddArrayAccess(this SteExpression expr, string head, params SteExpression[] args) { return(expr.AddArgument(CreateArrayAccess(head, args))); }