示例#1
0
        private static void handleFunctionCall(Logic[] logicOrder, expectType theExpectedType, int lineNumber, Scope currentScope, int i)
        {
            FunctionParser.linkFunctionCall((logicOrder [i] as FunctionCall), lineNumber, currentScope);

            if ((logicOrder [i] as FunctionCall).targetFunc.isUserFunction)
            {
                currentScope.getCurrentLine().insertReturnExpect(logicOrder [i]);
                (logicOrder [i] as FunctionCall).runFunction(currentScope);

                throw new FunctionCallException();
            }
            else
            {
                if ((logicOrder [i] as FunctionCall).targetFunc.pauseWalker)
                {
                    CodeWalker.pauseWalker();
                }

                if ((logicOrder[i] as FunctionCall).targetFunc.name == "input")
                {
                    CodeWalker.linkSubmitInput.Invoke(SubmitInput, currentScope);

                    Variable returnVariable = (logicOrder[i] as FunctionCall).runFunction(currentScope);
                    logicOrder[i] = returnVariable;

                    if (returnVariable.variableType == VariableTypes.boolean)
                    {
                        setNewExpectVariable(theExpectedType, VariableTypes.boolean, lineNumber);
                    }
                    else if (returnVariable.variableType == VariableTypes.number)
                    {
                        setNewExpectVariable(theExpectedType, VariableTypes.number, lineNumber);
                    }
                    else if (returnVariable.variableType == VariableTypes.textString)
                    {
                        setNewExpectVariable(theExpectedType, VariableTypes.textString, lineNumber);
                    }

                    CodeWalker.isWaitingForUserInput = true;
                }
                else
                {
                    Variable returnVariable = (logicOrder[i] as FunctionCall).runFunction(currentScope);
                    logicOrder[i] = returnVariable;

                    if (returnVariable.variableType == VariableTypes.boolean)
                    {
                        setNewExpectVariable(theExpectedType, VariableTypes.boolean, lineNumber);
                    }
                    else if (returnVariable.variableType == VariableTypes.number)
                    {
                        setNewExpectVariable(theExpectedType, VariableTypes.number, lineNumber);
                    }
                    else if (returnVariable.variableType == VariableTypes.textString)
                    {
                        setNewExpectVariable(theExpectedType, VariableTypes.textString, lineNumber);
                    }
                }
            }
        }
示例#2
0
        public static Logic parseForLoop(Logic[] logicOrder, int lineNumber, Scope currentScope)
        {
            syntaxCheckForLoop(logicOrder, lineNumber);


            #region get & check variables
            FunctionCall rangeCall      = (logicOrder [3] as FunctionCall);
            Variable[]   inputVariables = FunctionParser.getValueOfParameters(rangeCall.parameter, rangeCall.targetFunc, lineNumber, currentScope, rangeCall);

            // Checks if inputVariables is empty and else if only numbers
            if (inputVariables.Length == 0)
            {
                ErrorMessage.sendErrorMessage(lineNumber, ErrorType.ForLoop, ForLoopErrorType.rangeArgumentEmpty.ToString(), null);
            }
            else
            {
                foreach (Variable v in inputVariables)
                {
                    if (v.variableType != VariableTypes.number)
                    {
                        ErrorMessage.sendErrorMessage(lineNumber, ErrorType.ForLoop, ForLoopErrorType.rangeArgumentNotNumber.ToString(), null);
                    }
                }
            }
            #endregion


            ForLoop returnLoop = new ForLoop();
            returnLoop.setTargetScope((logicOrder [0] as ScopeStarter).getTargetScope());
            returnLoop.getTargetScope().theScoopLoop = returnLoop;

            string counterName = logicOrder[1].word;
            if (inputVariables.Length == 1)
            {
                returnLoop.setLoopVariables(counterName, 0, inputVariables [0].getNumber(), 1);
            }

            if (inputVariables.Length == 2)
            {
                returnLoop.setLoopVariables(counterName, inputVariables [0].getNumber(), inputVariables [1].getNumber(), 1);
            }

            if (inputVariables.Length == 3)
            {
                returnLoop.setLoopVariables(counterName, inputVariables [0].getNumber(), inputVariables [1].getNumber(), inputVariables [2].getNumber());
            }

            returnLoop.doEnterScope = returnLoop.makeComparison(lineNumber, false);
            returnLoop.addCounterVariableToScope(lineNumber);


            return(returnLoop);
        }
示例#3
0
        // Could be optimized so that we save left, right and operators for next comparision so we do not need to parse every loop instance!


        public static Logic parseDefStatement(Logic[] logicOrder, int lineNumber, Scope currentScope)
        {
            FunctionCall theFuncCall = logicOrder [1] as FunctionCall;

            if (SpecialWordParser.isKeyWord(theFuncCall.name))
            {
                ErrorMessage.sendErrorMessage(lineNumber, string.Format("\"{0}\" är ett Python keyword, du kan därför inte döpa en funktion till det", theFuncCall.name));
            }

            int          paraAmount = (FunctionParser.getParameterAmount(theFuncCall.parameter, lineNumber, currentScope));
            UserFunction theFunc    = new UserFunction(theFuncCall.name, (logicOrder [0] as ScopeStarter).getTargetScope(), paraAmount);

            currentScope.scopeFunctions.addFunction(theFunc);

            theFunc.inputParameterNames = FunctionParser.getParameterNames(theFuncCall.parameter, lineNumber, currentScope);

            return(new DefStatement());
        }
示例#4
0
        private static Logic[] parseVariablesAndPackagesIntoFunctionCalls(Logic[] logicOrder, int lineNumber, Scope currentScope)
        {
            List <Logic> tempOrder = new List <Logic> ();

            for (int i = 0; i < logicOrder.Length; i++)
            {
                if (logicOrder [i].currentType == WordTypes.variable && (i + 1 < logicOrder.Length && logicOrder[i + 1].currentType == WordTypes.package))
                {
                    Logic theFuncCall = FunctionParser.parseIntoFunctionCall(logicOrder [i].word + logicOrder [i + 1].word, lineNumber, currentScope);
                    tempOrder.Add(theFuncCall);
                    i += 1;
                }
                else
                {
                    tempOrder.Add(logicOrder [i]);
                }
            }

            return(tempOrder.ToArray());
        }
        private static Logic getCurrentLogic(string word, int lineNumber, Scope currentScope)
        {
            if (word == ",")
            {
                return(new CommaSign());
            }

            if (word == ">")
            {
                return(new GreaterThenSign());
            }

            if (word == "<")
            {
                return(new LessThenSign());
            }

            if (word == ":")
            {
                return(new IndentOperator());
            }

            if (word == "!")
            {
                return(new XorOperator(word));
            }

            if (word == "not")
            {
                return(new NotOperator(word));
            }

            if (word == "or")
            {
                return(new OrOperator(word));
            }

            if (word == "and")
            {
                return(new AndOperator(word));
            }


            if (isBooleanValue(word) == 1)
            {
                return(new BooleanValue(true));
            }
            if (isBooleanValue(word) == 0)
            {
                return(new BooleanValue(false));
            }


            if (isNumber(word))
            {
                return(new NumberValue(word));
            }

            if (isString(word))
            {
                return(new TextValue(word));
            }


            if (SpecialWordParser.isKeyWord(word))
            {
                SpecialWordParser.checkIfUnsupportedKeyword(word, lineNumber);
                WordTypes specialType = SpecialWordParser.getSpecialType(word, lineNumber);

                if (specialType == WordTypes.forLoop)
                {
                    return(new ForLoop());
                }

                if (specialType == WordTypes.whileLoop)
                {
                    return(new WhileLoop());
                }

                if (specialType == WordTypes.ifOperator)
                {
                    return(new IfStatement());
                }

                if (specialType == WordTypes.elifOperator)
                {
                    return(new ElifStatement());
                }

                if (specialType == WordTypes.elseOperator)
                {
                    return(new ElseStatement());
                }

                if (specialType == WordTypes.defStatement)
                {
                    return(new DefStatement());
                }

                if (specialType == WordTypes.returnStatement)
                {
                    return(new ReturnStatement());
                }

                if (specialType == WordTypes.breakStatement)
                {
                    return(new BreakStatement());
                }

                if (specialType == WordTypes.continueStatement)
                {
                    return(new ContinueStatment());
                }
            }



            if (startsWithDigitOrWeirdChar(word) == false)
            {
                if (endsWithParantes(word))
                {
                    Logic temp = FunctionParser.parseIntoFunctionCall(word, lineNumber, currentScope);
                    if (temp != null)
                    {
                        return(temp);
                    }
                }
                else
                {
                    if (containsButNotStartWithDigitWeirdChar(word) == false)
                    {
                        return(checkVariable(word, currentScope.scopeVariables));
                    }
                }
            }

            if (word.Length == 1)
            {
                if (word [0] == '=')
                {
                    return(new EqualSign());
                }
                if (isMathOperator(word[0]))
                {
                    return(new MathOperator(word));
                }
            }

            if (isPackage(word))
            {
                return(new Package(word, lineNumber));
            }

            return(new UnknownLogic(lineNumber));
        }
        public static bool hasReturnValue(string word, int lineNumber)
        {
            Compiler.Function searchedFunc = Camera.main.GetComponent <HelloCompiler>().funcs.getSavedFunction(FunctionParser.getFunctionName(word, lineNumber), lineNumber);
            if (searchedFunc != null)
            {
                return(searchedFunc.hasReturnVariable);
            }


            return(false);
        }