summaryrefslogtreecommitdiff
path: root/Token.h
blob: 8f20b2ee32597350f92d5022fea03f3aeb565035 (plain)
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
#pragma once
#include <stdbool.h>

enum {
	TOK_NONE,
	TOK_WORD,
	TOK_STRING,
	TOK_INTEGER,
	/* single char toks */
	TOK_PAREN_OPEN,
	TOK_PAREN_CLOS,
	TOK_CURL_OPEN,
	TOK_CURL_CLOS,
	TOK_SQUAR_OPEN,
	TOK_SQUAR_CLOS,
	TOK_COLON,
	TOK_SEMICOLON,
	TOK_ASSIGN,
	TOK_COMMA,
	TOK_COMP_LESS,
	TOK_MODULO,
	TOK_STAR,
	/* double char toks */
	TOK_INCREMENT,
	TOK_COMP_EQ,
	TOK_COMP_NEQ,
	/* keywords */
	TOK_KW_VAR,
	TOK_KW_CONST,
	TOK_KW_FN,
};

union TokenValue {
	char c;
	int i;
	double d;
	bool b;
};

typedef struct Token {
	unsigned int type;
	unsigned int line;
	unsigned int column;
	union TokenValue v;
	char *s;
} Token;

void token_free(Token *tok);
void token_print(const Token *tok);
const char *token_type_str(const unsigned int type);