Isis 3 Programmer Reference
|
A parser for converting equation strings to postfix. More...
#include <InlineInfixToPostfix.h>
Public Member Functions | |
InlineInfixToPostfix () | |
Constructs an InlineInfixToPostfix object. More... | |
virtual | ~InlineInfixToPostfix () |
Destroys the InlineInfixToPostfix object. More... | |
QString | convert (const QString &infix) |
This method converts infix to postfix. More... | |
QString | tokenizeEquation (const QString &equation) |
This method will add spaces between all operators and numbers, making it possible to get each element of the equation one by one. More... | |
Protected Member Functions | |
virtual bool | isKnownSymbol (QString representation) |
This method attempts to verify that the given argument is recognized as a valid function, operator, scalar, or variable. More... | |
virtual InfixOperator * | findOperator (QString element) |
This method will first search the recognized list of operators and functions for the given token. More... | |
Protected Attributes | |
QList< InfixOperator * > | p_operators |
Private Member Functions | |
void | initialize () |
Adds several infix operators and functions to the operator list that are not already recognized by the parent class, InfixToPostfix. More... | |
bool | exists (const QString &str) |
Determines whether the given string exists as a recognized variable. More... | |
bool | isScalar (const QString &scalar) |
Determines whether the given token represents a scalar value (i.e. More... | |
bool | isVariable (const QString &str) |
Determines whether the given token is a variable and, if so, appends it to the list of variables. More... | |
Private Attributes | |
QStringList | m_variables |
The list of variables (represented as strings). More... | |
A parser for converting equation strings to postfix.
This class converts infix equations to postfix for parsing.
2012-07-15 Kris Becker - Original version.
2015-03-18 Jeannie Backer - Brought class files closer to ISIS coding standards.
2015-03-24 Jeffrey Covington and Jeannie Backer - Improved documentation.
2015-03-24 Jeannie Backer - Changed m_variables from a QVector to QStringList
2016-02-21 Kristin Berry - Added unitTest.
2017-01-09 Jesse Mapel - Added logical and, or operators. Fixes #4581.
Definition at line 51 of file InlineInfixToPostfix.h.
Isis::InlineInfixToPostfix::InlineInfixToPostfix | ( | ) |
Constructs an InlineInfixToPostfix object.
The operators list is filled with string representations of known symbols, recognized by both this class and the parent class.
Definition at line 41 of file InlineInfixToPostfix.cpp.
References initialize().
|
virtual |
Destroys the InlineInfixToPostfix object.
Definition at line 49 of file InlineInfixToPostfix.cpp.
|
inherited |
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 154 of file InfixToPostfix.cpp.
References _FILEINFO_, Isis::IString::Remove(), Isis::toDouble(), Isis::IString::Token(), and Isis::IString::ToQt().
Referenced by Isis::InlineCalculator::toPostfix().
|
private |
Determines whether the given string exists as a recognized variable.
NOTE: This list is constructed using the isVariable() method.
token | A string token to be compared to the recognized variable list. |
Definition at line 153 of file InlineInfixToPostfix.cpp.
References m_variables.
|
protectedvirtual |
This method will first search the recognized list of operators and functions for the given token.
If found, it will return a pointer to the represented operator or function. If not found, the method checks whether the given token is a variable. If it is a variable, a new operator is constructed from the given token and a pointer to the represented variable is returned. If the given token is neither an operator, a function nor a variable, then an exception is thrown.
token | The symbolic representation of the operator, function, or variable |
IException::User | "The token is not recognized as an operator, function or variable." |
Reimplemented from Isis::InfixToPostfix.
Definition at line 98 of file InlineInfixToPostfix.cpp.
References _FILEINFO_, Isis::InfixToPostfix::findOperator(), isVariable(), and Isis::IException::User.
|
private |
Adds several infix operators and functions to the operator list that are not already recognized by the parent class, InfixToPostfix.
Definition at line 125 of file InlineInfixToPostfix.cpp.
Referenced by InlineInfixToPostfix().
|
protectedvirtual |
This method attempts to verify that the given argument is recognized as a valid function, operator, scalar, or variable.
representation | The symbolic representation of the operator |
Reimplemented from Isis::InfixToPostfix.
Definition at line 61 of file InlineInfixToPostfix.cpp.
References Isis::InfixToPostfix::isKnownSymbol(), isScalar(), and isVariable().
|
private |
Determines whether the given token represents a scalar value (i.e.
whether it can be converted to a double).
token | String to be tested. |
Definition at line 166 of file InlineInfixToPostfix.cpp.
References Isis::toDouble().
Referenced by isKnownSymbol().
|
private |
Determines whether the given token is a variable and, if so, appends it to the list of variables.
A token is considered a variable if it is not a known operator symbol from the parent InfixToPostfix class, not a scalar, and is not empty. Variables are implemented as functions, so new variables are also added to the operators list.
token | A string containing the token to be tested. |
Definition at line 195 of file InlineInfixToPostfix.cpp.
References m_variables.
Referenced by findOperator(), and isKnownSymbol().
|
inherited |
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 384 of file InfixToPostfix.cpp.
References Isis::IString::DownCase(), and Isis::IString::ToQt().
|
private |
The list of variables (represented as strings).
Definition at line 67 of file InlineInfixToPostfix.h.
Referenced by exists(), and isVariable().