blob: 7cb50e0fa2c18135e0752ebad0a81495f19999c7 [file] [log] [blame]
swissChili7babd922021-12-02 22:46:48 -08001#include "Token.h"
2
3Token::Token(const Token &other) {
4 *this = other;
5}
6
7Token::Token(QChar symbol) {
8 _type = SYM;
9 _charVal = symbol;
10}
11
12Token::Token(QString &&identifier) {
13 _type = IDENT;
14 _stringVal = identifier;
15}
16
17Token::Token(QList<Token> &&parenthesized) {
18 _type = PAREN;
19 _listVal = new QList<Token>(parenthesized);
20}
21
22Token::Token(char varType, const QString &&name) {
23 _type = VAR;
24 _charVal = varType;
25 _stringVal = name;
26}
27
28Token::~Token() {
29 // Стерать нулевые пойнтеры безопасно
30 delete _listVal;
31}
32
33bool Token::isSym() {
34 return _type == SYM;
35}
36
37bool Token::isIdent() {
38 return _type == IDENT;
39}
40
41bool Token::isParen() {
42 return _type == PAREN;
43}
44
45bool Token::isVar() {
46 return _type == VAR;
47}
48
49Token::Token() : Token("Null") {
50}
51
52bool Token::operator==(const Token &other) {
53 return _type == other._type
54 && _stringVal == other._stringVal
55 && _charVal == other._charVal
56 && (_listVal == nullptr || *_listVal == (*other._listVal));
57}
58
59QList<Token> Token::parenContent() {
60 if (isParen() && _listVal) {
61 return *_listVal;
62 } else {
63 return {};
64 }
65}