private void Interpret() { if (isOverdrive(givenString)) { MathParserOverdrive mpo = new MathParserOverdrive(givenString.TrimStart(new char[] { '@' })); mpo.Solve(); if (isProcessed()) { Solution = mpo.getSolution(); Processed = true; return; } } else if (!givenString.Contains("=")) { NonEquation solve = new NonEquation(givenString); solve.History = History; solve.Solve(); if (solve.isProcessed()) { Solution = solve.getSolution(); } else { Processed = false; } } else { Equation sol = new Equation(givenString); sol.theHistory = History; sol.Solve(); if (sol.isProcessed()) { Solution = sol.getSolution(); } else { Processed = false; } } }
public void Solve() { string testString = givenExpression.Replace("=", ""); int testLenght = testString.Length; if (givenExpression.Length - testLenght <= 1) // Declaration statement. a = 2+2 { string Name, Exp; { string[] parts = givenExpression.Split('='); Name = parts [0].Trim(); Exp = parts [1].Trim(); } NonEquation sol = new NonEquation(Exp); sol.History = theHistory; sol.Solve(); BasicOperators = sol.theBasicOperatorsString; string numbers = "0123456789."; if (sol.ConstantName.Contains(Name) || sol.theKeyWordsList.Contains(Name) || Checker.ifContainOperation(Name, BasicOperators) || numbers.Contains(new string(Name[0], 1)) || string.IsNullOrEmpty(Name) || string.IsNullOrWhiteSpace(Name)) { Processed = false; throw new MathParserException($"Invalid declaration. '{Name}'."); } if (sol.isProcessed()) { solution = new MathParserExpression(sol.getSolution()); solution.Tag = Name.Trim(); //if (string.IsNullOrEmpty (solution.Data.Tag) || string.IsNullOrWhiteSpace (solution.Data.Tag)) { solution.setEntireTag(Name.Trim()); } else { Processed = false; throw new MathParserException("Unsolveable Input."); } } } // end solve().
// End matrix syntax checker. public void Parse() // Parse method. { bool proceed = MatrixSyntaxChecker(); if (!proceed) { Processed = false; } else { string matExpression = givenExpression.TrimStart(FlagStart.ToCharArray()); matExpression = matExpression.TrimEnd(FlagEnd.ToCharArray()); matExpression = matExpression.Trim(); List <string> theStringRows = new List <string>(matExpression.Split(FlagRowSeperation.ToCharArray())); theStringRows.Remove(""); int rows = theStringRows.Count; int cols = 0; List <List <string> > theMatrixElements = new List <List <string> >(); foreach (string row in theStringRows) { List <string> dumyList = new List <string>(row.Trim().Split(FlagElementSeperation.ToCharArray())); dumyList.Remove(""); if (dumyList.Count > cols) { cols = dumyList.Count; } theMatrixElements.Add(dumyList); } theMatrix = new Matrix(rows, cols, ""); int irow = 0, icol = 0; foreach (List <string> row in theMatrixElements) { icol = 0; foreach (string element in row) { if (OnParse != null) { dynamic mElement = OnParse(element.Trim(), ref Processed); theMatrix[irow, icol] = mElement; } else if (staticOnParse != null) { dynamic mElement = staticOnParse(element.Trim(), ref Processed); theMatrix[irow, icol] = mElement; } else { NonEquation sol = new NonEquation(element.Trim()); sol.History = Checker.History; sol.Solve(); Number a; if (sol.isProcessed()) { MathParserExpression ans = sol.getSolution(); a = ans.Data; } else { Processed = false; throw new MathParserException("Invalid Entry."); } theMatrix[irow, icol] = (double)a.Data; Processed = true; } if (!Processed) { Processed = false; break; } icol++; } if (!Processed) { Processed = false; break; } irow++; } if (!Processed) { theMatrix = new Matrix(1, 1); } } }