diff options
Diffstat (limited to 'src/bytecode/lexer.h')
-rwxr-xr-x | src/bytecode/lexer.h | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/src/bytecode/lexer.h b/src/bytecode/lexer.h deleted file mode 100755 index 3cadf30..0000000 --- a/src/bytecode/lexer.h +++ /dev/null | |||
@@ -1,92 +0,0 @@ | |||
1 | #ifndef BDL_LEXER_H | ||
2 | #define BDL_LEXER_H | ||
3 | |||
4 | #include "string_view.h" | ||
5 | |||
6 | typedef enum TokenType { | ||
7 | TOKEN_UNKNOWN = 0, | ||
8 | |||
9 | // Parentheses. | ||
10 | TOKEN_LPAREN, | ||
11 | TOKEN_RPAREN, | ||
12 | |||
13 | // Primitive types. | ||
14 | TOKEN_FIXNUM, | ||
15 | TOKEN_SYMBOL, | ||
16 | TOKEN_STRING, | ||
17 | |||
18 | // Keywords. | ||
19 | TOKEN_NIL, | ||
20 | TOKEN_QUOTE, | ||
21 | TOKEN_TRUE, | ||
22 | TOKEN_FALSE, | ||
23 | TOKEN_IF, | ||
24 | TOKEN_ELSE, | ||
25 | TOKEN_DEF, | ||
26 | TOKEN_SET, | ||
27 | TOKEN_FUN, | ||
28 | TOKEN_LAMBDA, | ||
29 | TOKEN_DISPLAY, | ||
30 | TOKEN_PRINT, | ||
31 | TOKEN_NEWLINE, | ||
32 | |||
33 | // Arithmetic. | ||
34 | TOKEN_ADD, | ||
35 | TOKEN_SUB, | ||
36 | TOKEN_MUL, | ||
37 | TOKEN_DIV, | ||
38 | TOKEN_MOD, | ||
39 | |||
40 | // Boolean comparisons. | ||
41 | TOKEN_NOT, | ||
42 | TOKEN_AND, | ||
43 | TOKEN_OR, | ||
44 | TOKEN_EQUAL, | ||
45 | TOKEN_LESS, | ||
46 | TOKEN_GREATER, | ||
47 | TOKEN_LESS_EQUAL, | ||
48 | TOKEN_GREATER_EQUAL, | ||
49 | |||
50 | TOKEN_EOF, | ||
51 | } TokenType; | ||
52 | |||
53 | typedef struct Token { | ||
54 | TokenType type; | ||
55 | StringView value; | ||
56 | size_t line; | ||
57 | size_t column; | ||
58 | } Token; | ||
59 | |||
60 | typedef struct Scanner { | ||
61 | StringView current; | ||
62 | size_t line_number; | ||
63 | size_t col_number; | ||
64 | size_t offset; | ||
65 | } Scanner; | ||
66 | |||
67 | // Print a token to standard output for debugging purposes. | ||
68 | void print_token(Token tok); | ||
69 | |||
70 | // Same functionality as the ScanView pairs, but keeping track of line and | ||
71 | // column numbers. | ||
72 | char scan_next(Scanner *scanner); | ||
73 | char scan_peek(const Scanner *scanner); | ||
74 | |||
75 | // Check if the current scanner still have characters left. | ||
76 | bool scan_has_next(const Scanner *scanner); | ||
77 | |||
78 | // Advance the scanner until we ran out of whitespace. | ||
79 | void skip_whitespace(Scanner *scanner); | ||
80 | |||
81 | // Check if a given character is a delimiter. | ||
82 | bool is_delimiter(char c); | ||
83 | |||
84 | // Extract the token type from the current string. | ||
85 | TokenType find_primitive_type(const StringView value); | ||
86 | |||
87 | // Generate a list of tokens from the given string. | ||
88 | Token * tokenize(const StringView *sv); | ||
89 | |||
90 | #define TOK_BUF_CAP 256 | ||
91 | |||
92 | #endif // BDL_LEXER_H | ||