-
Notifications
You must be signed in to change notification settings - Fork 7
/
parseutil.h
executable file
·44 lines (39 loc) · 1.12 KB
/
parseutil.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
#ifndef PARSEUTIL_H
#define PARSEUTIL_H
#include <QString>
#include <QList>
#include <QMap>
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>*);
private:
QList<Token> tokenizeExpression(QString expression, QMap<QString, int>* knownIdentifiers);
QList<Token> generatePostfix(QList<Token> tokens);
int evaluatePostfix(QList<Token> postfix);
};
#endif // PARSEUTIL_H