-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompilo.c
108 lines (95 loc) · 2.86 KB
/
compilo.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "analyseur_lexical_flex.h"
FILE *yyin;
extern char *yytext; // déclaré dans analyseur_lexical
/***********************************************************************
* Fonction auxiliaire appelée par le compilo en mode -l pour tester
* l'analyseur lexical et, étant donné un programme en entrée, afficher
* la liste des tokens.
******************************************************************************/
void test_yylex(FILE *yyin) {
int uniteCourante;
char nom[100], valeur[100];
while( ( uniteCourante = yylex() ) != 0 ) {
nom_token( uniteCourante, nom, valeur );
printf("%s\t%s\t%s\n", yytext, nom, valeur);
}
}
/**********************************************************************/
void affiche_message_aide(char *nom_prog) {
fprintf(stderr, "usage: %s OPT fichier_source\n", nom_prog);
fprintf(stderr, "\t-l affiche les tokens de l'analyse lexicale\n");
/*fprintf(stderr, "\t-s affiche l'arbre de derivation\n");*/
fprintf(stderr, "\t-a affiche l'arbre abstrait\n");
fprintf(stderr, "\t-t affiche la table des symboles\n");
fprintf(stderr, "\t-3 affiche le code trois adresses\n");
fprintf(stderr, "\t-n affiche le code nasm (actif par defaut)\n");
fprintf(stderr, "\t-h affiche ce message\n");
exit(1);
}
/**********************************************************************/
int main(int argc, char **argv) {
int i;
int affiche_lex = 0;
int affiche_syntaxe_abstraite = 0;
int affiche_code3a = 0;
int affiche_mips = 0;
int affiche_nasm = 0;
int affiche_tabsymb = 0;
if(argc == 1){
affiche_message_aide(argv[0]);
}
for(i=1; i<argc; i++){
if(!strcmp(argv[i], "-l")) {
affiche_lex = 1;
}
/*else if(!strcmp(argv[i], "-s")) {
affiche_syntaxe = 1;
}*/
else if(!strcmp(argv[i], "-a")) {
affiche_syntaxe_abstraite = 1;
}
else if(!strcmp(argv[i], "-3")) {
affiche_code3a = 1;
}
else if(!strcmp(argv[i], "-n")) {
affiche_nasm = 1;
}
else if(!strcmp(argv[i], "-t")) {
affiche_tabsymb = 1;
}
else if(!strcmp(argv[i], "-h")){
affiche_message_aide(argv[0]);
}
else {
yyin = fopen(argv[i], "r");
if(yyin == NULL){
fprintf(stderr, "impossible d'ouvrir le fichier %s\n", argv[i]);
exit(1);
}
}
}
if( !( affiche_lex || affiche_syntaxe_abstraite || affiche_code3a ||
affiche_tabsymb || affiche_mips ) ) {
affiche_nasm = 1; /* Par défaut, affiche code cible NASM */
}
if(affiche_lex == 1) {
test_yylex( yyin );
}
//yyparse();
if( affiche_syntaxe_abstraite ) {
//Affiche arbre abstrait
}
if(affiche_code3a){
//Affiche code 3a
}
if(affiche_tabsymb){
//Affiche table de symboles
}
if(affiche_nasm){
//Affiche code cible NASM
}
return 0;
}