-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenizer.h
71 lines (48 loc) · 1.15 KB
/
tokenizer.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
#pragma once
#include <variant>
#include <string>
#include <iostream>
struct SymbolToken {
std::string name;
bool operator==(const SymbolToken& other) const {
return name == other.name;
}
};
struct QuoteToken {
bool operator==(const QuoteToken&) const {
return true;
}
};
struct DotToken {
bool operator==(const DotToken&) const {
return true;
}
};
enum class BracketToken { OPEN, CLOSE };
struct ConstantToken {
int value;
bool operator==(const ConstantToken& other) const {
return value == other.value;
}
};
using Token = std::variant<ConstantToken, BracketToken, SymbolToken, QuoteToken, DotToken>;
bool CheckCloseBracketToken(const Token& a);
bool CheckOpenBracketToken(const Token& a);
bool CheckDotToken(const Token& a);
class Tokenizer {
public:
Tokenizer(std::istream* in);
Token GetToken();
bool IsEnd();
void Next();
private:
bool ready_{false};
Token parsed_token_;
std::istream* in_;
bool IsStart(char c);
bool IsInner(char c);
bool IsDigit(char c);
bool IsPM(char c);
bool GoodSymbol(char c);
void SkipWhitespaces();
};