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
77
78
79
|
/**
* @file parser.h
* @author x221e
* @brief parser
* @description
* I am opting-in to AST producing compiler design. It is not strictly
* needed in this context, however, it will produce optimization benefits
* in the future.
*
* @warning DEFINETLY NEEDS ARENA ALLOC IMPL // prototyping one under lib/
*/
#ifndef PARSER_H
#define PARSER_H
#include <stddef.h>
#include <lex.h>
typedef struct vector vector;
struct parser {
struct region *tokens;
struct vector *result; //TODO: replace with arena,, temporary
struct region *buffer;
size_t size;
size_t pos;
int error;
};
enum node_type { // Or should I use macros???
N_INVALID = -1,
N_EXPR = 0,
N_LITERAL = 1,
N_UNARY,
N_BINARY,
};
enum data_type {
DT_INVALID = -1,
DT_UNSIGNED64,
DT_UNSIGNED32,
DT_UNSIGNED16,
DT_UNSIGNED8,
};
struct node_primary {
enum node_type ntype;
enum data_type type;
int is_number;
union {
size_t number;
char* str;
} value;
};
struct node_unary {
enum node_type ntype;
struct token operator;
void *expr;
};
struct node_binary {
enum node_type ntype;
struct token operator;
void *left;
void *right;
};
struct node {
enum node_type ntype;
};
void parser_parse(struct parser *p);
#endif
|