Compare commits
No commits in common. "de931ee17f5bdc4966218aa1a82e31533e7ca3a0" and "a669e59abcc219c0ceca293c48370b0e4298d881" have entirely different histories.
de931ee17f
...
a669e59abc
2 changed files with 4 additions and 87 deletions
84
table.c
84
table.c
|
|
@ -18,90 +18,6 @@ void checkArraySanity(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Suppress variable dont la profondeur est plus grande
|
|
||||||
add element */
|
|
||||||
|
|
||||||
/* a avoir
|
|
||||||
tableau, length, esp, indexTab */
|
|
||||||
|
|
||||||
/* Fonction d'affichage des erreurs */
|
|
||||||
void error(char * mess){
|
|
||||||
printf("ERROR : %s\n", &mess);
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Récupérer l'addresse à partir du nom */
|
|
||||||
int getOffset(int esp, char* name, Symbol *tab, int endingIndex){
|
|
||||||
return (esp + getStruct(&tab, endingIndex, &name).offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Récupérer la structure d'un élement à partir du nom */
|
|
||||||
Symbol getStruct(Symbol* tab, int endingIndex, char* name){
|
|
||||||
for(int i=0; i < endingIndex; i++){
|
|
||||||
if (tab[i].name == name){
|
|
||||||
return tab[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
error("No structure found");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Récupérer l'index d'une valeur dans le tableau*/
|
|
||||||
int getIndex(Symbol* tab, int endingIndex, char* name){
|
|
||||||
for(int i=0; i < endingIndex; i++){
|
|
||||||
if (strcmp(tab[i].name, &name) == 0){
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
error("No index found");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Toggle le init */
|
|
||||||
void toggleInit(char *name, Symbol *tab, int endingIndex){
|
|
||||||
tab[getIndex(&tab, endingIndex, &name)].init = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Ajoute un élément */
|
|
||||||
void addElement(Symbol *tab, int endingIndex, Symbol element){
|
|
||||||
if (endingIndex == 0){
|
|
||||||
tab[0] = element;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tab[endingIndex].name = element.name;
|
|
||||||
tab[endingIndex].init = element.init;
|
|
||||||
tab[endingIndex].varType = element.varType;
|
|
||||||
tab[endingIndex].offset = initOffset(&tab, endingIndex -1);
|
|
||||||
tab[endingIndex].deep = element.deep;
|
|
||||||
}
|
|
||||||
endingIndex ++; // faudra la mettre en variable globale
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Calcule l'offset à partir de l'offset de l'élément précédent */
|
|
||||||
int initOffset(Symbol *tab, int index){
|
|
||||||
int offset = 0;
|
|
||||||
switch (tab[index].varType){
|
|
||||||
case INT:
|
|
||||||
return (tab[index].offset + 1);
|
|
||||||
break;
|
|
||||||
case FLOAT:
|
|
||||||
return (tab[index].offset + 1);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
error("Impossible to compute the nexw offset");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Supprimer un élément de la table des symboles */
|
|
||||||
suppressElement(Symbol *tab, int endingIndex, Symbol element){
|
|
||||||
for(int i = getIndex(&tab, endingIndex, element.name); i < (endingIndex - 1); i ++){
|
|
||||||
tab[i] = tab[i+1];
|
|
||||||
}
|
|
||||||
endingIndex --; // variable globale
|
|
||||||
}
|
|
||||||
|
|
||||||
void reallocateArray(int size){
|
void reallocateArray(int size){
|
||||||
Symbol* newSymbolTable = malloc(sizeof (symbol) * size); // we double the size of the array
|
Symbol* newSymbolTable = malloc(sizeof (symbol) * size); // we double the size of the array
|
||||||
Symbol* oldSymbolTable = symbolTable; // we double the size of the array
|
Symbol* oldSymbolTable = symbolTable; // we double the size of the array
|
||||||
|
|
|
||||||
7
table.h
7
table.h
|
|
@ -4,7 +4,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
enum enumVarType {INT, FLOAT}; // a adapter
|
|
||||||
/*defined constants*/
|
/*defined constants*/
|
||||||
#define START_TABLE_SIZE 128;
|
#define START_TABLE_SIZE 128;
|
||||||
|
|
||||||
|
|
@ -13,13 +12,15 @@ static int currentIndex;
|
||||||
static int maxIndex;
|
static int maxIndex;
|
||||||
static symbol* symbolTable;
|
static symbol* symbolTable;
|
||||||
|
|
||||||
typedef struct {
|
enum enumVarType {INT, FLOAT, CHAR, STRING};
|
||||||
|
|
||||||
|
struct symbol {
|
||||||
char* name;
|
char* name;
|
||||||
bool init;
|
bool init;
|
||||||
enumVarType varType;
|
enumVarType varType;
|
||||||
int offset;
|
int offset;
|
||||||
int deep;
|
int deep;
|
||||||
} Symbol;
|
};
|
||||||
|
|
||||||
void reallocateArray(int size);
|
void reallocateArray(int size);
|
||||||
void checkArraySanity();
|
void checkArraySanity();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue