rename TokenType to TokenClass to fix Windows issues
This commit is contained in:
parent
c816801429
commit
911b30089c
2 changed files with 8 additions and 8 deletions
|
@ -9,7 +9,7 @@
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
enum TokenType {
|
enum TokenClass {
|
||||||
Number,
|
Number,
|
||||||
Operator,
|
Operator,
|
||||||
Error,
|
Error,
|
||||||
|
@ -19,19 +19,19 @@ class Token {
|
||||||
public:
|
public:
|
||||||
Token(QString value = "", QString type = "") {
|
Token(QString value = "", QString type = "") {
|
||||||
this->value = value;
|
this->value = value;
|
||||||
this->type = TokenType::Operator;
|
this->type = TokenClass::Operator;
|
||||||
if (type == "decimal" || type == "hex") {
|
if (type == "decimal" || type == "hex") {
|
||||||
this->type = TokenType::Number;
|
this->type = TokenClass::Number;
|
||||||
this->operatorPrecedence = -1;
|
this->operatorPrecedence = -1;
|
||||||
} else if (type == "operator") {
|
} else if (type == "operator") {
|
||||||
this->operatorPrecedence = precedenceMap[value];
|
this->operatorPrecedence = precedenceMap[value];
|
||||||
} else if (type == "error") {
|
} else if (type == "error") {
|
||||||
this->type = TokenType::Error;
|
this->type = TokenClass::Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static QMap<QString, int> precedenceMap;
|
static QMap<QString, int> precedenceMap;
|
||||||
QString value;
|
QString value;
|
||||||
TokenType type;
|
TokenClass type;
|
||||||
int operatorPrecedence; // only relevant for operator tokens
|
int operatorPrecedence; // only relevant for operator tokens
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ QList<Token> ParseUtil::generatePostfix(QList<Token> tokens) {
|
||||||
QList<Token> output;
|
QList<Token> output;
|
||||||
QStack<Token> operatorStack;
|
QStack<Token> operatorStack;
|
||||||
for (Token token : tokens) {
|
for (Token token : tokens) {
|
||||||
if (token.type == TokenType::Number) {
|
if (token.type == TokenClass::Number) {
|
||||||
output.append(token);
|
output.append(token);
|
||||||
} else if (token.value == "(") {
|
} else if (token.value == "(") {
|
||||||
operatorStack.push(token);
|
operatorStack.push(token);
|
||||||
|
@ -198,7 +198,7 @@ QList<Token> ParseUtil::generatePostfix(QList<Token> tokens) {
|
||||||
int ParseUtil::evaluatePostfix(QList<Token> postfix) {
|
int ParseUtil::evaluatePostfix(QList<Token> postfix) {
|
||||||
QStack<Token> stack;
|
QStack<Token> stack;
|
||||||
for (Token token : postfix) {
|
for (Token token : postfix) {
|
||||||
if (token.type == TokenType::Operator && stack.size() > 1) {
|
if (token.type == TokenClass::Operator && stack.size() > 1) {
|
||||||
int op2 = stack.pop().value.toInt(nullptr, 0);
|
int op2 = stack.pop().value.toInt(nullptr, 0);
|
||||||
int op1 = stack.pop().value.toInt(nullptr, 0);
|
int op1 = stack.pop().value.toInt(nullptr, 0);
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -222,7 +222,7 @@ int ParseUtil::evaluatePostfix(QList<Token> postfix) {
|
||||||
result = op1 | op2;
|
result = op1 | op2;
|
||||||
}
|
}
|
||||||
stack.push(Token(QString("%1").arg(result), "decimal"));
|
stack.push(Token(QString("%1").arg(result), "decimal"));
|
||||||
} else if (token.type != TokenType::Error) {
|
} else if (token.type != TokenClass::Error) {
|
||||||
stack.push(token);
|
stack.push(token);
|
||||||
} // else ignore errored tokens, we have already warned the user.
|
} // else ignore errored tokens, we have already warned the user.
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue