1
1

parse.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef PARSE_H
  2. #define PARSE_H
  3. #include <QString>
  4. #include <QVector>
  5. using namespace std;
  6. #include "instruction.h"
  7. enum TokenType {
  8. TokenTypeError,
  9. TokenTypeEOL,
  10. TokenTypeComma,
  11. TokenTypeHash,
  12. TokenTypePercent,
  13. TokenTypeDollar,
  14. TokenTypeNumber,
  15. TokenTypeWord,
  16. };
  17. struct Token {
  18. size_t line = 0;
  19. size_t column = 0;
  20. TokenType tokenType = TokenTypeError;
  21. size_t begin = 0;
  22. size_t end = 0;
  23. Token()
  24. : line(0)
  25. , column(0)
  26. , tokenType(TokenTypeError)
  27. , begin(0)
  28. , end(0)
  29. {}
  30. Token(const Token& tok)
  31. : line(tok.line)
  32. , column(tok.column)
  33. , tokenType(tok.tokenType)
  34. , begin(tok.begin)
  35. , end(tok.end)
  36. {}
  37. Token(size_t line, size_t column, TokenType tokenType, size_t begin, size_t end)
  38. : line(line)
  39. , column(column)
  40. , tokenType(tokenType)
  41. , begin(begin)
  42. , end(end)
  43. {}
  44. };
  45. QVector<Token> lex(const QString& code);
  46. struct ParseError {
  47. size_t line = 0;
  48. size_t column = 0;
  49. QString text;
  50. ParseError()
  51. : line(0)
  52. , column(0)
  53. , text("")
  54. {}
  55. ParseError(const ParseError& par)
  56. : line(par.line)
  57. , column(par.column)
  58. , text(par.text)
  59. {}
  60. ParseError(size_t line, size_t column, const QString& text)
  61. : line(line)
  62. , column(column)
  63. , text(text)
  64. {}
  65. };
  66. QVector<QVector<Instruction>> parse(const QString& code, const QVector<Token>& tokens, QVector<ParseError>& errors);
  67. #endif // PARSE_H