Website Summary Files Commits Branches @commit @diff @stats
path: root / spasm / src / asm / token.hpp
blob: 2e69108f15f2e37924c3cc571a8fef3c38e97772 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef TOKEN_HPP
#define TOKEN_HPP

#include <string>

namespace SpasmImpl
{
namespace ASM
{
namespace Lexer
{
class Token
{
   public:
    enum Token_type
    {
        _NoArgBegin,
        Halt = _NoArgBegin,
        Dup,
        Pop,
        _OneArgBegin,
        PopTo = _OneArgBegin,
        PushFrom,
        Push,
        Print,
        Read,
        Call,
        Ret,
        Jump,
        _TwoArgBegin,
        JumpT = _TwoArgBegin,
        JumpF,
        Const,
        String,
        _ThreeArgBegin,
        Add = _ThreeArgBegin,
        Sub,
        Mul,
        Div,
        Mod,
        Less,
        LessEq,
        _NotOpCodeBegin,
        Label = _NotOpCodeBegin,
        Ident,
        // Register,
        Integer,
        XInteger,
        FloatingPoint,
        StringValue,
        EndInput,
        NotUsed
    };

    Token(Token_type = NotUsed);

    Token(Token_type, size_t, const char* = NULL, const char* = NULL);

    Token_type type() const;

    size_t lineno() const;

    int64_t value_int() const;
    void set_int(int64_t v) { _value_int = v; }

    double value_double() const { return _value_double; }

    const std::string& value_str() const;

   private:
    Token_type _type;

    size_t _lineno;

    int64_t _value_int;
    double _value_double;

    std::string _value_str;
};

class TokenStream
{
   public:
    virtual void push_token(const Token&) = 0;
    virtual ~TokenStream(){};
};

}  // namespace Lexer
}  // namespace ASM
}  // namespace SpasmImpl

#undef TOKENS

#endif