예제 #1
0
        private void OnClosingBracket()
        {
            var funcNode = new MultiTreeNode <Value>(new Value(ValueType.Function, null));

            while (OperationsStack.Peek() != "(")
            {
                if (EvalOperator() == ",")
                {
                    funcNode.AddChild(OperandsStack.Pop());
                }
            }

            OperationsStack.Pop();

            if (OperationsStack.Count > 0 && Library.IsFunction(OperationsStack.Peek()))
            {
                funcNode.Data.Val = OperationsStack.Pop();
                OperandsStack.Push(funcNode);
                return;
            }

            if (funcNode.Count > 0)
            {
                funcNode.Data.Val = "MkTuple";
                OperandsStack.Push(funcNode);
            }
        }
예제 #2
0
        private void OnClosingSquareBracket()
        {
            var funcNode = new MultiTreeNode <Value>(new Value(ValueType.Function, null));

            while (OperationsStack.Peek() != "[")
            {
                if (EvalOperator() == ",")
                {
                    funcNode.AddChild(OperandsStack.Pop());
                }
            }

            OperationsStack.Pop();

            if (OperationsStack.Count > 0 && OperationsStack.Peek() == "MkList")
            {
                funcNode.Data.Val = OperationsStack.Pop();
                OperandsStack.Push(funcNode);
                return;
            }

            if (OperationsStack.Count > 0 && OperationsStack.Peek() == "ByIdx")
            {
                funcNode.Data.Val = OperationsStack.Pop();
                funcNode.AddChild(OperandsStack.Pop());
                funcNode.AddChild(OperandsStack.Pop());
                OperandsStack.Push(funcNode);
                return;
            }
        }
예제 #3
0
        private string EvalOperator()
        {
            var op = OperationsStack.Pop();

            if (op == ",")
            {
                return(op);
            }

            if (!Library.Operators.ContainsKey(op))
            {
                throw new ArgumentException($"Expected operator, but was <{op}>");
            }

            var opNode = new MultiTreeNode <Value>(new Value(ValueType.Function, op));

            opNode.AddChild(OperandsStack.Pop());
            opNode.AddChild(OperandsStack.Pop());
            OperandsStack.Push(opNode);
            return(op);
        }