-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToken.hpp
75 lines (63 loc) · 1.61 KB
/
Token.hpp
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
// Copyright 2020 <Copyright hulin>
#ifndef TOKEN_HPP_
#define TOKEN_HPP_
#include <string>
#include <memory>
using std::string;
using std::shared_ptr;
class LoxCallable;
class LoxClass;
class LoxInstance;
typedef enum {
LEFT_PAREN, RIGHT_PAREN, LEFT_BRACE, RIGHT_BRACE,
COMMA, DOT, MINUS, PLUS, SEMICOLON, SLASH, STAR,
// One or two character tokens.
BANG, BANG_EQUAL,
EQUAL, EQUAL_EQUAL,
GREATER, GREATER_EQUAL,
LESS, LESS_EQUAL,
// Literals.
IDENTIFIER, STRING, NUMBER,
// Keywords.
AND, CLASS, ELSE, FALSE, FUN, FOR, IF, NIL, OR,
PRINT, RETURN, SUPER, THIS, TRUE, VAR, WHILE,
TOKEN_EOF
} TokenType;
class Object {
public:
typedef enum {
Object_str,
Object_num,
Object_bool,
Object_nil,
Object_fun,
Object_instance,
Object_class,
} Object_type;
string str;
double num;
bool boolean;
int* nil;
Object_type type;
string toString();
shared_ptr<LoxCallable> function;
shared_ptr<LoxInstance> instance;
shared_ptr<LoxClass> lox_class;
static Object make_num_obj(double num);
static Object make_str_obj(string str);
static Object make_bool_obj(bool boolean);
static Object make_nil_obj();
static Object make_fun_obj(shared_ptr<LoxCallable> function_);
static Object make_instance_obj(shared_ptr<LoxInstance> instance_);
static Object make_class_obj(shared_ptr<LoxClass> lox_class_);
};
class Token {
public:
Token(TokenType type, string lexeme, Object literal, int line);
string toString();
TokenType type;
string lexeme;
Object literal;
int line;
};
#endif // TOKEN_HPP_