No Description

parseutil.h 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef PARSEUTIL_H
  2. #define PARSEUTIL_H
  3. #include <QString>
  4. #include <QList>
  5. enum TokenType {
  6. Number,
  7. Operator,
  8. };
  9. class Token {
  10. public:
  11. Token(QString value = "", QString type = "") {
  12. this->value = value;
  13. this->type = TokenType::Operator;
  14. if (type == "decimal" || type == "hex") {
  15. this->type = TokenType::Number;
  16. this->operatorPrecedence = -1;
  17. } else if (type == "operator") {
  18. this->operatorPrecedence = precedenceMap[value];
  19. }
  20. }
  21. static QMap<QString, int> precedenceMap;
  22. QString value;
  23. TokenType type;
  24. int operatorPrecedence; // only relevant for operator tokens
  25. };
  26. class ParseUtil
  27. {
  28. public:
  29. ParseUtil();
  30. void strip_comment(QString*);
  31. QList<QStringList>* parseAsm(QString);
  32. int evaluateDefine(QString, QMap<QString, int>*);
  33. private:
  34. QList<Token> tokenizeExpression(QString expression, QMap<QString, int>* knownIdentifiers);
  35. QList<Token> generatePostfix(QList<Token> tokens);
  36. int evaluatePostfix(QList<Token> postfix);
  37. };
  38. #endif // PARSEUTIL_H