-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexer.h
43 lines (34 loc) · 1.33 KB
/
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
#pragma once
#include "vector.h"
typedef enum {
// Single and double symbols
Tok_Equal, Tok_EqualEqual, Tok_BangEqual, Tok_Less, Tok_LessEqual, Tok_Greater, Tok_GreaterEqual,
Tok_Plus, Tok_Minus, Tok_Star, Tok_Slash, Tok_Exp,
Tok_PlusEqual, Tok_MinusEqual, Tok_StarEqual, Tok_SlashEqual, Tok_ExpEqual,
Tok_Colon, Tok_Dot, Tok_Comma, Tok_LParen, Tok_RParen, Tok_LSquare, Tok_RSquare,
// Keywords
Tok_Global, Tok_For, Tok_To, Tok_Next, Tok_While, Tok_EndWhile, Tok_Do, Tok_Until, Tok_If, Tok_Then, Tok_ElseIf, Tok_Else, Tok_EndIf,
Tok_Switch, Tok_Case, Tok_Default, Tok_EndSwitch,
Tok_And, Tok_Or, Tok_Not, Tok_Mod, Tok_Div,
Tok_Function, Tok_Return, Tok_EndFunction, Tok_Procedure, Tok_EndProcedure, Tok_ByVal, Tok_ByRef,
Tok_Class, Tok_EndClass, Tok_Inherits, Tok_Public, Tok_Private, Tok_Super, Tok_Self, Tok_New,
Tok_Array,
// Literals + identifiers
Tok_True, Tok_False, Tok_StringLit, Tok_IntLit, Tok_FloatLit, Tok_Nil, Tok_Identifier,
// EOF
Tok_EOF
} TokType;
typedef struct {
TokType type;
char* start;
int length;
int line, col;
} Token;
DECL_VEC(Token, TokList)
typedef TokList LexOutput;
// ALLOCATES!
//
// Copy token contents into a standalone, null-terminated string
char* tokText(Token tok);
void destroyLexOutput(LexOutput lo);
LexOutput lex(char* source);