-
Notifications
You must be signed in to change notification settings - Fork 8
/
Tokenizer.hpp
54 lines (43 loc) · 1.02 KB
/
Tokenizer.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
#pragma once
#include <vector>
#include <string>
namespace simpleparser {
using namespace std;
enum TokenType {
WHITESPACE, // No token ever has this type.
IDENTIFIER,
INTEGER_LITERAL,
DOUBLE_LITERAL,
STRING_LITERAL,
OPERATOR,
STRING_ESCAPE_SEQUENCE,
POTENTIAL_DOUBLE,
POTENTIAL_COMMENT,
COMMENT
};
static const char *sTokenTypeStrings[] = {
"WHITESPACE",
"IDENTIFIER",
"INTEGER_LITERAL",
"DOUBLE_LITERAL",
"STRING_LITERAL",
"OPERATOR",
"STRING_ESCAPE_SEQUENCE",
"POTENTIAL_DOUBLE",
"POTENTIAL_COMMENT",
"COMMENT"
};
class Token {
public:
enum TokenType mType{WHITESPACE};
string mText;
size_t mLineNumber{0};
void debugPrint() const;
};
class Tokenizer {
public:
vector<Token> parse(const string &inProgram);
private:
void endToken(Token &token, vector<Token> &tokens);
};
}