Example #1
0
        public void Update(IOperationsProcessor processor, IProcessorStorage storage)
        {
            if (processor.CurrentOperation.OperatorChar.IsOneOf('l', 's', 'q'))
            {
                return;
            }

            string expression;

            switch (processor.CurrentOperation.OperatorChar)
            {
            case '\0':
                expression = storage.Maths.Values[0].ToWolfString();
                break;

            case '#':
                expression = $"Out[{ storage.Maths.TempValue }]";
                break;

            default:
                expression = $"Out[-1] { processor.CurrentOperation.OperatorChar } { storage.Maths.TempValue.ToWolfString() } ";
                break;
            }

            Data.Add(expression);
        }
Example #2
0
        public bool Run(IProcessorStorage storage)
        {
            ICalcIO     calcIO     = storage.CalcIO;
            IMathBuffer mathBuffer = storage.Maths;

            mathBuffer.TempValue = storage.InputParser.ReadDouble();
            mathBuffer.AccValue += mathBuffer.TempValue;
            mathBuffer.SaveAccValue();

            return(true);
        }
        public bool Run(IProcessorStorage storage)
        {
            ICalcIO     calcIO     = storage.CalcIO;
            IMathBuffer mathBuffer = storage.Maths;

            int input = storage.InputParser.ReadInt(x => (x > 0 && x <= mathBuffer.Values.Count));

            mathBuffer.TempValue = input;
            mathBuffer.AccValue  = mathBuffer.Values[input - 1];
            mathBuffer.SaveAccValue();

            return(true);
        }
        public bool Run(IProcessorStorage storage)
        {
            IMathBuffer mathBuffer = storage.Maths;

            List <string>     history          = null;
            IPathReader       pathReader       = null;
            IExpressionParser expressionParser = null;

            if (storage is IProcessorStorageFilesWork ext)
            {
                history          = ext.OperationsHistory.Data;
                pathReader       = ext.FilePathReader;
                expressionParser = ext.MathExpressionParser;
            }
            else
            {
                throw new ArgumentException();
            }

            var     newOperBuffer = new List <string>();
            var     valBuffer     = new List <double>();
            ICalcIO calcIO        = storage.CalcIO;

            using (var file = new StreamReader(pathReader.Read(calcIO)))
            {
                string expression, rawExpression;

                while ((rawExpression = expression = file.ReadLine()) != null)
                {
                    newOperBuffer.Add(expression);

                    double result = expressionParser.Parse(ref expression, valBuffer, calcIO);

                    if (double.IsNaN(result))
                    {
                        calcIO.Write("Parse error!\n");
                        return(true);
                    }

                    calcIO.Write($"[#{ valBuffer.Count }] { rawExpression } = { (rawExpression != expression ? $"{ expression } = " : "") }{ result }\n");
                }
            }

            mathBuffer.Values   = valBuffer;
            mathBuffer.AccValue = valBuffer.Last();

            history.Clear();
            history.AddRange(newOperBuffer);

            return(true);
        }
Example #5
0
        public bool Run(IProcessorStorage storage)
        {
            ICalcIO     calcIO     = storage.CalcIO;
            IMathBuffer mathBuffer = storage.Maths;

            double input = storage.InputParser.ReadDouble();

            while (input == 0)
            {
                calcIO.WriteLine(new DivideByZeroException().Message);
                input = (calcIO as ICalcInputParser).ReadDouble();
            }

            mathBuffer.TempValue = input;
            mathBuffer.AccValue /= input;
            mathBuffer.SaveAccValue();

            return(true);
        }
        public bool Run(IProcessorStorage storage)
        {
            ICalcIO       calcIO  = storage.CalcIO;
            List <string> history = null;

            if (storage is IProcessorStorageFilesWork ext)
            {
                history = ext.OperationsHistory.Data;
            }
            else
            {
                throw new ArgumentException();
            }

            using (var file = new StreamWriter(new PathReader().Read(calcIO), false))
            {
                // Operations buffer
                history.ForEach(expression => file.WriteLine(expression));
            }

            return(true);
        }
 public OperationsProcessor(IProcessorStorage storage, List <IOperation> operations, IOperation firstOperation)
 {
     Operations       = operations;
     CurrentOperation = firstOperation;
     _storage         = storage;
 }
 public bool Run(IProcessorStorage storage)
 {
     return(false);
 }