-
Notifications
You must be signed in to change notification settings - Fork 0
/
lex.hpp
60 lines (49 loc) · 914 Bytes
/
lex.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
54
55
56
57
58
59
60
#pragma once
#include <string>
enum TokenID {
TOKEN_EOF = 0,
// keywords
TOKEN_BREAK,
TOKEN_ELSE,
TOKEN_FOR,
TOKEN_FUNC,
TOKEN_IF,
TOKEN_RETURN,
TOKEN_VAR,
// operators and punctuation
TOKEN_PLUS,
TOKEN_MINUS,
TOKEN_STAR,
TOKEN_SLASH,
TOKEN_PERCENT,
TOKEN_LOGIC_AND,
TOKEN_LOGIC_OR,
TOKEN_EQ, // ==
TOKEN_LT,
TOKEN_GT,
TOKEN_ASSIGN, // =
TOKEN_BANG,
TOKEN_NEQ,
TOKEN_LEQ, // <=
TOKEN_GEQ, // >=
TOKEN_LPAREN,
TOKEN_RPAREN,
TOKEN_LBRACE,
TOKEN_RBRACE,
TOKEN_COMMA,
TOKEN_SEMICOLON,
// identifiers
TOKEN_ID,
TOKEN_INT,
TOKEN_STRING,
TOKEN_UNSET,
};
const char *token_to_string( TokenID token );
struct Tokinfo {
TokenID token = TOKEN_UNSET;
// attributes
int linenum = 1;
std::string lexeme;
};
Tokinfo lex();
void unlex( Tokinfo t );