Ejemplo n.º 1
0
        static bool handleOnlyValueStatement(Logic[] logicOrder, int lineNumber, Scope currentScope)
        {
            Variable sum = SumParser.parseIntoSum(logicOrder, lineNumber, currentScope);

            if (sum.variableType != VariableTypes.boolean)
            {
                ErrorMessage.sendErrorMessage(lineNumber, "När du skriver in endast ett värde, måste det vara Sant eller Falskt");
            }

            return(sum.getBool());
        }
Ejemplo n.º 2
0
        //Later fix!
        //Should be possible to avoid all the else if statements.
        public void addVariable(Variable newVar, ExpressionParser scopePareser, int lineNumber)
        {
            //First we check if the variable we are trying to add already exists, if it does we change the value of it.
            //Otherwise create a new variable
            int tempCont = containsVariable(newVar.name);

            if (tempCont >= 0)
            {
                variableList [tempCont] = newVar;

                if (newVar.variableType == VariableTypes.boolean)
                {
                    changeExistingVariable(tempCont, newVar.getBool(), scopePareser);
                }
                else if (newVar.variableType == VariableTypes.number)
                {
                    changeExistingVariable(tempCont, newVar.getNumber(), scopePareser);
                }
                else if (newVar.variableType == VariableTypes.textString)
                {
                    changeExistingVariable(tempCont, newVar.getString(), scopePareser);
                }
                else if (newVar.variableType == VariableTypes.None)
                {
                    changeExistingVariable(tempCont, newVar.getString(), scopePareser);
                }
                else
                {
                    ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, ErrorType.System, SystemFailureErrorType.addOrChangeUnsupportedVariableType.ToString(), null);
                }
            }
            else
            {
                if (newVar.variableType != VariableTypes.unknown && newVar.variableType != VariableTypes.unsigned)
                {
                    variableList.Add(newVar);
                    if (newVar.variableType == VariableTypes.number)
                    {
                        scopePareser.AddConst(newVar.name, () => newVar.getNumber());
                    }
                }
                else
                {
                    ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, ErrorType.System, SystemFailureErrorType.addOrChangeUnsupportedVariableType.ToString(), null);
                }
            }
        }
Ejemplo n.º 3
0
        private static Logic insertTheValue(Variable returnVar)
        {
            Print.print("Var type: " + returnVar.variableType);

            if (returnVar.variableType == VariableTypes.boolean)
            {
                return(new BooleanValue(returnVar.getBool()));
            }
            else if (returnVar.variableType == VariableTypes.number)
            {
                return(new NumberValue(returnVar.getNumber()));
            }
            else if (returnVar.variableType == VariableTypes.textString)
            {
                return(new TextValue(returnVar.getString()));
            }

            return(new Variable("Nill"));
        }
Ejemplo n.º 4
0
        public static bool parseAndCheckStatement(Logic[] logicOrder, int lineNumber, Scope currentScope)
        {
            Variable sum = SumParser.parseIntoSum(logicOrder, lineNumber, currentScope);

            if (sum.variableType == VariableTypes.number)
            {
                if (sum.getNumber() == 0)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            if (sum.variableType == VariableTypes.textString)
            {
                if (sum.getString() == "")
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }

            if (sum.variableType == VariableTypes.None)
            {
                return(false);
            }

            if (sum.variableType != VariableTypes.boolean)
            {
                ErrorMessage.sendErrorMessage(lineNumber, ErrorType.IfStatements, IfErrorType.expressionNotCorrectType.ToString(), null);
            }

            return(sum.getBool());
        }
        private static string convertIntoBoolAlgebra(Logic[] logicOrder, int lineNumber, Scope currentScope)
        {
            string boolString = "";

            for (int i = 0; i < logicOrder.Length; i++)
            {
                if (logicOrder [i] is AndOrOperator)
                {
                    if (logicOrder[i].currentType == WordTypes.andOperator)
                    {
                        boolString += "*";
                    }
                    else
                    {
                        boolString += "+";
                    }

                    continue;
                }

                if (logicOrder [i].currentType == WordTypes.package)
                {
                    Variable tempSum = SumParser.parseIntoSum((logicOrder [i] as Package).logicOrder, lineNumber, currentScope);
                    if (tempSum.getBool())
                    {
                        boolString += "1";
                    }
                    else
                    {
                        boolString += "0";
                    }
                }
                else
                {
                    ErrorMessage.sendErrorMessage(lineNumber, "Korrupt uttryck");
                }
            }

            return(boolString);
        }
        public static bool makeComparison(Variable var1, Variable var2, ComparisonType theOperator, int lineNumber)
        {
            if (var1.variableType == VariableTypes.unknown || var1.variableType == VariableTypes.unsigned || var2.variableType == VariableTypes.unknown || var2.variableType == VariableTypes.unsigned)
            {
                ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, "En eller flera av operatorerna går inte att tyda");
            }


            if (var1.variableType != var2.variableType)
            {
                ErrorHandler.ErrorMessage.sendErrorMessage(lineNumber, "Kan inte utföra jämförelse mellan " + var1.variableType + " och " + var2.variableType);
            }


            if (theOperator == ComparisonType.equalsTo)
            {
                if (var1.variableType == VariableTypes.boolean)
                {
                    if (var1.getBool() == var2.getBool())
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (var1.variableType == VariableTypes.number)
                {
                    if (var1.getNumber() == var2.getNumber())
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (var1.variableType == VariableTypes.textString)
                {
                    if (var1.getString() == var2.getString())
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            if (theOperator == ComparisonType.notEqualsTo)
            {
                if (var1.variableType == VariableTypes.boolean)
                {
                    if (var1.getBool() != var2.getBool())
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (var1.variableType == VariableTypes.number)
                {
                    if (var1.getNumber() != var2.getNumber())
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                if (var1.variableType == VariableTypes.textString)
                {
                    if (var1.getString() != var2.getString())
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            if (theOperator == ComparisonType.greaterThenOrEqaulsTo && var1.variableType == VariableTypes.number)
            {
                if (var1.getNumber() >= var2.getNumber())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            if (theOperator == ComparisonType.lessThenOrEqualsTo && var1.variableType == VariableTypes.number)
            {
                if (var1.getNumber() <= var2.getNumber())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            if (theOperator == ComparisonType.lessThen && var1.variableType == VariableTypes.number)
            {
                if (var1.getNumber() < var2.getNumber())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            if (theOperator == ComparisonType.greaterThen && var1.variableType == VariableTypes.number)
            {
                if (var1.getNumber() > var2.getNumber())
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }


            ErrorMessage.sendErrorMessage(lineNumber, ErrorType.System, SystemFailureErrorType.unknownLogic.ToString(), new string[] { "4" });
            return(false);
        }