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
|
#pragma once
#include <stdbool.h>
#include <stddef.h>
// names longer than this are refused, nobody needs a longer name
#define NAME_LENGTH_MAX 15
enum NodeKind
{
NODE_CHAR,
NODE_PARAMETER,
TYPE_VOID,
TYPE_INT32,
TYPE_BYTE,
TYPE_SIZE,
TYPE_REMOVE_CV,
TYPE_ARRAY,
TYPE_CONDITIONAL,
TYPE_DECLTYPE,
TYPE_CHAR,
TYPE_CHAR_CONSTANT,
TYPE_TUPLE,
TYPE_INVOKE,
VALUE_DIFFERENCE,
VALUE_SUM,
VALUE_PRODUCT,
VALUE_QUOTIENT,
VALUE_EXTENT,
VALUE_TUPLE_SIZE,
VALUE_INTEGRAL_CONSTANT,
VALUE_CONDITIONAL,
VALUE_VARIABLE,
VALUE_DECLVAL,
COND_TRUE,
COND_FALSE,
COND_IS_SAME,
COND_EQUAL,
COND_LESS,
STMT_DECLARE,
STMT_UNDECLARE,
STMT_ENABLE_IF,
STMT_REPEAT,
STMT_EMIT,
STMT_STATIC_ASSERT,
STMT_DEFINE,
STMT_RETURN
};
struct Name
{
char text[NAME_LENGTH_MAX + 1];
size_t length;
};
struct Node
{
enum NodeKind kind;
int line;
char character;
char name[NAME_LENGTH_MAX + 1];
struct Node* first;
struct Node* second;
struct Node* third;
struct Node* body;
struct Node* next;
};
void name_init(struct Name* name);
bool name_push(struct Name* name, char character);
struct Node* node_leaf(enum NodeKind kind);
struct Node* node_char(char character);
struct Node* node_unary(enum NodeKind kind, struct Node* first);
struct Node* node_binary(enum NodeKind kind, struct Node* first, struct Node* second);
struct Node* node_ternary(enum NodeKind kind, struct Node* first, struct Node* second,
struct Node* third);
struct Node* node_named(enum NodeKind kind, const struct Name* name, struct Node* first);
struct Node* node_block(enum NodeKind kind, struct Node* first, struct Node* body);
struct Node* node_append(struct Node* list, struct Node* node);
void node_free(struct Node* node);
|