Ejemplo n.º 1
0
 public void AddChild(MultiTreeNode <T> child)
 {
     child.Parent   = this;
     child._sibling = _child;
     _child         = child;
     Count++;
 }
Ejemplo n.º 2
0
 public MultiTreeNode(T data, MultiTreeNode <T> parent = null)
 {
     Data     = data;
     Parent   = parent;
     _sibling = parent;
     _child   = this;
 }
Ejemplo n.º 3
0
        internal static Container Interpret(ICodeBlock context, MultiTreeNode <Value> line)
        {
            switch (line.Data.Type)
            {
            case ValueType.Function when line.Data.Val is string fname:
                if (fname == "=" && line.PeekChild().Data.Type == ValueType.Variable)
                {
                    context.SetVariable(line.PeekChild().Data.Val as string,
                                        Interpret(context, line.PeekChild().PeekSibling()).value);
                    return(null);
                }
                else
                {
                    return(Library.Functions[fname]
                               (line.GetChildren().Select(v => Interpret(context, v)).ToList()));
                }

            case ValueType.Value:
                return(new Container(line.Data.Val));

            case ValueType.Variable when line.Data.Val is string vname:
                return(context.GetVariable(vname));

            default:
                return(null);
            }
        }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        public MultiTreeNode <T> PopChild()
        {
            var c = _child;

            if (c == this)
            {
                return(null);
            }

            _child = _child._sibling;
            Count--;
            return(c);
        }
Ejemplo n.º 7
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);
        }