-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.h
71 lines (55 loc) · 1.31 KB
/
lexer.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 <cstdio>
#include <string>
#include <vector>
#include <list>
#include "types.h"
namespace core {
enum class tok_t {
invalid = 0,
unknown,
literal,
identifier,
oper,
// keywords
fn, ext, cif, cthen, pure, type,
from,
paren_open, paren_close,
semicolon,
curly_open, curly_close,
colon,
max
};
struct token {
tok_t first;
std::string second;
int line;
int col;
};
token get_token(input_file& f);
FILE* preprocess(FILE* f, FILE* tmp = nullptr);
struct token_stream {
tok_t type() const {
return c.front().first;
}
const std::string& current() const {
return c.front().second;
}
void step() {
c.pop_front();
}
bool empty() const {
return c.size() == 0;
}
int line() const {
return c.front().line;
}
int col() const {
return c.front().col;
}
void add_tokens(std::list<token>& other) {
c.splice(c.end(), other);
}
std::list<token> c;
};
}