-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.c
More file actions
85 lines (74 loc) · 2.1 KB
/
Copy pathMain.c
File metadata and controls
85 lines (74 loc) · 2.1 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Lexer/lexer.h"
#include "Parser/parser.h"
#include "Analyser_Semantic/analyser_semantic.h"
char *Read_file(const char *nom_fichier)
{
FILE *fichier = fopen(nom_fichier, "r");
if (fichier == NULL)
{
perror("Erreur lors de l'ouverture du fichier");
return NULL;
}
// Aller à la fin du fichier pour connaître sa taille
fseek(fichier, 0, SEEK_END);
long taille = ftell(fichier);
rewind(fichier); // Retour au début
if (taille <= 0)
{
fclose(fichier);
return NULL; // Fichier vide
}
// Allouer la mémoire
char *buffer = malloc(taille + 1);
if (buffer == NULL)
{
perror("Erreur d'allocation mémoire");
fclose(fichier);
return NULL;
}
// Lire le fichier en une seule fois
size_t lu = fread(buffer, 1, taille, fichier);
buffer[lu] = '\0'; // Assurer une fin de chaîne correcte
fclose(fichier);
return buffer;
}
int main()
{
char *buffer = Read_file("test2.txt");
if (buffer)
{
printf("hello");
// LEXER
TokenList *list = malloc(sizeof(TokenList));
list->tokens = NULL;
list->count = 0;
lexer(buffer, list);
for (int i = 0; i < list->count; ++i)
{
printf("TOKEN[%d] type=%d ligne=%d valeur=%s\n", i, list->tokens[i].type, list->tokens[i].ligne, list->tokens[i].valeur);
}
// PARSER
ASTNode *root = new_ATS(NODE_BLOCK, NULL, NULL, list->tokens[0], list->tokens[0].ligne);
int current_block_index = 0;
parser(list, root, ¤t_block_index);
// ANALYSER
Analyse_Table *table = malloc(sizeof(Analyse_Table));
if (!table)
{
perror("malloc table");
exit(EXIT_FAILURE);
}
table->count = 0;
table->tete = NULL;
int index = 0;
analyser_semantique(root, table);
print_symbol_table(table);
printf("code sources valide\n");
free_token_list(list);
free(buffer);
}
return 0;
}