#ifndef PARSEUTIL_H #define PARSEUTIL_H #include "heallocation.h" #include "log.h" #include #include #include #include enum TokenClass { Number, Operator, Error, }; class Token { public: Token(QString value = "", QString type = "") { this->value = value; this->type = TokenClass::Operator; if (type == "decimal" || type == "hex") { this->type = TokenClass::Number; this->operatorPrecedence = -1; } else if (type == "operator") { this->operatorPrecedence = precedenceMap[value]; } else if (type == "error") { this->type = TokenClass::Error; } } static QMap precedenceMap; QString value; TokenClass type; int operatorPrecedence; // only relevant for operator tokens }; class ParseUtil { public: ParseUtil(); void set_root(QString); QString readTextFile(QString); void strip_comment(QString*); QList* parseAsm(QString); int evaluateDefine(QString, QMap*); QStringList readCArray(QString text, QString label); QMap readNamedIndexCArray(QString text, QString label); QString readCIncbin(QString text, QString label); QMap readCDefines(QString filename, QStringList prefixes); void readCDefinesSorted(QString, QStringList, QStringList*); QList* getLabelMacros(QList*, QString); QStringList* getLabelValues(QList*, QString); bool tryParseJsonFile(QJsonDocument *out, QString filepath); bool ensureFieldsExist(QJsonObject obj, QList fields); private: QString root; QString text; QString file; QList tokenizeExpression(QString expression, QMap* knownIdentifiers); QList generatePostfix(QList tokens); int evaluatePostfix(QList postfix); void error(QString message, QString expression); }; #endif // PARSEUTIL_H