public override void Interpret(Fields context)
        {
            if (Check(context))
            {
                string[] splitOperation = calc.GetOperation();
                string   datastring     = context.Data.Substring(1);

                Fields field     = new Fields("");
                string operation = "";
                while (datastring.Length != 0)
                {
                    int    index     = FindOperation(datastring, splitOperation);
                    Fields new_field = new Fields(datastring.Substring(0, (index == -1) ? datastring.Length : index));
                    interpret.Interpret(new_field);

                    if (field.Value == null)
                    {
                        field = new_field;
                    }
                    else
                    {
                        field.Value = calc.PerformOperation(operation, field.Value, new_field.Value);
                    }

                    if (index == -1)
                    {
                        break;
                    }
                    operation  = datastring.Substring(index, 1);
                    datastring = datastring.Remove(0, index + 1);
                }

                context.Value = new NumberResult(int.Parse(field.Value.GetValue()));
            }
        }
 public override void Interpret(Fields context)
 {
     if (Check(context))
     {
         int i = int.Parse(context.Data[1].ToString()) - 1;
         int j = LetterToNumber(context.Data[0]);
         if ((sheet.width <= j) || (sheet.height <= i))
         {
             throw new InvalidReferenceException(context.Data);
         }
         Fields temp = sheet.Fields[i, j];
         interpret.Interpret(temp);
         context.Value = new NumberResult(int.Parse(temp.Value.GetValue()));
     }
 }
Example #3
0
        public void ControllerOutput(List <string> slova)
        {
            int    blocks = slova.Count;
            string substring;

            if (blocks == 0)
            {
                Console.Write("Something went wrong. Check number you want to interpret");
                Console.ReadKey();
                return;
            }

            for (int i = 0; i < blocks; i++)
            {
                substring = _inter.Interpret(slova);

                if (substring == null && blocks == 1)
                {
                    Console.Write("zero");
                    Console.ReadKey();
                    return;
                }

                if (substring != null && substring.Contains("error"))
                {
                    Console.Clear();
                    Console.Write("Something went wrong. Check number you want to interpret");
                    Console.ReadKey();
                    return;
                }
                else
                {
                    Console.Write(substring);
                }
            }

            Console.ReadKey();
        }