diff --git a/Labgen/a.out b/Labgen/a.out index 6dc060296f6a65e13977c12e48cc264760244e59..9afc3faa27b9fecef4426a5efd8435c6cd41ce9b 100755 Binary files a/Labgen/a.out and b/Labgen/a.out differ diff --git a/Labgen/labgen b/Labgen/labgen index 8614f7558318db3bf52b230f391fc8fb5813f98e..cd0167934fe91538b41a5337518646aea13c32bf 100755 Binary files a/Labgen/labgen and b/Labgen/labgen differ diff --git a/Labgen/labgen.c b/Labgen/labgen.c index 532b52c4931268fb19ebee5bbac0b32bf10d119f..1f520baffb831e9acd11dfd8f57041947bb0f9eb 100644 --- a/Labgen/labgen.c +++ b/Labgen/labgen.c @@ -1,6 +1,6 @@ #include "labgen.h" point size; /*Attention c'est la taille réelle de la matrice*/ -char *** matrice = NULL ; +/* char *** matrice = NULL ; */ int in,out; variables listevars; @@ -18,10 +18,10 @@ point new_point(int x, int y) /* Crée une matrice de taille (s1, s2) * /!\ Attention : toujours créer la matrice avant d'utiliser * les autres fonctions */ -void create_matrice(int s1, int s2) +char*** create_matrice(int s1, int s2) { int i,j; - matrice = malloc((s1+1)*sizeof(char **)); + char*** matrice = malloc((s1+1)*sizeof(char **)); for (i= 0; i<s1+1; i++){ matrice[i] = malloc((s2+1) * sizeof(char *)); @@ -34,11 +34,12 @@ void create_matrice(int s1, int s2) /*Attention c'est la taille réelle de la matrice*/ in = 0; out = 0; + return matrice; } /* Renvoie la valeur de la matrice de coordonnées p */ -char* lecture(point p) +char* lecture(point p, char*** matrice) { if (matrice == NULL){ printf("Matrice non initialisée.\n"); @@ -54,7 +55,7 @@ char* lecture(point p) /* void stock_val */ /* Change la valeur de la matrice de coordonnées p par la valeur msg */ -void change_val_matrice(point p, char * msg) +void change_val_matrice(point p, char * msg, char*** matrice) { if (matrice == NULL){ printf("Matrice non initialisée.\n"); @@ -84,7 +85,7 @@ void change_val_matrice(point p, char * msg) printf("\n"); }*/ -void affichmat() { +void affichmat(char*** matrice) { int i,j; /*ligne();*/ @@ -151,18 +152,18 @@ void create_modif_var(char* nom, int val) { } -int main () { - create_matrice(5,4); +/*int main () { + char*** matrice = create_matrice(5,4); point p1 = new_point(5,4); printf("Point p1 (%d,%d)\n",p1.x,p1.y); printf("\nAppel de la fonction change_val_matrice(p1,ABC)\n"); - change_val_matrice(p1,"ABC"); - printf("Point p1 :%s\n", lecture(p1)); + change_val_matrice(p1,"ABC",matrice); + printf("Point p1 :%s\n", lecture(p1,matrice)); printf("\nAppel de la fonction change_val_matrice(p1,DEF)\n"); - change_val_matrice(p1, "DEF"); - printf("Point p1 :%s\n", lecture(p1)); + change_val_matrice(p1, "DEF", matrice); + printf("Point p1 :%s\n", lecture(p1,matrice)); printf("\nTaille de la matrice : (%d,%d)\n",size.x-1,size.y-1); printf("Matrice correspondante :\n"); @@ -180,4 +181,4 @@ int main () { printf("Deuxième valeur : %d\n",listevars.val[1]); return 0; -} +}*/ diff --git a/Labgen/labgen.h b/Labgen/labgen.h index 6e34048d04f3a387c9c38be6c0271e050186acbb..5aeb11e8c231196a756982fcf97aef8c28398ad1 100644 --- a/Labgen/labgen.h +++ b/Labgen/labgen.h @@ -16,10 +16,10 @@ int last; point new_point(int ,int); -void create_matrice(int,int); -char* lecture(point); -void change_val_matrice(point,char*); -void affichmat(); +char*** create_matrice(int,int); +char* lecture(point,char***); +void change_val_matrice(point,char*, char***); +void affichmat(char***); void init_listevars(); int find_var(char*); diff --git a/Labgen/labgen.o b/Labgen/labgen.o index 43cc4455572ae0b1d8aab00a132a8d51ff3560b4..faa8e7a8f832a1c5243512a18f60e5b1820c09fc 100644 Binary files a/Labgen/labgen.o and b/Labgen/labgen.o differ diff --git a/Labgen/labgen.y b/Labgen/labgen.y index 0dc3173d15222ba3d73051f330e198d1d8d0a022..33ab99d276f6ac7e1ffd5dcd34061ee1bc871206 100644 --- a/Labgen/labgen.y +++ b/Labgen/labgen.y @@ -18,7 +18,7 @@ extern int yylineno; char file[255]; %} -%union yylval +%union yylval { int cnum ; char* ident; @@ -28,26 +28,26 @@ char* dir; -%token<ident> IDENT +%token<ident> IDENT %token<cnum> CNUM -%token SIZE +%token SIZE %token<cnum> IN %token<cnum> OUT WALL PTD SHOW UNWALL END R F PTA FOR TOGGLE WH MD %token<op> OP %token<dir> DIR - + %left MULT DIV MOD -%left PLUS MOINS +%left PLUS MOINS %nonassoc NEG %% file: -listinstr +listinstr ; listinstr: -instruction +instruction |listinstr instruction ; instruction: @@ -83,13 +83,13 @@ affichmat(matrice); |WALL PTD pt wallptd END |WALL FOR wallfor END |UNWALL PTA list END -|UNWALL R F pt pt END -|UNWALL PTD unwallptd END -|UNWALL FOR unwallfor END +|UNWALL R F pt pt END +|UNWALL PTD unwallptd END +|UNWALL FOR unwallfor END |TOGGLE PTA list END -|TOGGLE R F pt pt END -|TOGGLE PTD toggleptd END -|TOGGLE FOR togglefor END +|TOGGLE R F pt pt END +|TOGGLE PTD toggleptd END +|TOGGLE FOR togglefor END |WH pt MOINS MOINS '>'pt list1 END |WH pt MOINS '>'pt list1 END |MD pt destlist END; @@ -104,16 +104,16 @@ xcst |expr DIV expr; */ -xcst: -IDENT -|CNUM -|PLUS CNUM +xcst: +IDENT +|CNUM +|PLUS CNUM |MOINS CNUM -| xcst PLUS xcst -|xcst MOINS xcst -|xcst MULT xcst -| xcst DIV xcst -| xcst MOD xcst +| xcst PLUS xcst +|xcst MOINS xcst +|xcst MULT xcst +| xcst DIV xcst +| xcst MOD xcst | '(' xcst ')' ; @@ -121,7 +121,7 @@ IDENT wallfor: -IDENT wallfor +IDENT wallfor |IN listRange pt; unwallfor: @@ -152,7 +152,7 @@ pt wallptd unwallptd: pt |pt ':' r | -pt unwallptd +pt unwallptd |pt ':' r unwallptd; @@ -160,7 +160,7 @@ r: "*" | xcst; -pt: '('xcst ',' xcst')' ; +pt: '('xcst ',' xcst')' ; range: @@ -180,7 +180,7 @@ list1: ; -destlist: +destlist: |DIR pt destlist; listRange: @@ -193,26 +193,41 @@ range %% void yyerror(const char* mess){ -fprintf(stderr," %s:%i:syntaxe error (near %s) \n", file,yylineno,yytext); -exit(1);} + fprintf(stderr," %s:%i:syntaxe error (near %s) \n", file,yylineno,yytext); + exit(1); +} int main(int argc, char *argv[]){ - - - if (argc==2) { + if (argc == 1){ + printf("A faire : lecture sur le flux standard d'entrée + exécutable labres\n"); + } + + else if (argc==2) { FILE *fp = fopen(argv[1],"r"); if (fp!=NULL) { - strcpy(file,argv[1]); + strcpy(file,argv[1]); printf("Reading input from file succeded: %s\n",argv[1]); - + yyin = fp; listevars.last=0; yyparse(); - } else { - printf("File doesn't exist\n"); - return 1; + } + else { + fprintf(stderr,"File doesn't exist.\n"); + exit(1); } } - + + + else if (argc == 3){ + printf("A faire : lecture dans le fichier argc[1] + exécutable argc[2]\n"); + } + + else{ + fprintf(stderr,"usage: %s OR %s if OR %s if exe\n", + argv[0],argv[0],argv[0]); + exit(1); + } + return 0; } diff --git a/Labgen/y.tab.c b/Labgen/y.tab.c index 5aa93226d0978bc3b51fcb847402c1328db8e7b4..68d77cdc7bf78215d295bade14bb0ddeaa76b0bb 100644 --- a/Labgen/y.tab.c +++ b/Labgen/y.tab.c @@ -1650,26 +1650,41 @@ yyreturn: #line 194 "labgen.y" /* yacc.c:1906 */ void yyerror(const char* mess){ -fprintf(stderr," %s:%i:syntaxe error (near %s) \n", file,yylineno,yytext); -exit(1);} + fprintf(stderr," %s:%i:syntaxe error (near %s) \n", file,yylineno,yytext); + exit(1); +} int main(int argc, char *argv[]){ - - - if (argc==2) { + if (argc == 1){ + printf("A faire : lecture sur le flux standard d'entrée + exécutable labres\n"); + } + + else if (argc==2) { FILE *fp = fopen(argv[1],"r"); if (fp!=NULL) { - strcpy(file,argv[1]); + strcpy(file,argv[1]); printf("Reading input from file succeded: %s\n",argv[1]); - + yyin = fp; listevars.last=0; yyparse(); - } else { - printf("File doesn't exist\n"); - return 1; + } + else { + fprintf(stderr,"File doesn't exist.\n"); + exit(1); } } - + + + else if (argc == 3){ + printf("A faire : lecture dans le fichier argc[1] + exécutable argc[2]\n"); + } + + else{ + fprintf(stderr,"usage: %s OR %s if OR %s if exe\n", + argv[0],argv[0],argv[0]); + exit(1); + } + return 0; }