mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-19 23:25:09 -05:00
Evaluate C define expressions using postfix evaluation, and rename 'asm' to 'parseutil'
This commit is contained in:
43
parseutil.h
Executable file
43
parseutil.h
Executable file
@@ -0,0 +1,43 @@
|
||||
#ifndef PARSEUTIL_H
|
||||
#define PARSEUTIL_H
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user