Ejemplo n.º 1
0
        protected override Value Invoke()
        {
            Value exprV = expression.Evaluate();

            if (exprV.Type != ValType.Boolean)
            {
                throw new CompilerException(Line, 217, "condition", "IF", "Boolean", exprV.TypeString);
            }

            while (expression.Evaluate().BoolValue)
            {
                Value returnValue = block.Evaluate();
                if (returnValue != Value.VOID)
                {
                    if (returnValue == Value.BREAK)
                    {
                        return(Value.VOID);
                    }
                    else if (returnValue.Type == ValType.Return)
                    {
                        // return early from this block if value is a return statement
                        return(returnValue.ReturnValue);
                    }
                }
            }

            return(Value.VOID);
        }
Ejemplo n.º 2
0
        public Boolean RunTest()
        {
            try
            {
                GlobalMemory.Clear();

                var sStream = new ANTLRStringStream(input);
                var lexer   = new SGLLexer(sStream);

                var tStream = new CommonTokenStream(lexer);

                // Parsing
                var parser = new SGLParser(tStream);
                var t      = (CommonTree)parser.main().Tree;

                // Printing tree
                Console.WriteLine("; " + t.ToStringTree());

                // TreeWalking
                var treeStream = new CommonTreeNodeStream(t);

                var          tw       = new SGLTreeWalker(treeStream, true);
                AbstractNode returned = tw.main();
                returned.Evaluate();

                if (debug)
                {
                    realOutput = GlobalMemory.Instance.DebugString;
                }
                else
                {
                    realOutput = GlobalMemory.Instance.StoryboardCode.ToString();
                }

                // comparison
                realOutput = realOutput.Trim();
                output.Trim();

                if (output.Equals(realOutput))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (CompilerException ce)
            {
                Console.WriteLine(ce.GetExceptionAsString());
                return(false);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Es ist ein Fehler aufgetreten.");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                return(false);
            }
        }
Ejemplo n.º 3
0
    private NodeStates EvaluateFromIndex(int startingIndex)
    {
        for (int i = startingIndex; i < nodes.Length; i++)
        {
            AbstractNode node = nodes[i];

            switch (node.Evaluate())
            {
            //if a node returns running set currentRunningNodeIndex to that nodes index in the child list
            case NodeStates.RUNNING:
                currentRunningNodeIndex = i;
                NodeState = NodeStates.RUNNING;
                return(NodeState);

            //if a node returns success reset currentRunningNodeIndex
            case NodeStates.SUCCESS:
                currentRunningNodeIndex = -1;
                NodeState = NodeStates.SUCCESS;
                return(NodeState);

            case NodeStates.FAILURE:
                break;
            }
        }
        //if all nodes returns failure reset currentRunningNodeIndex
        currentRunningNodeIndex = -1;
        NodeState = NodeStates.FAILURE;
        return(NodeState);
    }
Ejemplo n.º 4
0
        protected override Value Invoke()
        {
            Value value = expression.Evaluate();

            var indexValues = new List <Value>();

            foreach (AbstractNode indexNode in indexes)
            {
                indexValues.Add(indexNode.Evaluate());
            }

            foreach (Value index in indexValues)
            {
                if (!index.TypeEquals(ValType.Integer))
                {
                    throw new CompilerException(Line, 214, index.TypeString);
                }
                else if (value.Type != ValType.List /* || value.IsString()*/)
                {
                    throw new CompilerException(Line, 215, value.TypeString);
                }

                int idx = index.IntValue;
                value = value.ListValue[idx];
            }

            return(value);
        }
        protected override Value Invoke()
        {
            Value value1 = node1.Evaluate();
            Value value2 = node2.Evaluate();
            Value value3 = node3.Evaluate();

            ValType type1 = value1.Type;
            ValType type2 = value2.Type;
            ValType type3 = value3.Type;

            if (CheckArguments(type1, type2, type3))
            {
                try
                {
                    return(Operate(value1, value2, value3, type1, type2, type3));
                }
                catch (CompilerException sce)
                {
                    // Catch all CompilerExceptions and add the line number.
                    sce.Line = Line;
                    throw;
                }
            }
            else
            {
                throw new CompilerException(Line, 203, Name, value1.TypeString, value2.TypeString, value3.TypeString);
            }
        }
        protected override Value Invoke()
        {
            Value exprV = expression == null ? Value.NULL : expression.Evaluate();

            if (indexes.Count < 1)
            {
                // a simple assignment
                //scope.SetSpriteGenerators(SpriteGenerators);
                scope.Assign(name, exprV);
            }
            else
            {
                // a possible list-lookup and reassignment
                Value list = scope.Resolve(name);

                // iterate up to `foo[x][y]` in case of `foo[x][y][z] = 42;`
                for (int i = 0; i < indexes.Count - 1 && list != null; i++)
                {
                    Value index = indexes[i].Evaluate();

                    if (!index.TypeEquals(ValType.Integer))
                    {
                        throw new CompilerException(line, 212, (i + 1).ToString(), name, index.TypeString);
                    }
                    else if (list.Type != ValType.List)
                    {
                        throw new CompilerException(line, 213, name, (i).ToString(), list.TypeString);
                    }

                    int position = index.IntValue;
                    list = list.ListValue[position];
                }
                // list is now pointing to `foo[x][y]` in case of `foo[x][y][z] = 42;`

                // get the value `z`: the last index, in `foo[x][y][z] = 42;`
                Value idx = indexes[indexes.Count - 1].Evaluate();

                if (!idx.TypeEquals(ValType.Integer))
                {
                    throw new CompilerException(line, 212, (indexes.Count).ToString(), name, idx.TypeString);
                }
                else if (list.Type != ValType.List)
                {
                    throw new CompilerException(line, 213, name, (indexes.Count - 1).ToString(), list.TypeString);
                }

                // re-assign `foo[x][y][z]`
                List <Value> existing = list.ListValue;
                // add elements if the index is out of range
                while (idx.IntValue >= existing.Count)
                {
                    existing.Add(Value.NULL);
                }
                existing[idx.IntValue] = exprV;
            }


            return(Value.VOID);
        }
        protected override Value Invoke()
        {
            Value value = node.Evaluate();

            return(Operate(value));

            //throw new CompilerException(Line, 201, Name, value.TypeString);
        }
Ejemplo n.º 8
0
        //public abstract bool CheckArguments(ValType type1, ValType type2);

        protected override Value Invoke()
        {
            Value value1 = node1.Evaluate();
            Value value2 = node2.Evaluate();

            return(Operate(value1, value2));

            //throw new CompilerException(Line, 202, Name, value1.TypeString, value2.TypeString);
        }
Ejemplo n.º 9
0
        protected override Value Invoke()
        {
            Value condValue = conditionNode.Evaluate();

            if (condValue.Type != ValType.Boolean)
            {
                throw new CompilerException(Line, 206, condValue.TypeString);
            }

            return(condValue.BoolValue ? ifNode.Evaluate() : elseNode.Evaluate());
        }
Ejemplo n.º 10
0
        protected override Value Invoke()
        {
            Value exprV = expression.Evaluate();

            if (exprV.TypeEquals(ValType.Integer))
            {
                ((BlockNode)block).AddOffset(exprV.IntValue);
                // Execute the block
                return(block.Evaluate());
            }
            else
            {
                throw new CompilerException(Line, 217, "offset", "AT", "Integer/Double", exprV.TypeString);
            }
        }
Ejemplo n.º 11
0
        protected override Value Invoke()
        {
            /*
             * Console.WriteLine("init: " + init.Evaluate());
             * Console.WriteLine("cond: " + condition.Evaluate());
             * Console.WriteLine("iteration: " + iteration.Evaluate());
             */

            //Console.WriteLine("--------------------------------------");
            for (EvaluateInit(); condition.Evaluate().BoolValue; iteration.Evaluate())
            {
                block.Evaluate();
            }

            return(Value.VOID);
        }
Ejemplo n.º 12
0
    public override NodeStates Evaluate()
    {
        if (_constructed)
        {
            CalculatePlanValue();
            CalculateRiskValue();
            CalculateTimeInterval();

            if (currentlyRunningNode != null)
            {
                switch (currentlyRunningNode.Evaluate())
                {
                case NodeStates.RUNNING:
                    NodeState = NodeStates.RUNNING;
                    break;

                //if a node returns success reset currentlyRunningNode
                case NodeStates.SUCCESS:
                    currentlyRunningNode = null;
                    NodeState            = NodeStates.SUCCESS;
                    break;


                //if a node returns failure reset currentlyRunningNode
                case NodeStates.FAILURE:
                    currentlyRunningNode = null;
                    NodeState            = NodeStates.FAILURE;
                    break;
                }
                return(NodeState);
            }
            else
            {
                CalculateProbabilities();

                float random = UnityEngine.Random.Range(0f, 1f);

                for (int i = 0; i < nodeProbabilities.Length; i++)
                {
                    if (random < nodeProbabilities[i])
                    {
                        NodeState = nodes[i].Evaluate();
                        if (NodeState == NodeStates.RUNNING)
                        {
                            currentlyRunningNode = nodes[i];
                        }
                        break;
                    }
                    else
                    {
                        random -= nodeProbabilities[i];
                    }
                }
                return(NodeState);
            }
        }
        else
        {
            Debug.LogError("Node not constructed!");
            return(NodeStates.FAILURE);
        }
    }
Ejemplo n.º 13
0
        protected override Value Invoke()
        {
            Value exprVal = expression.Evaluate();

            return(new Value(exprVal, ValType.Return));
        }