2018-03-04 01:09:05 +00:00
|
|
|
#ifndef PARSEUTIL_H
|
|
|
|
#define PARSEUTIL_H
|
|
|
|
|
2018-09-12 01:37:36 +01:00
|
|
|
#include "heallocation.h"
|
|
|
|
|
2018-03-04 01:09:05 +00:00
|
|
|
#include <QString>
|
|
|
|
#include <QList>
|
2018-03-19 01:30:12 +00:00
|
|
|
#include <QMap>
|
2018-03-04 01:09:05 +00:00
|
|
|
|
|
|
|
enum TokenType {
|
|
|
|
Number,
|
|
|
|
Operator,
|
|
|
|
};
|
|
|
|
|
|
|
|
class Token {
|
|
|
|
public:
|
|
|
|
Token(QString value = "", QString type = "") {
|
|
|
|
this->value = value;
|
|
|
|
this->type = TokenType::Operator;
|
|
|
|
if (type == "decimal" || type == "hex") {
|
|
|
|
this->type = TokenType::Number;
|
|
|
|
this->operatorPrecedence = -1;
|
|
|
|
} else if (type == "operator") {
|
|
|
|
this->operatorPrecedence = precedenceMap[value];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static QMap<QString, int> precedenceMap;
|
|
|
|
QString value;
|
|
|
|
TokenType type;
|
|
|
|
int operatorPrecedence; // only relevant for operator tokens
|
|
|
|
};
|
|
|
|
|
|
|
|
class ParseUtil
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ParseUtil();
|
|
|
|
void strip_comment(QString*);
|
|
|
|
QList<QStringList>* parseAsm(QString);
|
|
|
|
int evaluateDefine(QString, QMap<QString, int>*);
|
2018-09-12 01:37:36 +01:00
|
|
|
QList<HealLocation>* parseHealLocs(QString);
|
2018-03-04 01:09:05 +00:00
|
|
|
private:
|
|
|
|
QList<Token> tokenizeExpression(QString expression, QMap<QString, int>* knownIdentifiers);
|
|
|
|
QList<Token> generatePostfix(QList<Token> tokens);
|
|
|
|
int evaluatePostfix(QList<Token> postfix);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PARSEUTIL_H
|