-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.h
46 lines (39 loc) · 1.32 KB
/
parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef PARSER_H
#define PARSER_H
#include <cmath>
#include "utils.h"
#include <qchar.h>
#include <qstack.h>
#include <qstring.h>
class Parser
{
public:
Parser();
Parser(const QString& _userInputExpression);
void convertToPolishExpression();
double calculate(double valueX);
QString getExpressionPolishNotation() const;
void setUserInputExpression(const QString value);
private:
QString userInputExpression;
QString expressionPolishNotation;
QStack<QChar> operators;
QStack<double> operands;
QString symbolsNumber;
int getPriorityOperator(QChar symbol);
void checkAndAddDigits(QChar symbol);
void addDigitToExpression(size_t currentPosition, QChar symbol);
void addBracketToExpression(QChar symbol);
void addOperatorToExpression(QChar symbol);
void addVariableToExpression();
void addDecimalSeparatorToExpression();
void addMathSymbolToExpression(QChar symbol);
void addOperatorsFromStackToExpression();
void addDigitToOperands(QChar symbol);
void addValueVariableToOperands(double valueX);
void calculateIntermediateResults(QChar symbolOperator);
double calculateOperandsWithOperator(double leftOperand, double rightOperand, QChar symbolOperator);
double getResultExpression();
bool isDecimalSeparator(QChar symbol);
};
#endif // PARSER_H