Esempio n. 1
0
        void DoSteps(ActionSequence sequence)
        {
            string[] separators = { " " };

            int lineNumber = 1;

            foreach (string x in Code)
            {
                List <string> Line = new List <string>();

                //Remove all blank spaces and leave what matters
                string[] words = x.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                foreach (string wrd in words)
                {
                    Line.Add(wrd);
                }

                string theEquation = "";
                if (Line.Count < 3)
                {
                    return;
                }
                switch (defineVariable(Line[0]))
                {
                case 1:     //String
                    if (Strings.Any(prod => prod.getName() == Line[1]))
                    {
                        Errors.Add("Same name and type variables not allowed at line " + lineNumber.ToString());
                        return;
                    }
                    break;

                case 2:     //Int
                    if (Ints.Any(prod => prod.getName() == Line[1]))
                    {
                        Errors.Add("Same name and type variables not allowed at line " + lineNumber.ToString());
                        return;
                    }
                    break;

                case 3:     //Float
                    if (Floats.Any(prod => prod.getName() == Line[1]))
                    {
                        Errors.Add("Same name and type variables not allowed at line " + lineNumber.ToString());
                        return;
                    }
                    break;

                case 4:     //Boolean
                    if (Booleans.Any(prod => prod.getName() == Line[1]))
                    {
                        Errors.Add("Same name and type variables not allowed at line " + lineNumber.ToString());
                        return;
                    }
                    break;
                }


                for (int i = 3; i < Line.Count(); i++)
                {
                    theEquation += Line[i];
                }

                try
                {
                    Line[3] = theEquation;
                }
                catch (System.ArgumentOutOfRangeException e)
                {
                    Errors.Add(e.Message.ToString() + " At line: " + lineNumber.ToString());
                    Warnings.Add("Possibly 1 or more standart variable rules are not applied At line: " + lineNumber.ToString());
                    break;
                }


                try
                {
                    switch (defineVariable(Line[0]))
                    {
                    case 1:     //String
                        sequence.variables.Strings.Add(new StringVariable(Line[1], Line[3]));
                        break;

                    case 2:     //Int
                        sequence.variables.Ints.Add(new IntegerVariable(Line[1], Int32.Parse(CheckForOperators(Line[3], lineNumber))));
                        break;

                    case 3:     //Float
                        sequence.variables.Floats.Add(new FloatVariable(Line[1], float.Parse(CheckForOperators(Line[3], lineNumber), CultureInfo.InvariantCulture.NumberFormat)));
                        break;

                    case 4:     //Boolean
                        sequence.variables.Booleans.Add(new BooleanVariable(Line[1], bool.Parse(CheckForOperators(Line[3], lineNumber))));
                        break;


                    default:
                        Errors.Add("Could not define the variable in line " + lineNumber.ToString());
                        break;
                    }
                }
                catch (System.FormatException e)
                {
                    Errors.Add(e.Message.ToString() + " At line: " + lineNumber.ToString());
                }

                lineNumber++;
            }
        }