Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis 3 Programmer Reference
InfixToPostfix.h
1
5
6/* SPDX-License-Identifier: CC0-1.0 */
7
8#ifndef INFIXTOPOSTFIX_H_
9#define INFIXTOPOSTFIX_H_
10
11#include <stack>
12#include <iostream>
13
14#include <QList>
15#include <QString>
16#include <QRegularExpression>
17
18namespace Isis {
19 class InfixOperator;
20 class InfixFunction;
21
48 public:
50 virtual ~InfixToPostfix();
51
52 QString convert(const QString &infix);
53 QString tokenizeEquation(const QString &equation);
54
55 protected:
56
57 virtual bool isKnownSymbol(QString representation);
58 virtual InfixOperator *findOperator(QString representation);
59
60 QList<InfixOperator *> p_operators;
61
62 private:
63 void initialize();
64 void uninitialize();
65
66 QString formatFunctionCalls(QString equation);
67 QString cleanSpaces(QString equation);
68
69 void closeParenthesis(QString &postfix, std::stack<InfixOperator> &theStack);
70 void addOperator(QString &postfix, const InfixOperator &op, std::stack<InfixOperator> &theStack);
71 bool isFunction(QString representation);
72 void checkArgument(QString funcName, int argNum, QString argument);
73 };
74
82 class InfixOperator {
83 public:
84 InfixOperator(int prec, QString inString, bool isFunc = false) {
85 m_precedence = prec;
86 m_inputString = inString;
87 m_outputString = inString;
88 m_isFunction = isFunc;
89 }
90
91 InfixOperator(int prec, QString inString, QString outString,
92 bool isFunc = false) {
93 m_precedence = prec;
94 m_inputString = inString;
95 m_outputString = outString;
96 m_isFunction = isFunc;
97 }
98
99 const QString &inputString() const {
100 return m_inputString;
101 }
102
103 const QString &outputString() const {
104 return m_outputString;
105 }
106
107 int precedence() const {
108 return m_precedence;
109 }
110
111 bool isFunction() const {
112 return m_isFunction;
113 }
114
115
116 private:
117 int m_precedence;
118 QString m_inputString;
119 QString m_outputString;
120 bool m_isFunction;
121 };
122
123
131 class InfixFunction : public InfixOperator {
132 public:
133 InfixFunction(QString inString, int argCount) :
134 InfixOperator(-1, inString, true) {
135 m_numArguments = argCount;
136 }
137
138 InfixFunction(QString inString, QString outString, int argCount) :
139 InfixOperator(-1, inString, outString, true) {
140 m_numArguments = argCount;
141 }
142
143 int argumentCount() const {
144 return m_numArguments;
145 }
146
147 private:
148 int m_numArguments;
149 };
150};
151
152#endif
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.
Definition Apollo.h:16