|
None | __init__ (self, str equation) |
| A class for parsing and solving mathematical equations from a string representation.
|
|
float | getResult (self) |
| Returns the result of the equation.
|
|
List[strNum] | getTokens (self) |
| Returns the tokenized form of the equation.
|
|
| solve (self) |
| Parses and solves the equation.
|
|
|
None | __addbrackets (self) |
| Ensures all opened brackets are closed by appending missing closing brackets.
|
|
None | __addZeroBinary (self) |
| Adds a zero before binary operators if they are at the beginning or after an opening bracket.
|
|
List[strNum] | __binaryOps (self, List[strNum] tokens, str ops) |
| Evaluates binary operations like addition, subtraction, etc.
|
|
List[strNum] | __calc (self, List[strNum] tokens) |
| Evaluates value of the given token list using operator precedence.
|
|
None | __checkOpsNum (self) |
| Validates the sequence of tokens for correct number/operator placement.
|
|
None | __convertToNum (self) |
| Converts numeric string tokens to float type in the token list.
|
|
List[strNum] | __handleBrackets (self, List[strNum] tokens) |
| Recursively evaluates bracketed expressions in the token list.
|
|
bool | __isFloat (self, str num) |
| Checks if a string or int can be converted to a float.
|
|
bool | __isNumOrDot (self, str char) |
| Checks if a character is a digit or a decimal point.
|
|
bool | __isOperator (self, str char) |
| Checks if a character is a valid operator.
|
|
List[strNum] | __specialOps (self, List[strNum] tokens, str ops) |
| Evaluates special unary operators like log, factorial, and root.
|
|
List[str] | __textDiver (self) |
| Splits the equation text into tokens.
|
|
◆ __init__()
None parser.EquationSolver.__init__ |
( |
|
self, |
|
|
str |
equation |
|
) |
| |
A class for parsing and solving mathematical equations from a string representation.
Constructor for EquationSolver.
- Parameters
-
equation | The equation string to be solved. |
- Exceptions
-
TypeError | If the equation is not a string. |
ValueError | If the equation is an empty string. |
◆ __addbrackets()
None parser.EquationSolver.__addbrackets |
( |
|
self | ) |
|
|
private |
Ensures all opened brackets are closed by appending missing closing brackets.
- Exceptions
-
TypeError | If there are more closing than opening brackets. |
◆ __addZeroBinary()
None parser.EquationSolver.__addZeroBinary |
( |
|
self | ) |
|
|
private |
Adds a zero before binary operators if they are at the beginning or after an opening bracket.
- Exceptions
-
ValueError | If the equation token list is empty. |
◆ __binaryOps()
List[strNum] parser.EquationSolver.__binaryOps |
( |
|
self, |
|
|
List[strNum] |
tokens, |
|
|
str |
ops |
|
) |
| |
|
private |
Evaluates binary operations like addition, subtraction, etc.
- Parameters
-
tokens | The token list to process. |
ops | The binary operator to evaluate. |
- Returns
- Updated token list after evaluating the binary operation.
- Exceptions
-
ValueError | If the operation is malformed or operands are invalid. |
◆ __calc()
List[strNum] parser.EquationSolver.__calc |
( |
|
self, |
|
|
List[strNum] |
tokens |
|
) |
| |
|
private |
Evaluates value of the given token list using operator precedence.
- Parameters
-
tokens | The token list to evaluate. |
- Returns
- The result as a single-item list or partial evaluation.
- Exceptions
-
ValueError | If the input is invalid or incomplete. |
◆ __checkOpsNum()
None parser.EquationSolver.__checkOpsNum |
( |
|
self | ) |
|
|
private |
Validates the sequence of tokens for correct number/operator placement.
- Exceptions
-
TypeError | If numbers are placed without operators or if an invalid token is found. |
◆ __convertToNum()
None parser.EquationSolver.__convertToNum |
( |
|
self | ) |
|
|
private |
Converts numeric string tokens to float type in the token list.
◆ __handleBrackets()
List[strNum] parser.EquationSolver.__handleBrackets |
( |
|
self, |
|
|
List[strNum] |
tokens |
|
) |
| |
|
private |
Recursively evaluates bracketed expressions in the token list.
- Parameters
-
tokens | List of tokens including bracketed expressions. |
- Returns
- Evaluated token list with brackets resolved.
- Exceptions
-
TypeError | If brackets are unmatched. |
◆ __isFloat()
bool parser.EquationSolver.__isFloat |
( |
|
self, |
|
|
str |
num |
|
) |
| |
|
private |
Checks if a string or int can be converted to a float.
param num The string to check.
- Returns
- True if the string represents a float, False otherwise.
◆ __isNumOrDot()
bool parser.EquationSolver.__isNumOrDot |
( |
|
self, |
|
|
str |
char |
|
) |
| |
|
private |
Checks if a character is a digit or a decimal point.
- Parameters
-
char | The character to check. |
- Returns
- True if the character is a number or '.', False otherwise.
◆ __isOperator()
bool parser.EquationSolver.__isOperator |
( |
|
self, |
|
|
str |
char |
|
) |
| |
|
private |
Checks if a character is a valid operator.
- Parameters
-
char | The character to check. |
- Returns
- True if the character is an operator, False otherwise.
◆ __specialOps()
List[strNum] parser.EquationSolver.__specialOps |
( |
|
self, |
|
|
List[strNum] |
tokens, |
|
|
str |
ops |
|
) |
| |
|
private |
Evaluates special unary operators like log, factorial, and root.
- Parameters
-
tokens | The token list to process. |
ops | The operator to evaluate. |
- Returns
- Updated token list after evaluating special operations.
- Exceptions
-
ValueError | If the syntax is invalid or operands are missing. |
◆ __textDiver()
List[str] parser.EquationSolver.__textDiver |
( |
|
self | ) |
|
|
private |
Splits the equation text into tokens.
- Returns
- List of string tokens.
◆ getResult()
float parser.EquationSolver.getResult |
( |
|
self | ) |
|
Returns the result of the equation.
- Returns
- The evaluated result as a float.
- Note
- Automatically solves the equation if not already solved.
◆ getTokens()
List[strNum] parser.EquationSolver.getTokens |
( |
|
self | ) |
|
Returns the tokenized form of the equation.
- Returns
- List of equation tokens.
- Note
- Automatically solves the equation if not already solved.
◆ solve()
parser.EquationSolver.solve |
( |
|
self | ) |
|
Parses and solves the equation.
- Exceptions
-
TypeError | If there are parsing or evaluation issues. |
ValueError | If the evaluation results in an error. |
◆ __equationText
parser.EquationSolver.__equationText |
|
private |
◆ __equationTokens
parser.EquationSolver.__equationTokens |
|
private |
◆ __opsBinary
parser.EquationSolver.__opsBinary |
|
private |
◆ __opsBracket
parser.EquationSolver.__opsBracket |
|
private |
◆ __opsFunc
parser.EquationSolver.__opsFunc |
|
private |
◆ __opsUnary
parser.EquationSolver.__opsUnary |
|
private |
◆ __solved
parser.EquationSolver.__solved |
|
private |
◆ __value
parser.EquationSolver.__value |
|
private |
The documentation for this class was generated from the following file: