-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.h
More file actions
52 lines (40 loc) · 1.56 KB
/
Token.h
File metadata and controls
52 lines (40 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// Created by LE, Duc Anh on 7/29/15.
//
#ifndef CLDEPARSER_TOKEN_H
#define CLDEPARSER_TOKEN_H
#include <string>
#include <vector>
#include "Common/IPrintable.h"
namespace CLDEParser {
class Token : public Common::IPrintable,
public std::enable_shared_from_this<Token> {
public:
Token(int id, const std::string &word) : _id{id}, _lexeme{word} { };
Token(int id, int index, std::string const &word) : _id{id}, _index{index}, _lexeme{word} { };
Token(int id, const char *word) : _id{id}, _lexeme{word} { };
Token(const Token &) = default;
Token(Token &&) = default;
Token &operator=(const Token &) = default;
Token &operator=(Token &&) = default;
virtual ~Token() = default;
// Accessors
int id() const { return _id; }
const std::string &lexeme() const { return _lexeme; }
// IPrintable
std::string CopyToString() const override;
std::string CopyToString(const Common::IPrintFormatter &formatter) const override;
protected:
int _id;
int _index;
std::string _lexeme;
};
using SPtrToken = std::shared_ptr<Token>;
using SPtrTokenVector = std::vector<SPtrToken>;
using SPtrTokenVectorIterator = SPtrTokenVector::const_iterator;
using SPtrTokenSet = std::vector<SPtrToken>;
using SPtrTokenSetIterator = SPtrTokenSet::iterator;
SPtrToken CreateSPtrToken(int id, const std::string &lexeme);
SPtrToken CreateSPtrToken(int id, int index, std::string const &lexeme);
}
#endif //CLDEPARSER_TOKEN_H