-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokenizer.h
49 lines (35 loc) · 861 Bytes
/
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
#pragma once
#include <variant>
#include <optional>
#include <string>
#include <istream>
struct SymbolToken {
std::string name;
bool operator==(const SymbolToken& other) const;
};
struct QuoteToken {
bool operator==(const QuoteToken&) const;
};
struct DotToken {
bool operator==(const DotToken&) const;
};
enum class BracketToken { OPEN, CLOSE };
struct ConstantToken {
int value;
bool operator==(const ConstantToken& other) const;
};
using Token = std::variant<ConstantToken, BracketToken, SymbolToken, QuoteToken, DotToken>;
class Tokenizer {
public:
Tokenizer(std::istream* in);
bool IsEnd();
void Next();
Token GetToken();
private:
void SkipSpaces();
bool IsBeginSymbol(char c);
bool IsSymbol(char c);
bool is_eof_ = false;
Token current_token_;
std::istream* current_stream_;
};