-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.h
More file actions
119 lines (103 loc) · 2.32 KB
/
Copy pathtype.h
File metadata and controls
119 lines (103 loc) · 2.32 KB
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
#ifndef TYPE_H
#define TYPE_H
typedef enum
{
TOKEN_KEYWORD,
TOKEN_IDENTIFIER,
TOKEN_OPERATOR,
TOKEN_ASSIGNMENT,
TOKEN_NUMBER,
TOKEN_STRING,
TOKEN_CHAR,
TOKEN_PREPROCESSOR,
TOKEN_PUNCTUATION,
} TokenType;
typedef struct
{
TokenType type;
int ligne;
char *valeur;
} Token;
typedef struct
{
Token *tokens;
int count;
} TokenList;
// Tous les types de nœud que tu vas rencontrer
typedef enum
{
NODE_BLOCK,
NODE_DECLARATION,
NODE_ASSIGNMENT,
NODE_IF,
NODE_FOR,
NODE_KEYWORD,
NODE_WHILE,
NODE_BINARY_EXPR, // + - * / % == != < <= > >= && ||
NODE_UNARY_EXPR, // ++ -- - !
NODE_LITERAL, // entier, flottant, char, string
NODE_IDENTIFIER,
NODE_POINTER // **
/* … ajoute tes autres types ici … */
} NodeType;
typedef struct ASTNode
{
NodeType type;
Token token; // optionnel : copie du token (utile pour littéraux ou identifiants)
int line; // numéro de ligne pour les erreurs
int pointer_level;
// enfant et frère pour naviguer dans l’arbre
struct ASTNode *first_child;
struct ASTNode *next_sibling;
// payload spécifique selon type de nœud
union
{
struct
{ // pour NARY (ex: programme ou bloc)
// aucun champ, on utilisera first_child / next_sibling
} nary;
struct
{ // pour binaire
struct ASTNode *left;
struct ASTNode *right;
} binary;
struct
{ // pour unaire
struct ASTNode *operande;
} unary;
struct
{ // pour littéral
union
{
int int_val;
double float_val;
char char_val;
char *str_val;
};
} literal;
struct
{ // pour identifiant
char *name;
} ident;
// tu peux ajouter d’autres payloads spécifiques…
} data;
} ASTNode;
typedef struct Pile
{
int index; // ID unique du bloc (utile pour debug ou table de symboles)
struct Pile *parent; // Pointeur vers le bloc parent
} Pile;
typedef struct T
{
char *type;
Token token;
char *name;
int index_block;
struct T *suivant;
} SymbolEntry;
typedef struct
{
SymbolEntry *tete;
int count;
} Analyse_Table;
#endif