-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.h
More file actions
44 lines (39 loc) · 1.47 KB
/
Copy pathscanner.h
File metadata and controls
44 lines (39 loc) · 1.47 KB
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
#ifndef clox_scanner_h
#define clox_scanner_h
// In clox the scanner produces a synthetic "error" token for an error
// and passes it over to the compiler. This way, the compiler knows an
// error occured and can kick off error recovery before reporting it.
typedef enum {
// Single-character tokens.
TOKEN_LEFT_PAREN, TOKEN_RIGHT_PAREN,
TOKEN_LEFT_BRACE, TOKEN_RIGHT_BRACE,
TOKEN_COMMA, TOKEN_DOT, TOKEN_MINUS, TOKEN_PLUS,
TOKEN_SEMICOLON, TOKEN_SLASH, TOKEN_STAR,
// One or two character tokens.
TOKEN_BANG, TOKEN_BANG_EQUAL,
TOKEN_EQUAL, TOKEN_EQUAL_EQUAL,
TOKEN_GREATER, TOKEN_GREATER_EQUAL,
TOKEN_LESS, TOKEN_LESS_EQUAL,
// Literals.
TOKEN_IDENTIFIER, TOKEN_STRING, TOKEN_NUMBER,
// Keywords.
TOKEN_AND, TOKEN_CLASS, TOKEN_ELSE, TOKEN_FALSE,
TOKEN_FOR, TOKEN_FUN, TOKEN_IF, TOKEN_NIL, TOKEN_OR,
TOKEN_PRINT, TOKEN_RETURN, TOKEN_SUPER, TOKEN_THIS,
TOKEN_TRUE, TOKEN_VAR, TOKEN_WHILE,
TOKEN_ERROR, TOKEN_EOF
} TokenType;
// We use the original source string as our character store. We represent
// a lexeme by a pointer to its first character and the number of characters
// it contains. This means we don't need to worry about managing memory for
// lexemes at all and we can freely copy tokens around. As long as the main
// source code string outlives all of the tokens, everytying works fine.
typedef struct {
TokenType type;
const char* start;
int length;
int line;
} Token;
void initScanner(const char* source);
Token scanToken();
#endif