blob: b394da9aa165823aaf075cceb83ef4820bbc3194 (
plain) (
blame)
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
|
#include <iostream>
#include <memory>
#include <new>
#include "lexer.hpp"
#include "token.hpp"
#include "tokenizer.hpp"
namespace SpasmImpl
{
namespace ASM
{
namespace Lexer
{
Tokenizer::Tokenizer(std::istream& istr)
: _lexer(new Lexer(istr, 1024)), end_input(false)
{
_lexer->buffer_init();
}
void Tokenizer::push_token(const Token& token)
{
_tokens.push(token);
if (token.type() == Token::EndInput)
end_input = true;
}
Token Tokenizer::next_token()
{
Token t(Token::EndInput);
if (!_tokens.empty())
{
t = _tokens.front();
_tokens.pop();
}
else if (!end_input)
{
while (_tokens.empty())
{
_lexer->read();
_lexer->tokenize(*this);
}
t = _tokens.front();
_tokens.pop();
}
return t;
}
} // namespace Lexer
} // namespace ASM
} // namespace SpasmImpl
|