Parses and calculates the expression @param expression the expression to parse and calculate @throws MathParserException If something went wrong @throws BalancedParenthesesException If parentheses aren't balanced @throws MathInvalidParameterException If parameter
(String expression)
| 166 | * @throws MathVariableNotFoundException If couldn't find the variable |
| 167 | */ |
| 168 | public double parse(String expression) throws MathParserException { |
| 169 | String org = expression; |
| 170 | validate(expression); |
| 171 | try { |
| 172 | initDefaultVariables(); |
| 173 | expression = firstSimplify(expression); |
| 174 | calculateVariables(); |
| 175 | |
| 176 | return round(calculate(expression, org)); |
| 177 | } catch (Exception e) { |
| 178 | if (e instanceof MathParserException) |
| 179 | throw e; |
| 180 | else if (e.getCause() instanceof MathParserException) |
| 181 | throw (MathParserException) e.getCause(); |
| 182 | else |
| 183 | throw new MathParserException(org, e.getMessage(), e); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * validate syntax |
no test coverage detected