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); } }