swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <QList> |
| 4 | #include <QChar> |
| 5 | |
| 6 | class Token { |
| 7 | public: |
| 8 | Token(); |
| 9 | Token(const Token &other); |
| 10 | |
| 11 | explicit Token(QChar symbol); |
| 12 | explicit Token(QString &&identifier); |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame^] | 13 | explicit Token(QList<Token> parenthesized); |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 14 | Token(char varType, const QString &&name); |
| 15 | |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 16 | bool operator ==(const Token &other) const; |
| 17 | bool operator !=(const Token &other) const; |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 18 | |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame^] | 19 | bool isSym() const; |
| 20 | bool isIdent() const; |
| 21 | bool isParen() const; |
| 22 | bool isVar() const; |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 23 | |
| 24 | QList<Token> parenContent(); |
| 25 | |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 26 | char varType() const; |
| 27 | const QString &name() const; |
| 28 | |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame^] | 29 | operator QString() const; |
| 30 | |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 31 | enum Type { |
| 32 | SYM, IDENT, PAREN, VAR, |
| 33 | }; |
| 34 | |
swissChili | d17b5a1 | 2021-12-05 20:46:42 -0800 | [diff] [blame^] | 35 | static QString typeToString(int type); |
| 36 | |
| 37 | int type() const; |
| 38 | |
| 39 | private: |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 40 | int _type = 0; |
| 41 | QString _stringVal = ""; |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 42 | QList<Token> _listVal; |
swissChili | 7babd92 | 2021-12-02 22:46:48 -0800 | [diff] [blame] | 43 | QChar _charVal = 0; |
| 44 | }; |
swissChili | 3e98c06 | 2021-12-04 22:07:38 -0800 | [diff] [blame] | 45 | |
| 46 | using LTok = QList<Token>; |