From e34720da2c703e496a74bff165ef2438c7d8f936 Mon Sep 17 00:00:00 2001 From: Faure Paul Date: Thu, 1 Apr 2021 11:51:58 +0200 Subject: [PATCH] On a rien foutu --- Lex_Yacc/as.y | 54 ++++++++++++--------------------------- Symboles/tab_instruc.c | 0 Symboles/tab_instruc.h | 5 ++++ Symboles/table_symboles.c | 31 +++++++++++++++++----- Symboles/table_symboles.h | 6 ++++- 5 files changed, 52 insertions(+), 44 deletions(-) create mode 100644 Symboles/tab_instruc.c create mode 100644 Symboles/tab_instruc.h diff --git a/Lex_Yacc/as.y b/Lex_Yacc/as.y index 8d41803..e515647 100644 --- a/Lex_Yacc/as.y +++ b/Lex_Yacc/as.y @@ -7,9 +7,14 @@ #include #include #include +#define TAILLE 1024 int addr = 0; +enum type_t type_courant; +int * tab_instruc = malloc(sizeof(int)*TAILLE); +int index_instruc = 0; + %} %token tMAIN @@ -46,7 +51,7 @@ Main : tINT tMAIN tOBRACE Params tCBRACE Body { print(pile); printf("addr = %d\ Params : { printf("Sans Params\n"); } ; Params : Param SuiteParams ; -Param : tINT tID { printf("Prametre : %s\n", $2); }; +Param : DeclType tID { printf("Prametre : %s\n", $2); }; SuiteParams : tCOMA Param SuiteParams ; SuiteParams : ; @@ -100,43 +105,18 @@ E : tNOT E { printf("!\n"); }; //Créer un champ isConst dans la table des symboles -Decl : tCONST tINT tID SuiteDeclConst { int init = ($3 != -1); - if (init){ - int val = *$2; - printf("AFC %ld %d",addr,val); - } -struct symbole_t symbole = {$2, addr, INT, init}; -push(symbole, pile); -addr++;} ; -SuiteDeclConst : tCOMA tID SuiteDecl { $$=$3; int init = ($3 != -1); - if (init){ - int val = *$2; - printf("AFC %ld %d",addr,val); - } -struct symbole_t symbole = {$2, addr, INT, init}; push(symbole, pile); addr++;}; -SuiteDeclConst : tEQ E tPV { $$=$2; }; -SuiteDeclConst : tPV { $$=$2; }; +Decl : tCONST DeclType SuiteDeclConst { } ; +SuiteDeclConst : tCOMA tID SuiteDeclConst ; +SuiteDeclConst : tEQ E tPV { }; +SuiteDeclConst : tPV { }; -Decl : tINT tID SuiteDecl { int init = ($3 != -1); - if (init){ - int val = *$2; - printf("AFC %ld %d",addr,val); - } - struct symbole_t symbole = {$2, addr, INT, init}; -push(symbole, pile); -addr++;} ; -SuiteDecl : tCOMA tID SuiteDecl - { $$=$3; - int init = ($3 != -1); - if (init){ - int val = *$2; - printf("AFC %ld %d",addr,val); - } - struct symbole_t symbole = {$2, addr, INT, init}; - push(symbole, pile); - addr++;}; -SuiteDecl : tEQ E tPV { $$=$2;}; -SuiteDecl : tPV { $$=$2; }; + +DeclType : tINT {type_courant = INT;} ; +Decl : DeclType Decl SuiteDecl { } ; +Decl : tID {push($1, 0, type_courant);}; +Decl : tID tEQ E {push($1,1, type_courant);} ; +SuiteDecl : tCOMA Decl SuiteDecl { }; +SuiteDecl : tPV { }; Invocation : tPRINTF tOBRACE tID tCBRACE { printf("Appel de printf sur %s\n", $3); } ; diff --git a/Symboles/tab_instruc.c b/Symboles/tab_instruc.c new file mode 100644 index 0000000..e69de29 diff --git a/Symboles/tab_instruc.h b/Symboles/tab_instruc.h new file mode 100644 index 0000000..3495914 --- /dev/null +++ b/Symboles/tab_instruc.h @@ -0,0 +1,5 @@ + +enum instructions_t {ADD,SUB} + + +void add_operation(struct instructions_t inst, int * argv, int argv); diff --git a/Symboles/table_symboles.c b/Symboles/table_symboles.c index 695381b..f327e90 100644 --- a/Symboles/table_symboles.c +++ b/Symboles/table_symboles.c @@ -31,6 +31,8 @@ Opérations possible : #include #include +int last_addr = 0; + struct element_t { struct symbole_t symbole; struct element_t * suivant; @@ -40,6 +42,8 @@ struct pile_t { int taille; struct element_t * first; }; +* +struct pile_t * pile; char * type_to_string(enum type_t type) { if (type == INT) { @@ -51,9 +55,9 @@ char * type_to_string(enum type_t type) { void print_symbole(struct symbole_t symbole) { if (symbole.initialized) { - printf("\t\t{nom:%s, adresse:%p, type:%s, initialized:OUI}\n", symbole.nom, (void *)(symbole.adresse), type_to_string(symbole.type)); + printf("\t\t{nom:%s, adresse:%p, type:%s, initialized:OUI, profondeur : %d}\n", symbole.nom, (void *)(symbole.adresse), type_to_string(symbole.type), symbole.profondeur); } else { - printf("\t\t{nom:%s, adresse:%p, type:%s, initialized:NON}\n", symbole.nom, (void *)(symbole.adresse), type_to_string(symbole.type)); + printf("\t\t{nom:%s, adresse:%p, type:%s, initialized:NON, profondeur : %d}\n", symbole.nom, (void *)(symbole.adresse), type_to_string(symbole.type),symbole.profondeur); } } @@ -63,7 +67,7 @@ void init (void) { pile->taille = 0; } -void push(struct symbole_t symbole, struct pile_t * pile) { +void push(char * nom, int isInit, enum type_t type) { struct element_t * aux = malloc(sizeof(struct element_t)); aux->symbole = symbole; aux->suivant = pile->first; @@ -71,7 +75,7 @@ void push(struct symbole_t symbole, struct pile_t * pile) { pile->taille++; } -struct symbole_t pop(struct pile_t * pile) { +struct symbole_t pop() { struct symbole_t retour = {"", 0, UNKNOWN, 0}; struct element_t * aux; if (pile->taille > 0) { @@ -84,7 +88,7 @@ struct symbole_t pop(struct pile_t * pile) { return retour; } -char status(char * nom, struct pile_t * pile) { +char status(char * nom) { char retour = 0; struct element_t * aux = pile->first; int i; @@ -103,7 +107,22 @@ char status(char * nom, struct pile_t * pile) { return retour; } -void print(struct pile_t * pile) { +struct symbole_t * getVariable(char * nom){ + struct symbole_t * retour = NULL; + struct element_t * aux = pile->first; + int i; + for (i=0; i < pile->taille; i++) { + if (!strcmp(nom, aux->symbole.nom)) { + retour = element_t; + break; + } else { + aux = aux->suivant; + } + } + return retour; +} + +void print() { printf("Affichage de la Table des Symboles\n\tSize : %d\n\tContenu : \n", pile->taille); struct element_t * aux = pile->first; int i; diff --git a/Symboles/table_symboles.h b/Symboles/table_symboles.h index d8fc90e..f101cd5 100644 --- a/Symboles/table_symboles.h +++ b/Symboles/table_symboles.h @@ -28,17 +28,21 @@ Opérations possible : #include enum type_t {UNKNOWN, INT}; +int taille_types[] = {-1, 4}; + +char * tab_instructions[2] = {"ADD %d %d", "SUB %d %d"} struct symbole_t { char nom[30]; uintptr_t adresse; enum type_t type; char initialized; + int profondeur; }; void print_symbole(struct symbole_t symbole); -struct pile_t * pile; +int profondeur = 0; void init(void); void push(struct symbole_t symbole, struct pile_t * pile);