Пример #1
0
 public CellType(SpreadsheetVisitor visitor, Types tp, SpreadsheetParser.ExpContext expression)
 {
     _visitor   = visitor;
     Type       = tp;
     Expression = expression;
     marked     = false;
 }
Пример #2
0
 public CellType(SpreadsheetVisitor visitor, Types value)
 {
     _visitor   = visitor;
     Type       = value;
     Expression = null;
     marked     = false;
 }
        public void AddFormula(Tuple <int, int> cell, SpreadsheetParser.ExpContext formula)
        {
            var abstractFormula = TranslateFormula(formula, cell, out bool success);

            if (success)
            {
                Logger.DebugLine($"Registered abstractFormula {abstractFormula.ToString()}");
                Logger.DebugLine($"Simplified: {abstractFormula.ToString()}");

                CellFormulas.Add(cell, abstractFormula);
            }
        }
        public AbstractFormula TranslateFormula(SpreadsheetParser.ExpContext formula, Tuple <int, int> cellIndex, out bool success)
        {
            if (formula == null)
            {
                Logger.DebugLine($"Error - Formula was null.");
                success = false;
                return(null);
            }
            success = formulaDict.TryGetValue(formula.GetType(), out Type formulaType);
            if (success)
            {
                var abstractFormula = (AbstractFormula)Activator.CreateInstance(formulaType);
                abstractFormula.Exp          = formula;
                abstractFormula.Visitor      = Visitor;
                abstractFormula.CellFormulas = CellFormulas;
                abstractFormula.Formulas     = this;
                abstractFormula.CellIndex    = cellIndex;

                bool result = abstractFormula.Translate();
                if (result)
                {
                    //abstractFormula.Simplify();   //Simplify is own function, dont partially simplify throughout translation (might be performance boost though)
                    return(abstractFormula);
                }
                else
                {
                    if (cellIndex != null)
                    {
                        Logger.DebugLine($"Error - Couldnt Translate Formula, abstractFormula.Translate returned false. For type {formula.GetType()} and Cellindex {cellIndex.ToString()}", 5);
                    }
                    else
                    {
                        Logger.DebugLine($"Error - Couldnt Translate Formula, abstractFormula.Translate returned false. For type {formula.GetType()}", 5);
                    }
                    success = false;
                    return(null);
                }
            }
            else
            {
                Logger.DebugLine($"Error - Couldnt Translate Formula, formula Type {formula.GetType()} not registered yet.");
                return(null);
            }
        }