Esempio n. 1
0
        private static Logic[] splitPackagesAndStatements(Logic[] logicOrder, int lineNumber, Scope currentScope)
        {
            List <Logic> newOrder = new List <Logic> ();

            for (int i = 0; i < logicOrder.Length; i++)
            {
                if (logicOrder [i].currentType == WordTypes.functionCall && SpecialWordParser.isKeyWord((logicOrder [i] as FunctionCall).name))
                {
                    Package temp = new Package("(" + (logicOrder [i] as FunctionCall).parameter + ")", lineNumber);
                    temp.logicOrder = WordsToLogicParser.determineLogicFromWords(new string[] { temp.word }, lineNumber, currentScope);

                    if ((logicOrder [i] as FunctionCall).name == "if")
                    {
                        newOrder.Add(new IfStatement());
                        newOrder.Add(temp);
                    }
                    else if ((logicOrder [i] as FunctionCall).name == "while")
                    {
                        newOrder.Add(new WhileLoop());
                        newOrder.Add(temp);
                    }
                }
                else
                {
                    newOrder.Add(logicOrder [i]);
                }
            }
            return(newOrder.ToArray());
        }
Esempio n. 2
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());
        }
        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));
        }