-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGosTokenizer.h
101 lines (96 loc) · 2.02 KB
/
GosTokenizer.h
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
95
96
97
98
99
100
101
#pragma once
#include <stack>
#include "GosVM.h"
namespace Gos {
enum TokenType {
USING,
CLASS,
VAR,
FUNC,
NEW,
LAMBDA,
FOR,
FOREACH,
IF,
ELSE,
WHILE,
RETURN,
BREAK,
CONTINUE,
AS,
ASSIGN,
ASSIGN_ADD,
ASSIGN_SUB,
ASSIGN_MUL,
ASSIGN_DIV,
ASSIGN_REM,
ASSIGN_XOR,
ASSIGN_AND,
ASSIGN_OR,
INC,
DEC,
ADD,
SUB,
MUL,
ADDR,
DIV,
REM,
XOR,
E,
NE,
L,
G,
LE,
GE,
NOT,
AND,
OR,
SYMBOL,
NUMBER,
STRING,
COM,
SEM,
DOT,
COLON,
QUESTION,
L_ROUND,
R_ROUND,
L_SQUARE,
R_SQUARE,
L_CURLY,
R_CURLY,
NONE,
};
struct GosToken {
static const std::string TokenName[];
TokenType type;
int line;
int8_t numType;
GosVM::RTConstNum num;
std::string str;
GosToken();
GosToken(TokenType type, int line);
GosToken(TokenType type, const std::string& str, int line);
GosToken(TokenType type, int8_t numType, GosVM::RTConstNum num, int line);
std::string ToString() const;
};
class GosTokenizer {
private:
std::istream& fin;
int lineCount;
std::string inputName;
int pos;
std::vector<GosToken> tokens;
GosToken ReadToken();
std::function<bool()> errorCallback;
public:
GosTokenizer(std::istream& fin, const std::string& inputName);
const GosToken& GetToken();
int GetProgress();
void RestoreProgress(int progress);
void BackToken();
void EatToken(TokenType type);
void SetErrorCallback(std::function<bool()> callback);
bool IsEOF();
};
}