On a rien foutu
This commit is contained in:
parent
eeba39940b
commit
e34720da2c
5 changed files with 52 additions and 44 deletions
|
@ -7,9 +7,14 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#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); } ;
|
||||
|
||||
|
|
0
Symboles/tab_instruc.c
Normal file
0
Symboles/tab_instruc.c
Normal file
5
Symboles/tab_instruc.h
Normal file
5
Symboles/tab_instruc.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
enum instructions_t {ADD,SUB}
|
||||
|
||||
|
||||
void add_operation(struct instructions_t inst, int * argv, int argv);
|
|
@ -31,6 +31,8 @@ Opérations possible :
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
|
|
|
@ -28,17 +28,21 @@ Opérations possible :
|
|||
#include <stdint.h>
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue