Ejemplo n.º 1
0
        public static SteExpression ResetAsOperator(this SteExpression expr, SteOperatorSpecs opHeadSpecs, params SteExpression[] args)
        {
            var headSpecs = opHeadSpecs;

            expr.Reset(headSpecs, args);

            return(expr);
        }
Ejemplo n.º 2
0
        public static SteExpression ResetAsOperator(this SteExpression expr, SteOperatorSpecs opHeadSpecs, IEnumerable <SteExpression> args)
        {
            var headSpecs = opHeadSpecs;

            expr.Reset(headSpecs, args);

            return(expr);
        }
Ejemplo n.º 3
0
        public static SteExpression ResetAsArrayAccess(this SteExpression expr, string arrayName, IEnumerable <SteExpression> args)
        {
            var headSpecs = new SteArrayAccessHeadSpecs(arrayName);

            expr.Reset(headSpecs, args);

            return(expr);
        }
Ejemplo n.º 4
0
        public static SteExpression ResetAsFunction(this SteExpression expr, string funcName, IEnumerable <SteExpression> args)
        {
            var headSpecs = new SteFunctionHeadSpecs(funcName);

            expr.Reset(headSpecs, args);

            return(expr);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        /// <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);
        }
Ejemplo n.º 12
0
        /// <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);
        }
Ejemplo n.º 13
0
        /// <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);
        }
Ejemplo n.º 14
0
 public static SteExpression AddLiteralNumbers(this SteExpression expr, params float[] numbersList)
 {
     return(expr.AddArguments(numbersList.Select(CreateLiteralNumber)));
 }
Ejemplo n.º 15
0
 public static SteExpression InsertOperator(this SteExpression expr, int index, SteOperatorSpecs head, IEnumerable <SteExpression> args)
 {
     return(expr.InsertArgument(index, CreateOperator(head, args)));
 }
Ejemplo n.º 16
0
 public static SteExpression InsertFunction(this SteExpression expr, int index, string head, IEnumerable <SteExpression> args)
 {
     return(expr.InsertArgument(index, CreateFunction(head, args)));
 }
Ejemplo n.º 17
0
 public static SteExpression InsertFunction(this SteExpression expr, int index, string head)
 {
     return(expr.InsertArgument(index, CreateFunction(head)));
 }
Ejemplo n.º 18
0
 public static SteExpression AddArrayAccess(this SteExpression expr, string head, IEnumerable <SteExpression> args)
 {
     return(expr.AddArgument(CreateArrayAccess(head, args)));
 }
Ejemplo n.º 19
0
 public static SteExpression InsertLiteralNumbers(this SteExpression expr, int index, IEnumerable <double> numbersList)
 {
     return(expr.InsertArguments(index, numbersList.Select(CreateLiteralNumber)));
 }
Ejemplo n.º 20
0
 public static SteExpression InsertVariables(this SteExpression expr, int index, params string[] varNamesList)
 {
     return(expr.InsertArguments(index, varNamesList.Select(CreateVariable)));
 }
Ejemplo n.º 21
0
 public static SteExpression InsertLiteralNumber(this SteExpression expr, int index, string numberText)
 {
     return(expr.InsertArgument(index, CreateLiteralNumber(numberText)));
 }
Ejemplo n.º 22
0
 public static SteExpression AddFunction(this SteExpression expr, string head, params SteExpression[] args)
 {
     return(expr.AddArgument(CreateFunction(head, args)));
 }
Ejemplo n.º 23
0
 public static SteExpression AddOperator(this SteExpression expr, SteOperatorSpecs head, IEnumerable <SteExpression> args)
 {
     return(expr.AddArgument(CreateOperator(head, args)));
 }
Ejemplo n.º 24
0
 public static SteExpression AddOperator(this SteExpression expr, SteOperatorSpecs head, params SteExpression[] args)
 {
     return(expr.AddArgument(CreateOperator(head, args)));
 }
Ejemplo n.º 25
0
 public static SteExpression AddLiteralNumber(this SteExpression expr, float number)
 {
     return(expr.AddArgument(CreateLiteralNumber(number)));
 }
Ejemplo n.º 26
0
 public static SteExpression InsertLiteralNumber(this SteExpression expr, int index, float number)
 {
     return(expr.InsertArgument(index, CreateLiteralNumber(number)));
 }
Ejemplo n.º 27
0
 public static SteExpression AddLiteralNumbers(this SteExpression expr, IEnumerable <double> numbersList)
 {
     return(expr.AddArguments(numbersList.Select(CreateLiteralNumber)));
 }
Ejemplo n.º 28
0
 public static SteExpression InsertLiteralNumbers(this SteExpression expr, int index, params float[] numbersList)
 {
     return(expr.InsertArguments(index, numbersList.Select(CreateLiteralNumber)));
 }
Ejemplo n.º 29
0
 public static SteExpression InsertVariable(this SteExpression expr, int index, string varName)
 {
     return(expr.InsertArgument(index, CreateVariable(varName)));
 }
Ejemplo n.º 30
0
 public static SteExpression AddArrayAccess(this SteExpression expr, string head, params SteExpression[] args)
 {
     return(expr.AddArgument(CreateArrayAccess(head, args)));
 }