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 <QRegularExpression>
|
||||
|
||||
enum TokenType {
|
||||
enum TokenClass {
|
||||
Number,
|
||||
Operator,
|
||||
Error,
|
||||
|
@ -19,19 +19,19 @@ class Token {
|
|||
public:
|
||||
Token(QString value = "", QString type = "") {
|
||||
this->value = value;
|
||||
this->type = TokenType::Operator;
|
||||
this->type = TokenClass::Operator;
|
||||
if (type == "decimal" || type == "hex") {
|
||||
this->type = TokenType::Number;
|
||||
this->type = TokenClass::Number;
|
||||
this->operatorPrecedence = -1;
|
||||
} else if (type == "operator") {
|
||||
this->operatorPrecedence = precedenceMap[value];
|
||||
} else if (type == "error") {
|
||||
this->type = TokenType::Error;
|
||||
this->type = TokenClass::Error;
|
||||
}
|
||||
}
|
||||
static QMap<QString, int> precedenceMap;
|
||||
QString value;
|
||||
TokenType type;
|
||||
TokenClass type;
|
||||
int operatorPrecedence; // only relevant for operator tokens
|
||||
};
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ QList<Token> ParseUtil::generatePostfix(QList<Token> tokens) {
|
|||
QList<Token> output;
|
||||
QStack<Token> operatorStack;
|
||||
for (Token token : tokens) {
|
||||
if (token.type == TokenType::Number) {
|
||||
if (token.type == TokenClass::Number) {
|
||||
output.append(token);
|
||||
} else if (token.value == "(") {
|
||||
operatorStack.push(token);
|
||||
|
@ -198,7 +198,7 @@ QList<Token> ParseUtil::generatePostfix(QList<Token> tokens) {
|
|||
int ParseUtil::evaluatePostfix(QList<Token> postfix) {
|
||||
QStack<Token> stack;
|
||||
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 op1 = stack.pop().value.toInt(nullptr, 0);
|
||||
int result = 0;
|
||||
|
@ -222,7 +222,7 @@ int ParseUtil::evaluatePostfix(QList<Token> postfix) {
|
|||
result = op1 | op2;
|
||||
}
|
||||
stack.push(Token(QString("%1").arg(result), "decimal"));
|
||||
} else if (token.type != TokenType::Error) {
|
||||
} else if (token.type != TokenClass::Error) {
|
||||
stack.push(token);
|
||||
} // else ignore errored tokens, we have already warned the user.
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue