8#ifndef INFIXTOPOSTFIX_H_
9#define INFIXTOPOSTFIX_H_
16#include <QRegularExpression>
52 QString
convert(
const QString &infix);
69 void closeParenthesis(QString &postfix, std::stack<InfixOperator> &theStack);
72 void checkArgument(QString funcName,
int argNum, QString argument);
84 InfixOperator(
int prec, QString inString,
bool isFunc =
false) {
86 m_inputString = inString;
87 m_outputString = inString;
88 m_isFunction = isFunc;
91 InfixOperator(
int prec, QString inString, QString outString,
92 bool isFunc =
false) {
94 m_inputString = inString;
95 m_outputString = outString;
96 m_isFunction = isFunc;
99 const QString &inputString()
const {
100 return m_inputString;
103 const QString &outputString()
const {
104 return m_outputString;
107 int precedence()
const {
111 bool isFunction()
const {
118 QString m_inputString;
119 QString m_outputString;
131 class InfixFunction :
public InfixOperator {
133 InfixFunction(QString inString,
int argCount) :
134 InfixOperator(-1, inString,
true) {
135 m_numArguments = argCount;
138 InfixFunction(QString inString, QString outString,
int argCount) :
139 InfixOperator(-1, inString, outString,
true) {
140 m_numArguments = argCount;
143 int argumentCount()
const {
144 return m_numArguments;
InfixOperator and InfixFunction are helper classes for InfixToPostfix.
InfixOperator and InfixFunction are helper classes for InfixToPostfix.
virtual InfixOperator * findOperator(QString representation)
This method will return a pointer to the operator represented by 'representation.
QString convert(const QString &infix)
This method converts infix to postfix.
bool isFunction(QString representation)
This method will return true if 'representation' is a known function.
QString cleanSpaces(QString equation)
This function takes a space-delimited string and removes empty delimiters.
void initialize()
This populates the known operators/functions list.
virtual bool isKnownSymbol(QString representation)
This method will return true if it believes the argument represents a valid function or operator.
void uninitialize()
This cleans the known operators/functions list.
InfixToPostfix()
Constructor.
QString tokenizeEquation(const QString &equation)
This method will add spaces between all operators and numbers, making it possible to get each element...
void closeParenthesis(QString &postfix, std::stack< InfixOperator > &theStack)
This is straight from the algorithm found on page 159 of "Data Structures & Algorithms in Java" Secon...
void addOperator(QString &postfix, const InfixOperator &op, std::stack< InfixOperator > &theStack)
This is straight from the algorithm found on page 159 of "Data Structures & Algorithms in Java" Secon...
QString formatFunctionCalls(QString equation)
This method looks through equation for function calls, parenthesizes them, and calls itself again wit...
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.