|
Isis 3.0 Object Programmers' Reference |
Home |
#include <InfixToPostfix.h>
Inheritance diagram for Isis::InfixToPostfix:


This class converts infix equations to postfix
For internal use only.
Definition at line 49 of file InfixToPostfix.h.
Public Member Functions | |
| InfixToPostfix () | |
| Constructor. | |
| virtual | ~InfixToPostfix () |
| iString | Convert (const iString &infix) |
| This method converts infix to postfix. | |
| iString | TokenizeEquation (const iString &equation) |
| This method will add spaces between all operators and numbers, making it possible to get each element of the equation one by one. | |
Protected Member Functions | |
| virtual bool | IsKnownSymbol (iString representation) |
| This method will return true if it believes the argument represents a valid function or operator. | |
| virtual InfixOperator * | FindOperator (iString representation) |
| This method will return a pointer to the operator represented by 'representation. | |
Protected Attributes | |
| QList< InfixOperator * > | p_operators |
Private Member Functions | |
| void | Initialize () |
| This populates the known operators/functions list. | |
| void | Uninitialize () |
| This cleans the known operators/functions list. | |
| iString | FormatFunctionCalls (iString equation) |
| This method looks through equation for function calls, parenthesizes them, and calls itself again with each argument in order to parse any embedded functions. | |
| iString | CleanSpaces (iString equation) |
| This function takes a space-delimited string and removes empty delimiters. | |
| void | CloseParenthesis (iString &postfix, std::stack< InfixOperator > &theStack) |
| This is straight from the algorithm found on page 159 of "Data Structures & Algorithms in Java" Second Edition by Robert Lafore. | |
| void | AddOperator (iString &postfix, const InfixOperator &op, std::stack< InfixOperator > &theStack) |
| This is straight from the algorithm found on page 159 of "Data Structures & Algorithms in Java" Second Edition by Robert Lafore. | |
| bool | IsFunction (iString representation) |
| This method will return true if 'representation' is a known function. | |
| void | CheckArgument (iString funcName, int argNum, iString argument) |
| Isis::InfixToPostfix::InfixToPostfix | ( | ) |
| void Isis::InfixToPostfix::AddOperator | ( | iString & | postfix, | |
| const InfixOperator & | op, | |||
| std::stack< InfixOperator > & | theStack | |||
| ) | [private] |
This is straight from the algorithm found on page 159 of "Data Structures & Algorithms in Java" Second Edition by Robert Lafore.
| postfix | The postix generated thus far | |
| op | The operator | |
| theStack | The operator stack |
Definition at line 287 of file InfixToPostfix.cpp.
References Isis::InfixOperator::precedence, and top.
Referenced by Convert().
This function takes a space-delimited string and removes empty delimiters.
In order words, it compresses the spaces. This is used to keep strings small, clean, and remove the necessity to check for empty tokens constantly.
That is, if your string is "a b" the result will be "a b".
| equation | A space-delimited string with excessive spaces |
Definition at line 115 of file InfixToPostfix.cpp.
References clean(), and Isis::iString::Token().
Referenced by Convert(), FormatFunctionCalls(), and TokenizeEquation().
| void Isis::InfixToPostfix::CloseParenthesis | ( | iString & | postfix, | |
| std::stack< InfixOperator > & | theStack | |||
| ) | [private] |
This is straight from the algorithm found on page 159 of "Data Structures & Algorithms in Java" Second Edition by Robert Lafore.
| postfix | The postix generated thus far | |
| theStack | The operator stack |
Definition at line 316 of file InfixToPostfix.cpp.
References _FILEINFO_, and Isis::iException::Message().
Referenced by Convert().
This method converts infix to postfix.
It uses an enhanced verion of the algorithm found on page 159 of "Data Structures & Algorithms in Java" Second Edition by Robert Lafore. First, we prep the equation with TokenizeEquation and then parse through it using the known-good algorithm.
| infix | The infix equation |
Definition at line 144 of file InfixToPostfix.cpp.
References _FILEINFO_, AddOperator(), CleanSpaces(), Isis::iException::Clear(), CloseParenthesis(), e, FindOperator(), IsFunction(), IsKnownSymbol(), Isis::iException::Message(), Isis::iString::Remove(), Isis::iString::Token(), and TokenizeEquation().
| InfixOperator * Isis::InfixToPostfix::FindOperator | ( | iString | representation | ) | [protected, virtual] |
This method will return a pointer to the operator represented by 'representation.
' Because in this model a function is an operator, this will return a pointer to functions as well (in a base class pointer).
| representation | The symbolic representation of the operator, such as '+' |
Reimplemented in Isis::CubeInfixToPostfix.
Definition at line 347 of file InfixToPostfix.cpp.
References _FILEINFO_, Isis::iException::Message(), and p_operators.
Referenced by Convert(), Isis::CubeInfixToPostfix::FindOperator(), FormatFunctionCalls(), and IsFunction().
This method looks through equation for function calls, parenthesizes them, and calls itself again with each argument in order to parse any embedded functions.
This ensures order of operations holds for cases like sin(.5)^2. This method might add too many parentheses, but that is harmless. This does not affect operators (excepting --) or numbers. Only functions. The input should be space-delimited.
| equation | The unparenthesized equation |
This code block is for multi-parameter functions. Functions with 1+ parameters are parsed here, excepting the negation (with no parentheses) which is done just above.
We figure out the arguments by looking for commas, outside of all parentheses, for each argument up until the last one. We look for an extra closing parenthesis for the last argument. When we figure out what an argument is, we recursively call FormatFunctionCalls to format any and all functionality inside of the argument.
Definition at line 470 of file InfixToPostfix.cpp.
References _FILEINFO_, CheckArgument(), CleanSpaces(), element, FindOperator(), IsFunction(), Isis::iException::Message(), Isis::InfixFunction::numArguments, Isis::InfixOperator::representation, and Isis::iString::Token().
Referenced by TokenizeEquation().
| void Isis::InfixToPostfix::Initialize | ( | ) | [private] |
This populates the known operators/functions list.
If the operators list is not empty, this function will do nothing.
Definition at line 43 of file InfixToPostfix.cpp.
References p_operators.
Referenced by InfixToPostfix().
| bool Isis::InfixToPostfix::IsFunction | ( | iString | representation | ) | [private] |
This method will return true if 'representation' is a known function.
| representation | The symbolic representation of a function, such as 'abs' |
Definition at line 270 of file InfixToPostfix.cpp.
References FindOperator(), Isis::InfixOperator::isFunction, and IsKnownSymbol().
Referenced by Convert(), and FormatFunctionCalls().
| bool Isis::InfixToPostfix::IsKnownSymbol | ( | iString | representation | ) | [protected, virtual] |
This method will return true if it believes the argument represents a valid function or operator.
| representation | The symbolic representation of the operator, such as 'sin' |
Reimplemented in Isis::CubeInfixToPostfix.
Definition at line 253 of file InfixToPostfix.cpp.
References p_operators.
Referenced by Convert(), and IsFunction().
This method will add spaces between all operators and numbers, making it possible to get each element of the equation one by one.
It will also parse out the function calls, adding parenthesis where needed so the user doesn't have to. The result is an equation ready for parsing (but NOT fully parenthesized, just enough to make sure our algorithm makes no mistakes).
| equation | An unformatted infix equation |
Definition at line 369 of file InfixToPostfix.cpp.
References CleanSpaces(), Isis::iString::DownCase(), and FormatFunctionCalls().
Referenced by Convert().
| void Isis::InfixToPostfix::Uninitialize | ( | ) | [private] |
This cleans the known operators/functions list.
Definition at line 95 of file InfixToPostfix.cpp.
References p_operators.
Referenced by ~InfixToPostfix().