Isis 3.0 Programmer Reference
Back | Home
InfixToPostfix.h
Go to the documentation of this file.
1 
23 #ifndef INFIXTOPOSTFIX_H_
24 #define INFIXTOPOSTFIX_H_
25 
26 #include <stack>
27 #include <iostream>
28 
29 #include <QList>
30 #include <QString>
31 
32 namespace Isis {
33  class InfixOperator;
34  class InfixFunction;
35 
60  public:
62  virtual ~InfixToPostfix();
63 
64  QString convert(const QString &infix);
65  QString tokenizeEquation(const QString &equation);
66 
67  protected:
68 
69  virtual bool isKnownSymbol(QString representation);
70  virtual InfixOperator *findOperator(QString representation);
71 
72  QList<InfixOperator *> p_operators;
73 
74  private:
75  void initialize();
76  void uninitialize();
77 
78  QString formatFunctionCalls(QString equation);
79  QString cleanSpaces(QString equation);
80 
81  void closeParenthesis(QString &postfix, std::stack<InfixOperator> &theStack);
82  void addOperator(QString &postfix, const InfixOperator &op, std::stack<InfixOperator> &theStack);
83  bool isFunction(QString representation);
84  void checkArgument(QString funcName, int argNum, QString argument);
85  };
86 
94  class InfixOperator {
95  public:
96  InfixOperator(int prec, QString inString, bool isFunc = false) {
97  m_precedence = prec;
98  m_inputString = inString;
99  m_outputString = inString;
100  m_isFunction = isFunc;
101  }
102 
103  InfixOperator(int prec, QString inString, QString outString,
104  bool isFunc = false) {
105  m_precedence = prec;
106  m_inputString = inString;
107  m_outputString = outString;
108  m_isFunction = isFunc;
109  }
110 
111  const QString &inputString() const {
112  return m_inputString;
113  }
114 
115  const QString &outputString() const {
116  return m_outputString;
117  }
118 
119  int precedence() const {
120  return m_precedence;
121  }
122 
123  bool isFunction() const {
124  return m_isFunction;
125  }
126 
127 
128  private:
129  int m_precedence;
130  QString m_inputString;
131  QString m_outputString;
132  bool m_isFunction;
133  };
134 
135 
143  class InfixFunction : public InfixOperator {
144  public:
145  InfixFunction(QString inString, int argCount) :
146  InfixOperator(-1, inString, true) {
147  m_numArguments = argCount;
148  }
149 
150  InfixFunction(QString inString, QString outString, int argCount) :
151  InfixOperator(-1, inString, outString, true) {
152  m_numArguments = argCount;
153  }
154 
155  int argumentCount() const {
156  return m_numArguments;
157  }
158 
159  private:
160  int m_numArguments;
161  };
162 };
163 
164 #endif
QString formatFunctionCalls(QString equation)
This method looks through equation for function calls, parenthesizes them, and calls itself again wit...
QString tokenizeEquation(const QString &equation)
This method will add spaces between all operators and numbers, making it possible to get each element...
bool isFunction(QString representation)
This method will return true if &#39;representation&#39; is a known function.
QString convert(const QString &infix)
This method converts infix to postfix.
virtual InfixOperator * findOperator(QString representation)
This method will return a pointer to the operator represented by &#39;representation. ...
InfixOperator and InfixFunction are helper classes for InfixToPostfix.
InfixOperator and InfixFunction are helper classes for InfixToPostfix.
void uninitialize()
This cleans the known operators/functions list.
void addOperator(QString &postfix, const InfixOperator &op, std::stack< InfixOperator > &theStack)
This is straight from the algorithm found on page 159 of &quot;Data Structures &amp; Algorithms in Java&quot; Secon...
Converter for math equations.
void closeParenthesis(QString &postfix, std::stack< InfixOperator > &theStack)
This is straight from the algorithm found on page 159 of &quot;Data Structures &amp; Algorithms in Java&quot; Secon...
InfixToPostfix()
Constructor.
void initialize()
This populates the known operators/functions list.
QString cleanSpaces(QString equation)
This function takes a space-delimited string and removes empty delimiters.
virtual bool isKnownSymbol(QString representation)
This method will return true if it believes the argument represents a valid function or operator...

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:20:32