-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokenStorage.cpp
More file actions
44 lines (34 loc) · 829 Bytes
/
TokenStorage.cpp
File metadata and controls
44 lines (34 loc) · 829 Bytes
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
//
// Created by nisal on 7/19/2023.
//
#include "TokenStorage.h"
void TokenStorage::setTokens() {
Token token;
do
{
token = lexer->getNextToken();
tokens.push_back(token);
} while (token.type != token_type::END_OF_FILE);
}
TokenStorage &TokenStorage::getInstance() {
return instance;
}
void TokenStorage::setLexer(Lexer &lexer_) {
this->lexer = &lexer_;
setTokens();
currentPosition = 0;
}
Token &TokenStorage::top() {
return tokens[currentPosition];
}
Token &TokenStorage::pop() {
return tokens[currentPosition++];
}
[[maybe_unused]] void TokenStorage::reset() {
currentPosition = 0;
}
void TokenStorage::destroyInstance() {
instance.lexer = nullptr;
instance.tokens.clear();
}
TokenStorage TokenStorage::instance; // Initialize the static instance