示例#1
0
        public override void Compile(CompiledStatement parent, string token, LinkedList <string> tokens, LinkedList <string> lines)
        {
            base.Compile(parent, token, tokens, lines);

            Delimiter.InlineToken = scriptToken;

            // Now check that there is another element after our keyword that we can use as the variable name
            Debug.Assert(tokens.Count > 0, "No value found for the right hand side of keyword: " + token);

            if (tokens.First.Value == FunctionKeyword.scriptToken)
            {
                // If we have a function after this, we do nothing - functions by default are added to the current local scope
                Delimiter.InlineToken = "";
                return;
            }

            // Get the next token that appears on the right hand side of this operator - this will be our variable name
            string rhsOfKeyword = CelesteCompiler.PopToken();

            Debug.Assert(!CelesteStack.CurrentScope.VariableExists(rhsOfKeyword), "Variable with the same name already exists in this scope");

            // Creates a new variable, but does not call Compile - Compile for variable assigns a reference from the stored variable in CelesteStack
            Variable variable = CelesteStack.CurrentScope.CreateLocalVariable <Variable>(rhsOfKeyword);

            // If we still have unparsed tokens, then add this variable to the tree
            // Otherwise, do not - we do not need to push an object onto the stack for no reason
            if (tokens.Count > 0)
            {
                // Add our variable underneath our parent - this keyword will do nothing at run time so do not add it to the tree
                parent.Add(variable);
            }
        }
示例#2
0
        public override void Compile(CompiledStatement parent, string token, LinkedList <string> tokens, LinkedList <string> lines)
        {
            base.Compile(parent, token, tokens, lines);

            Debug.Assert(parent.ChildCount > 0, "No value found for the left hand side of operator: " + token);

            // Take the previous statement and add it as a sub statement of the newly created operator - we will check for validity in the Compile function
            parent.MoveChildAtIndex(parent.ChildCount - 1, this);

            // Add this operator to the tree
            parent.Add(this);

            // Now check that there is another element after our operator that we can act on
            Debug.Assert(tokens.Count > 0, "No value found for the right hand side of operator: " + token);

            // Get the next token that appears on the right hand side of this operator
            string rhsOfOperatorToken = CelesteCompiler.PopToken();

            // Parse the next token which we will act on
            if (CelesteCompiler.CompileToken(rhsOfOperatorToken, parent))
            {
                // Take the value that has been added to the root and add it under this operator instead
                parent.MoveChildAtIndex(parent.ChildCount - 1, this);
            }
            else
            {
                // Error message if we cannot parse the next token
                Debug.Fail("Could not compile token: " + token + " in operator " + token);
            }
        }
示例#3
0
        public override void Compile(CompiledStatement parent, string token, LinkedList <string> tokens, LinkedList <string> lines)
        {
            base.Compile(parent, token, tokens, lines);

            // Now check that there is another element after our keyword that we can use as the variable name
            Debug.Assert(tokens.Count > 0, "No value found for the right hand side of keyword: " + token);

            // Get the next token that appears on the right hand side of this operator - this will be our variable name
            string rhsOfKeyword = CelesteCompiler.PopToken();

            if (rhsOfKeyword == FunctionKeyword.scriptToken)
            {
                Debug.Assert(tokens.Count > 0, "Function name must exist");
                string functionName = tokens.First.Value;
                functionName = functionName.Remove(functionName.IndexOf(OpenParenthesis.scriptToken));

                if (CelesteCompiler.CompileToken(rhsOfKeyword, parent))
                {
                    // If we have compiled our global function, we need to remove it from the current scope it is added to by default and move it to the global scope
                    Debug.Assert(CelesteStack.CurrentScope.VariableExists(functionName));
                    Variable function = CelesteStack.CurrentScope.RemoveLocalVariable(functionName);
                    CelesteStack.GlobalScope.AddLocalVariable(function);
                }
                else
                {
                    Debug.Fail("Error parsing global function");
                }

                return;
            }

            Debug.Assert(!CelesteStack.GlobalScope.VariableExists(rhsOfKeyword), "Variable with the same name already exists in this scope");

            // Creates a new variable, but does not call Compile - Compile for variable assigns a reference from the stored variable in CelesteStack
            Variable variable = CelesteStack.GlobalScope.CreateLocalVariable <Variable>(rhsOfKeyword);

            // If we still have unparsed tokens, then add this variable to the tree
            // Otherwise, do not - we do not need to push an object onto the stack for no reason
            if (tokens.Count > 0)
            {
                // Add our variable underneath our parent - this keyword will do nothing at run time so do not add it to the tree
                parent.Add(variable);
            }
        }
示例#4
0
        public override void Compile(CompiledStatement parent, string token, LinkedList <string> tokens, LinkedList <string> lines)
        {
            base.Compile(parent, token, tokens, lines);

            parent.Add(this);

            while (tokens.Count > 0)
            {
                // Get the next token that appears on the right hand side of this operator
                // This will be the name of the local variables we wish to return
                string rhsOfKeyword = CelesteCompiler.PopToken();
                if (rhsOfKeyword.EndsWith(returnParameterDelimiter))
                {
                    // Return the parameter delimiter after each return parameter if it exists
                    rhsOfKeyword = rhsOfKeyword.Remove(rhsOfKeyword.Length - 1);
                }
                Debug.Assert(CelesteCompiler.CompileToken(rhsOfKeyword, this), "Error compiling return parameter");
            }
        }
示例#5
0
        public override void Compile(CompiledStatement parent, string token, LinkedList <string> tokens, LinkedList <string> lines)
        {
            base.Compile(parent, token, tokens, lines);

            // Unary operators act on other variables/values and so they must be included in the same token as another token (e.g. !var for example)
            // We remove the script token for the operator and split the other token out
            Debug.Assert(token.Length > 1);
            string rest = token.Remove(0, 1); // Removing wrong thing here

            // Add this operator to the tree
            parent.Add(this);

            // Parse the rest of the token which we will act on
            if (CelesteCompiler.CompileToken(rest, parent))
            {
                // Take the value that has been added to the root and add it under this operator instead
                parent.MoveChildAtIndex(parent.ChildCount - 1, this);
            }
            else
            {
                // Error message if we cannot parse the next token
                Debug.Fail("Could not compile token: " + token + " in operator " + token);
            }
        }
示例#6
0
        public override void Compile(CompiledStatement parent, string token, LinkedList <string> tokens, LinkedList <string> lines)
        {
            base.Compile(parent, token, tokens, lines);

            parent.Add(this);
        }
示例#7
0
 /// <summary>
 /// Removes a child at an index in from this compiled statement and moves it into the inputted newParent
 /// </summary>
 /// <param name="index"></param>
 /// <param name="newParent"></param>
 public void MoveChildAtIndex(int index, CompiledStatement newParent)
 {
     newParent.Add(RemoveAt(index));
 }