Website Summary Files Commits Branches @commit @diff @stats
path: root / spasm / src / asm / token.cpp
blob: 6c88bef57b8575699984f3b3c5efcc5b460e3104 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <memory>
#include <new>
#include <queue>
#include <string>

#include "token.hpp"

namespace SpasmImpl
{
namespace ASM
{
namespace Lexer
{
Token::Token(Token_type type)
    : _type(type), _lineno(0), _value_int(0), _value_str("")
{
}

Token::Token(Token::Token_type type,
             size_t lineno,
             const char* start,
             const char* end)
    : _type(type), _lineno(lineno)
{
    if (_type == integer || _type == xinteger)
    {
        _value_int = strtol(start, NULL, 0);
    }
    else if (_type == ident)
    {
        if (end)
        {
            _value_str = std::string(start, end);
        }
        else
        {
            _value_str = std::string(start);
        }
    }
}

Token::Token_type Token::type() const
{
    return _type;
}

int Token::value_int() const
{
    return _value_int;
}

const std::string& Token::value_str() const
{
    return _value_str;
}

size_t Token::lineno() const
{
    return _lineno;
}

}  // namespace Lexer

}  // namespace ASM
}  // namespace SpasmImpl