-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanner.h
executable file
·76 lines (61 loc) · 1.85 KB
/
scanner.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
72
73
74
75
76
#ifndef scanner_h_hammer
#define scanner_h_hammer
// Type :: num_of_first - num_of_last (inclusive)
typedef enum {
// Symbols :: 0 - 6
TOKEN_LEFT_PAREN, TOKEN_RIGHT_PAREN,
TOKEN_LEFT_BRACKET, TOKEN_RIGHT_BRACKET,
TOKEN_LEFT_BRACE, TOKEN_RIGHT_BRACE,
TOKEN_SEMICOLON,
// Operators :: 7 - 29
TOKEN_DOT, TOKEN_DOT_DOT, TOKEN_COMMA,
TOKEN_PLUS, TOKEN_MINUS,
TOKEN_STAR, TOKEN_SLASH, TOKEN_PERCENT,
TOKEN_UCARET,
TOKEN_EQUALS, TOKEN_RECEIVE,
TOKEN_COLON, TOKEN_ROCKET,
TOKEN_GREATER, TOKEN_LESS,
TOKEN_GREATER_EQUALS, TOKEN_LESS_EQUALS,
TOKEN_BANG_EQUALS, TOKEN_EQUALS_EQUALS,
TOKEN_DOLLAR,
TOKEN_QUESTION, TOKEN_BANG, TOKEN_PIPE, TOKEN_SPIGOT,
TOKEN_CUSTOM,
// Literals :: 30 - 40
TOKEN_IDENTIFIER, TOKEN_INTEGER, TOKEN_BINARY, TOKEN_FLOAT, TOKEN_STRING,
TOKEN_FORMAT_STRING, TOKEN_CHAR, TOKEN_TRUE, TOKEN_FALSE, TOKEN_UNIT,
TOKEN_WILDCARD, TOKEN_GLYPH,
// Keywords :: 41 - 56
TOKEN_VAR, TOKEN_LET, TOKEN_FUNC,
TOKEN_IF, TOKEN_THEN, TOKEN_ELSE,
TOKEN_MATCH,
TOKEN_CONS, TOKEN_CAR, TOKEN_CDR,
TOKEN_AND, TOKEN_OR, TOKEN_IN,
TOKEN_PUT, TOKEN_PRINT,
TOKEN_RETURN,
// Types :: 57 - 64
TOKEN_BOOL_TN,
TOKEN_INT_TN, TOKEN_FLOAT_TN,
TOKEN_CHAR_TN, TOKEN_STR_TN,
TOKEN_LIST_TN, TOKEN_REC_TN,
TOKEN_UNIT_TN,
// Control :: 65 - 68
TOKEN_BREAK, TOKEN_SOF, TOKEN_EOF, TOKEN_ERROR
} TokenType;
typedef struct {
TokenType type;
const char* start;
int length;
int line;
} Token;
typedef struct {
const char* trueBeginning;
const char* start;
const char* current;
int line;
} Scanner;
void debugScanner(const char* source);
Token scanToken(Scanner* scanner);
Token debugScanToken(Scanner* scanner);
void printToken(const Token* token);
void initScanner(Scanner* scanner, const char* source);
#endif