-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
parser.h
144 lines (127 loc) · 2.48 KB
/
parser.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma once
#include "functions.h"
#include "globals.h"
#include "names.h"
#include "tokenizer.h"
#include "types.h"
#include <stdbool.h>
#include <stddef.h>
struct expression;
typedef struct expressions {
struct expression *e[256];
size_t size;
} expressions;
typedef struct expression {
enum {
EXPRESSION_BINARY,
EXPRESSION_UNARY,
EXPRESSION_BOOLEAN,
EXPRESSION_FLOAT,
EXPRESSION_INT,
// EXPRESSION_STRING,
EXPRESSION_VARIABLE,
EXPRESSION_GROUPING,
EXPRESSION_CALL,
EXPRESSION_STATIC_MEMBER,
EXPRESSION_DYNAMIC_MEMBER,
EXPRESSION_INDEX,
EXPRESSION_CONSTRUCTOR
} kind;
type_ref type;
union {
struct {
struct expression *left;
operatorr op;
struct expression *right;
} binary;
struct {
operatorr op;
struct expression *right;
} unary;
bool boolean;
double number;
// char string[MAX_IDENTIFIER_SIZE];
name_id variable;
uint32_t index;
struct expression *grouping;
struct {
name_id func_name;
expressions parameters;
} call;
struct {
struct expression *left;
struct expression *right;
} member;
struct {
expressions parameters;
} constructor;
};
} expression;
struct statement;
typedef struct statements {
struct statement *s[256];
size_t size;
} statements;
typedef struct local_variable {
name_id name;
type_ref type;
uint64_t variable_id;
} local_variable;
typedef struct local_variables {
local_variable v[256];
size_t size;
} local_variables;
typedef struct block {
struct block *parent;
local_variables vars;
statements statements;
} block;
typedef struct statement {
enum {
STATEMENT_EXPRESSION,
STATEMENT_RETURN_EXPRESSION,
STATEMENT_IF,
STATEMENT_WHILE,
STATEMENT_DO_WHILE,
STATEMENT_BLOCK,
STATEMENT_LOCAL_VARIABLE
} kind;
union {
expression *expression;
struct {
expression *test;
struct statement *if_block;
expression *else_tests[64];
struct statement *else_blocks[64];
uint16_t else_size;
} iffy;
struct {
expression *test;
struct statement *while_block;
} whiley;
block block;
struct {
local_variable var;
expression *init;
} local_variable;
};
} statement;
typedef struct definition {
enum {
DEFINITION_FUNCTION,
DEFINITION_STRUCT,
DEFINITION_TEX2D,
DEFINITION_TEX2DARRAY,
DEFINITION_TEXCUBE,
DEFINITION_SAMPLER,
DEFINITION_CONST_CUSTOM,
DEFINITION_CONST_BASIC,
DEFINITION_BVH
} kind;
union {
function_id function;
global_id global;
type_id type;
};
} definition;
void parse(const char *filename, tokens *tokens);