-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.h
54 lines (40 loc) · 787 Bytes
/
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
#pragma once
#include "common.h"
namespace nlang {
enum token {
T_UNKNOWN,
#define TOKEN(name, text) T_ ## name,
#include "tokens.inc.h"
token_count
};
class lexer {
public:
lexer(const char* src, int w);
void next();
int _tline, _tcol;
token _ttok;
std::string _tlit;
private:
void ident();
void number(u32 c);
void line_comment();
void full_comment();
void error(std::string err);
u32 getr();
void ungetr();
void ungetr2();
void start_lit();
std::string stop_lit();
const char* _src;
int _r0, _r, _w;
int _line0, _line;
int _col0, _col;
int _suf;
bool _nlsemi;
};
std::string token_to_string(token tk);
std::string token_to_text(token tk);
bool token_is_operator(token tk);
int token_operator_prec(token tk);
bool token_operator_lassoc(token tk);
}