Ejemplo n.º 1
0
        //Unless instead of attribute, I just pass in the SyntaxTree so it knows where to look, that way I could possible reuse nodes. That might be better
        public bool didPass(DataStructureLanguage.Syntax.Util.SyntaxTree syntaxTree)
        {
            //These event starts only need to be here cause all share same didPass method
            OnBeginExecuting();
            //      IsExecuting();

            //These meant to be temporary variables just to hold either the number or variable stored in SyntaxTree, and this way I can just move logic to function to avoid
            //duplicate code
            Variable one, two;

            //Here check if the strings are numeric, if they are then just number, otherwise check for variable name in dictionary.
            try
            {
                one = DataStructureLanguage.Syntax.Util.UtilMethods.ValidateOperand(condition.FirstOperand, syntaxTree);
                two = DataStructureLanguage.Syntax.Util.UtilMethods.ValidateOperand(condition.SecondOperand, syntaxTree);
            }
            catch (System.Exception e)
            {
                throw e;
            }



            //Does actual operation, returning the result. Todo: Do same in assignment node.
            return(Operators.logicalOperations[condition.Operation](one, two));
        }
        public override void execute(DataStructureLanguage.Syntax.Util.SyntaxTree programToLookIn)
        {
            //Prob best as coroutine tbh
            OnBeginExecuting();

            Variable two;
            int      res;

            IsExecuting();
            //Here check if the strings are numeric, if they are then just number, otherwise check for variable name in dictionary.
            try
            {
                //   one = DataStructureLanguage.Syntax.Util.UtilMethods.ValidateOperand(firstOperand, programToLookIn);
                two = DataStructureLanguage.Syntax.Util.UtilMethods.ValidateOperand(secondOperand, programToLookIn);
            }
            catch (System.Exception e)
            {
                throw e;
            }

            //That's it for now
            if (int.TryParse(firstOperand, out res))
            {
                throw new KeyNotFoundException("You cannot assign to a literal");
            }
            //Two variable doesn't matter if literal or variable
            if (programToLookIn.variables.ContainsKey(firstOperand))
            {
                programToLookIn.variables[firstOperand].Value = two.Value;
            }
            else
            {
                programToLookIn.variables[firstOperand]       = new Variable(firstOperand);
                programToLookIn.variables[firstOperand].Value = two.Value;
            }
        }
 // Use this for initialization
 void Start()
 {
     DataStructureLanguage.Syntax.Util.SyntaxTree tree = new DataStructureLanguage.Syntax.Util.SyntaxTree();
 }
Ejemplo n.º 4
0
    //Scans the code base
    public void scan()
    {
        //Always skip the root cause just placeholder for me.

        VisualNode current = root;
        //To keep track of bodies.
        Stack <BlockVisual> frames      = new Stack <BlockVisual>();
        List <int>          lineNumbers = new List <int>();

        lineNumbers.Add(0);
        compiled = new DataStructureLanguage.Syntax.Util.SyntaxTree();
        //Representing how many levels deep lineNumber is in, basically the index.
        int lineDimension = 0;

        while (lineDimension > -1)
        {
            VisualNode next;

            if (current is BlockVisual && current != root)
            {
                next = ((BlockVisual)current).nextNode();
                //If next node of block is null, then go to next body
                if (next == null)
                {
                    next = current.Next;
                }
            }
            else
            {
                next = current.Next;
            }

            if (next is BlockVisual)
            {
                frames.Push((BlockVisual)next);

                lineDimension += 1;

                if (lineDimension >= lineNumbers.Count)
                {
                    lineNumbers.Add(0);
                }

                current = next;
            }
            else if (next == null)
            {
                if (frames.Count > 0)
                {
                    current = frames.Peek();
                    frames.Pop();
                    continue;
                }
                else
                {
                    break;
                }

                //Reset that spot for the next time enter new body.
                lineNumbers[lineDimension] = 0;

                lineDimension--;
            }
            else
            {
                lineNumbers[lineDimension]++;
                current = next;
            }

            SyntaxNode syntaxNode = constructSyntaxNode(current);
            if (syntaxNode != null)
            {
                //Subscribing event of highlighting the corresponding VisualNode when the that SyntaxNode is executed.
                //So both got highlight event, No i got it... It's a thread issue
                syntaxNode.onBeginExecuting += current.highlight;
                syntaxNode.onDoneExecuting  += current.unhighlight;


                //What happens when you take breaks in between dev. I don't need to backtrace, the last added BlockVisual is the body of this current node.
                //BlockVisual block = getOwningBody(syntaxNode);

                syntaxNode.id = current.gameObject.name;

                if (current is BlockVisual)
                {
                    BlockVisual block = (frames.Count > 0) ? frames.Peek() : null;

                    if (block == null || block.ID == "else")
                    {
                        compiled.add(syntaxNode, lineNumbers, lineDimension, true);
                    }
                    else
                    {
                        compiled.add(syntaxNode, lineNumbers, lineDimension);
                    }
                }
                else
                {
                    Debug.Log("Successfuly made Syntax Node for " + current.gameObject.name);
                    compiled.add(syntaxNode, lineNumbers, lineDimension);
                }
            }
        }

        Debug.Log("Done executing");
    }