설명 없음

parseutil.h 1.1KB

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