-
Notifications
You must be signed in to change notification settings - Fork 2
/
synt.y
718 lines (653 loc) · 45.4 KB
/
synt.y
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
%{
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int nb_ligne=1, col=1,tss=0;
extern FILE *yyin;
char* saveType;
char *returnedType;
char typeval[25];
char *filename;
float idfValue;
char idfNewValue[20];
int qc=0;
int resultI;
float resultF;
int jj=0;
int kk=0;
int c=0;
int nb11=0,nb22=0,nb33=0,nb44=0;
int i=0;
float idfNewValue1;
int idfNewValue2;
int zz=0 ;
int xx1=0;
int bb = 0 ;
int vv=0;
int vv1=0;
char xx[20] ;
char chaine1[20];
int intIdfNewValue;
int err = 0;
int h = 0;
int Fin_if=0,Fin_while=0, Deb_while=0,OP = 0,and_b=0,and_f=0,or_b=0,or_f=0,debu=0,deb_for=0;
char L[25],Q[25];
char temp1[25] = "TEMP";
char opera[5];
char saveOP[25];
char saveOpLo[25];
char tmp[25];
char med[25];
char med2[25];
char op1[25];
char op2[25];
char medOp[25];
char tempMul[25];
char resultL[25];
char s[25];
char medType[25];
int fin_if[10];
int i_if=0;
int deb_else[10];
int i_else=0;
int lol = 0;
int Cond = 0;
int medL=0;
int indentation = 0;
int mustBe = 0;
int mull=0;
int x=0;
int AND_or_OR = 0;
int only_one = 0;
int first =0;
int teemp = 0;
int p = 0;
int o = 0;
int a = 0;
int value2,value1;
char saveCst[25];
char sauvIdf1[25];
char sauvIdf[2][10] = {};
int nbLigne=1;
int nbCol=1; //declaraction du cpt de nombre de colonne
int callIndex=-1;
int nbParams=0;
%}
%union {
int entier;
char* str;
float reel;
}
%token <str>mc_program <str>mc_routine <str>mc_entier <str>string <str>booleen
<str>mc_real <str>mc_logical <str>mc_character <str>mc_dimension
<str>mc_read <str>mc_write <str>mc_if <str>mc_then <str>mc_else <str>mc_endif
<str>mc_dowhile <str>mc_enddo <str>mc_or <str>mc_and <str>mc_gt <str>mc_ge <str>mc_eq
<str>mc_ne <str>mc_le <str>mc_lt <str>mc_call <str>mc_endr <str>mc_end <str>IDF <entier>integr <reel>floatt
<str>add <str>sub <str>mul <str>divv <str>pvg <str>vrg <str>aff <str>po <str>pf <str>mc_equivalence <str>point
%type <str> TYPE OPERATION CHAINE LOGICAL
%start S
%left add sub
%left mul divv
%left mc_or
%left mc_and
%left mc_gt mc_ge mc_lt mc_le mc_eq mc_ne
%%
S: FUNCTION | PROGRAM {printf("prog syntaxiquement correct"); YYACCEPT;}
;
FUNCTION : HEADER BODY mc_endr {rechercher ($3,"Mot cle ","","0", 1,tss);tss++; }S
;
HEADER : TYPE mc_routine IDF po PARAMETRE pf {
callIndex++;
initializeCall(callIndex,$3,3);
rechercher ($2,"Mot cle ","","0", 1,tss);
rechercher ($3,"IDF","Identifier","0", 0,tss);
modifyType($3,saveType,tss);
rechercher ($4,"Separateur","0","0", 2,tss);
rechercher ($6,"Separateur","0","0", 2,tss);
}
;
TYPE: mc_entier {saveType=$1;rechercher ($1,"Mot cle ","","0", 1,tss);}
| mc_real {saveType=$1;rechercher ($1,"Mot cle ","","0", 1,tss);}
| mc_logical {saveType=$1;rechercher ($1,"Mot cle ","","0", 1,tss);}
| mc_character {saveType=$1;rechercher ($1,"Mot cle ","","0", 1,tss);}
;
PARAMETRE : IDF {rechercher ($1,"IDF","Identifier","0", 0,tss); nbParams++;}
| IDF vrg PARAMETRE {rechercher ($1,"IDF","Identifier","0", 0,tss); rechercher ($2,"Separateur","0","0", 2,tss); }
| IDF po TAILLE pf {rechercher ($1,"IDF","Identifier","0", 0,tss);rechercher ($2,"Separateur","0","0", 2,tss);rechercher ($4,"Separateur","0","0", 2,tss);}
| IDF po TAILLE pf PARAMETRE {rechercher ($1,"IDF","Identifier","0", 0,tss);rechercher ($2,"Separateur","0","0", 2,tss);rechercher ($4,"Separateur","0","0", 2,tss);}
;
BODY : DEC INST
;
DEC: TYPE IDF{rechercher ($2,"IDF","Identifier","0", 0,tss); modifyType($2,saveType,tss); } ListIDF pvg {rechercher ($5,"Separateur","0","0", 2,tss);sprintf(chaine1, "%d",(int)idfNewValue1);if(zz == 1)Misajour($2,(int)tss,chaine1) ;if(kk == 1)modmat($2,nb11,nb22,i);kk=0;if(bb == 1)i++;} DEC
|
;
ListIDF: vrg IDF ListIDF { rechercher ($1,"Separateur","0","0", 2,tss); rechercher ($2,"IDF","Identifier","0", 0,tss); modifyType($2,saveType,tss); }
| mc_dimension po TAILLE pf {rechercher ($1,"Mot cle ","","0", 1,tss);rechercher ($2,"Separateur","0","0", 2,tss); rechercher ($4,"Separateur","0","0", 2,tss);zz=1;}
| mc_dimension po TAILLE pf vrg ListIDF {rechercher ($1,"Mot cle ","","0", 1,tss);rechercher ($2,"Separateur","0","0", 2,tss); rechercher ($4,"Separateur","0","0", 2,tss); rechercher ($5,"Separateur","0","0", 2,tss);}
| mul integr {rechercher ($1,"Separateur","0","0", 2,tss);}
|
;
TAILLE : integr {strcpy(typeval,"INTEGER"); if($1<0 ){printf("Erreur semantique : Indice Negatif %d,%d\n",nb_ligne,nbCol);exit(EXIT_FAILURE);}intIdfNewValue = $1 ;idfNewValue1 = (int)intIdfNewValue;;intIdfNewValue = $1 ;idfNewValue2 = (int)intIdfNewValue;vv1=1;bb=0;}
| integr vrg integr{rechercher ($2,"Separateur","0","0", 2,tss);if($1<0 || $3<0) {printf("Erreur semantique : Indice Negatif %d,%d\n",nb_ligne,nbCol); exit(EXIT_FAILURE); }intIdfNewValue = $1 ;nb11 = (int)intIdfNewValue; intIdfNewValue = $3 ;nb22 = (int)intIdfNewValue;vv1=0;if(c==1)bb=1;c=1;kk=1}
;
PROGRAM : mc_program IDF BODY mc_end {rechercher ($1,"Mot cle ","","0", 1,tss); rechercher ($2,"IDF","Identifier","0", 0,tss); rechercher ($4,"Mot cle ","","0", 1,tss); }
;
INST : AFFECTATION pvg INST {rechercher ($2,"Separateur","0","0", 2,tss);}
| ES pvg INST{rechercher ($2,"Separateur","0","0", 2,tss);}
| CONDITON INST
| LOOP pvg INST {rechercher ($2,"Separateur","0","0", 2,tss);}
| CALLING pvg INST {rechercher ($2,"Separateur","0","0", 2,tss);}
| EQUIV pvg INST {rechercher ($2,"Separateur","0","0", 2,tss);}
|
;
AFFECTATION : IDF aff EXPRESSION INST{
rechercher1 ($1,"IDF","Identifier","0", 0,tss);
if (incompatibiliteDeType($1,typeval,tss) == 1) {
printf("Erreur semantique: Incompatibilite de type a la ligne %d colonne %d\n", nb_ligne, col);
exit(EXIT_FAILURE);
}
rechercher ($2,"Separateur","0","0", 2,tss);
Misajour($1,(int)tss,idfNewValue);
quadr("=",saveCst,"",$1);
}
| IDF aff CHAINE INST{
rechercher1 ($1,"IDF","Identifier","0", 0,tss);
printf("%s \t %s \n",$1,typeval);
if (incompatibiliteDeType($1,typeval,tss) == 1) {
printf("Erreur semantique: Incompatibilite de type a la ligne %d colonne %d\n", nb_ligne, col);
exit(EXIT_FAILURE);
}
rechercher ($2,"Separateur","0","0", 2,tss);
Misajour($1,(int)tss,idfNewValue);
strcpy(saveCst,idfNewValue);
quadr("=",saveCst,"",$1);
}
| IDF aff LOGICAL INST{
rechercher1 ($1,"IDF","Identifier","0", 0,tss);
printf("%s \t %s \n",$1,typeval);
if (incompatibiliteDeType($1,typeval,tss) == 1) {
printf("Erreur semantique: Incompatibilite de type a la ligne %d colonne %d\n", nb_ligne, col);
exit(EXIT_FAILURE);
}
rechercher ($2,"Separateur","0","0", 2,tss);
Misajour($1,(int)tss,idfNewValue);
strcpy(saveCst,idfNewValue);
quadr("=",saveCst,"",$1);
}
;
EXPRESSION : VALEUR {
if(only_one == 0 ){
if(strcmp(op1,"")==0 && !h){
strcpy(saveCst,op1);}else{if(h){h=0;}}
}else{
if(!mull){
if(x==1){
if(p){
value2=atoi((char*)getValueOfIDF(op1,tss));
if (strcmp(saveOP, "+") == 0) {
resultI = value2 + value1;
} else if (strcmp(saveOP, "-") == 0) {
resultI = value2 - value1;
} else if (strcmp(saveOP, "*") == 0) {
resultI = value2 * value1;
} else if (strcmp(saveOP, "/") == 0) {
if (value1 != 0) {
resultI = value2 / value1;
} else {
printf("Error: Division by zero.\n");
exit(EXIT_FAILURE);
err=1; // Exit with an error code
}}
quadr(medOp,op1,"TEMP",temp1);
strcpy(saveCst,temp1);
sprintf(idfNewValue,"%d",resultI);
}else{
value2=resultI;
if (strcmp(saveOP, "+") == 0) {
resultI = value2 + value1;
} else if (strcmp(saveOP, "-") == 0) {
resultI = value2 - value1;
} else if (strcmp(saveOP, "*") == 0) {
resultI = value2 * value1;
} else if (strcmp(saveOP, "/") == 0) {
if (value1 != 0) {
resultI = value2 / value1;
} else {
printf("Error: Division by zero.\n");
exit(EXIT_FAILURE);
err=1; // Exit with an error code
}}
quadr(saveOP,temp1,op1,temp1);strcpy(saveCst,temp1);sprintf(idfNewValue,"%d",resultI);}
}else{
value2=atoi((char*)getValueOfIDF(med,tss));
if (strcmp(saveOP, "+") == 0) {
resultI = value2 + value1;
} else if (strcmp(saveOP, "-") == 0) {
resultI = value2 - value1;
} else if (strcmp(saveOP, "*") == 0) {
resultI = value2 * value1;
} else if (strcmp(saveOP, "/") == 0) {
if (value1 != 0) {
resultI = value2 / value1;
} else {
printf("Error: Division by zero.\n");
exit(EXIT_FAILURE);
err=1; // Exit with an error code
}}
quadr(saveOP,op1,med,temp1);
strcpy(saveCst,temp1);sprintf(idfNewValue,"%d",resultI);
}
}else{
if (lol){
value2=resultI;
if (strcmp(medOp, "+") == 0) {
resultI = value2 + value1;
} else if (strcmp(medOp, "-") == 0) {
resultI = value2 - value1;
} else if (strcmp(medOp, "*") == 0) {
resultI = value2 * value1;
} else if (strcmp(medOp, "/") == 0) {
if (value1 != 0) {
resultI = value2 / value1;
} else {
printf("Error: Division by zero.\n");
exit(EXIT_FAILURE);
err=1; // Exit with an error code
}}
quadr(medOp,temp1,tempMul,temp1);lol=0;strcpy(saveCst,temp1);
sprintf(idfNewValue,"%d",resultI);
}
if(strcmp(tempMul,"")!=0){
if(strcmp(med2,"")!=0){if(a){
value2=resultI;
if(strcmp((char*)getCodeOfEntity(med2,tss),"IDF")==0)
value1=atoi((char*)getValueOfIDF(med2));
else value1=atoi(med2);
if (strcmp(medOp, "+") == 0) {
resultI = value2 + value1;
} else if (strcmp(medOp, "-") == 0) {
resultI = value2 - value1;
} else if (strcmp(medOp, "*") == 0) {
resultI = value2 * value1;
} else if (strcmp(medOp, "/") == 0) {
if (value1 != 0) {
resultI = value2 / value1;
} else {
printf("Error: Division by zero.\n");
exit(EXIT_FAILURE);
err=1; // Exit with an error code
}}
quadr(medOp,med2,tempMul,temp1);
strcpy(saveCst,temp1);}}
sprintf(idfNewValue,"%d",resultI);
}
}
}
}
| VALEUR {strcpy(medType,saveType);strcpy(med,op1);} {only_one = 1} OPERATION {if(strcmp(saveOP,"+")==0 ||strcmp(saveOP,"-")==0){
if(!mull){printf("");
if(strcmp(med2,"")!=0){
if(x){
value2=resultI;
if (strcmp(saveOP, "+") == 0) {
resultI = value2 + value1;
} else if (strcmp(saveOP, "-") == 0) {
resultI = value2 - value1;
} else if (strcmp(saveOP, "*") == 0) {
resultI = value2 * value1;
} else if (strcmp(saveOP, "/") == 0) {
if (value1 != 0) {
resultI = value2 / value1;
} else {
printf("Error: Division by zero.\n");
exit(EXIT_FAILURE);
err=1; // Exit with an error code
}}
quadr(medOp,temp1,med,temp1);
}else{
value2=atoi((char*)getValueOfIDF(med2,tss));
if (strcmp(saveOP, "+") == 0) {
resultI = value2 + value1;
} else if (strcmp(saveOP, "-") == 0) {
resultI = value2 - value1;
} else if (strcmp(saveOP, "*") == 0) {
resultI = value2 * value1;
} else if (strcmp(saveOP, "/") == 0) {
if (value1 != 0) {
resultI = value2 / value1;
} else {
printf("Error: Division by zero.\n");
exit(EXIT_FAILURE);
err=1; // Exit with an error code
}}
quadr(medOp,med2,med,temp1);x=1;
}
lol = 1;
}
else{
strcpy(med2,med);
}}
else{
if(strcmp(med2,"")!=0){
value2=atoi((char*)getValueOfIDF(med2,tss));
if (strcmp(saveOP, "+") == 0) {
resultI = value2 + value1;
} else if (strcmp(saveOP, "-") == 0) {
resultI = value2 - value1;
} else if (strcmp(saveOP, "*") == 0) {
resultI = value2 * value1;
} else if (strcmp(saveOP, "/") == 0) {
// Ensure value2 is not zero before performing division
if (value1 != 0) {
resultI = value2 / value1;
} else {
printf("Error: Division by zero.\n");
exit(EXIT_FAILURE);
err=1; // Exit with an error code
}}
quadr(medOp,med2,"TEMP",temp1);
strcpy(med2,"TEMP");
}else{
strcpy(med2,"TEMP");p=1;
}mull=0;x=1;strcpy(tempMul,"");
}strcpy(medOp,saveOP);a=0;
}
if(strcmp(saveOP,"*")==0 || strcmp(saveOP,"/")==0){
mull = 1;a=1;
}
} EXPRESSION {strcpy(saveOP,"");strcpy(medOp,"");strcpy(med2,"");strcpy(med,"");strcpy(tempMul,"");strcpy(op1,"");lol=0;mull=0;x=0;a=0;p=0;only_one = 0}
| po EXPRESSION pf OPERATION EXPRESSION {rechercher ($1,"Separateur","0","0", 2,tss); rechercher ($3,"Separateur","0","0", 2,tss);}{strcpy(saveOP,"");strcpy(medOp,"");strcpy(med2,"");strcpy(med,"");strcpy(tempMul,"");strcpy(op1,"");lol=0;mull=0;x=0;a=0;p=0;only_one = 0}
| po EXPRESSION pf{rechercher ($1,"Separateur","0","0", 2,tss);rechercher ($3,"Separateur","0","0", 2,tss);}
;
VALEUR : IDF TABL {
rechercher1 ($1,"IDF","Identifier","0", 0,tss);
strcpy(typeval,(char*)printTypeOfIDF($1));
strcpy(idfNewValue, (char*)getValueOfIDF($1, tss));
strcpy(saveCst,$1);
strcpy(op1,saveCst);
value1=atoi(idfNewValue);
if(mull==1){printf("");
if(strcmp((char*)getCodeOfEntity(med,tss),"IDF")==0)
{value2=atoi((char*)getValueOfIDF(med,tss));}
else {value2=atoi(med);}
if (strcmp(saveOP, "+") == 0) {
resultI = value2 + value1;
} else if (strcmp(saveOP, "-") == 0) {
resultI = value2 - value1;
} else if (strcmp(saveOP, "*") == 0) {
resultI = value2 * value1;
} else if (strcmp(saveOP, "/") == 0) {
if (value1 != 0) {
resultI = value2 / value1;
} else {
printf("Error: Division by zero.\n");
exit(EXIT_FAILURE);
err=1;
}}
quadr(saveOP,med,op1,"TEMP");
strcpy(tempMul,"TEMP");strcpy(saveCst,op1);
sprintf(idfNewValue,"%d",resultI);
} ;strcpy(xx, (char*)getValueOfIDF($1, tss));xx1=atoi(xx) ;printf("");if( vv1 ==1 && idfNewValue2 > xx1) {printf("Erreur symantique : indice hors intervale\n");exit(EXIT_FAILURE);} vv1=0;jj=nbb2($1);if (bb == 1 && (nb11 > nbb1($1) || nb22 > nbb2($1)))printf("\nerreur dans la matrice la taille non disponible\n");bb=0;
}
| NUMBER
;
TABL : TAB |
;
TAB : po TAILLE pf {rechercher ($1,"Separateur","0","0", 2,tss); rechercher ($3,"Separateur","0","0", 2,tss);}
;
NUMBER: integr {
strcpy(typeval, "INTEGER");
sprintf(idfNewValue, "%d", $1);
sprintf(saveCst,"%d",$1);
strcpy(op1,saveCst);
value1=$1;
if(strcmp(saveOP,"")!=0){
if(strcmp(saveType,medType)!=0){
printf("error at %d %d,types error\n",nbLigne-1,nbCol);err=1;
}
}
if(mull==1){
if(strcmp(tempMul,"")==0){
value2=atoi((char*)getValueOfIDF(med,tss));
if (strcmp(saveOP, "+") == 0) {
resultI = value2 + value1;
} else if (strcmp(saveOP, "-") == 0) {
resultI = value2 - value1;
} else if (strcmp(saveOP, "*") == 0) {
resultI = value2 * value1;
} else if (strcmp(saveOP, "/") == 0) {
// Ensure value2 is not zero before performing division
if (value1 != 0) {
resultI = value2 / value1;
} else {
printf("Error: Division by zero.\n");
exit(EXIT_FAILURE);
err=1;
}}
quadr(saveOP,med,op1,"TEMP");
strcpy(tempMul,"TEMP");strcpy(saveCst,op1);
sprintf(idfNewValue,"%d",resultI);
}else{
value2=resultI;
if (strcmp(saveOP, "+") == 0) {
resultI = value2 + value1;
} else if (strcmp(saveOP, "-") == 0) {
resultI = value2 - value1;
} else if (strcmp(saveOP, "*") == 0) {
resultI = value2 * value1;
} else if (strcmp(saveOP, "/") == 0) {
if (value1 != 0) {
resultI = value2 / value1;
} else {
printf("Error: Division by zero.\n");
exit(EXIT_FAILURE);
err=1;
}}
quadr(saveOP,tempMul,op1,"TEMP"); printf("%s\t %s \t %s\n",tempMul,saveOP,op1);strcpy(saveCst,op1);
}
}
}
| floatt {
strcpy(typeval, "REAL");
sprintf(idfNewValue, "%f", $1);
sprintf(saveCst,"%f",$1);
strcpy(op1,saveCst);
if(strcmp(saveOP,"")!=0){
if(strcmp(saveType,medType)!=0){
}
}
if(mull==1){
if(strcmp(tempMul,"")==0){
quadr(saveOP,med,op1,"TEMP");
strcpy(tempMul,"TEMP");
}else{
quadr(saveOP,tempMul,op1,"TEMP");
}
}
}
;
OPERATION : add {rechercher ($1,"Separateur","0","0", 2,tss); strcpy(saveOP,$1);}| sub{rechercher ($1,"Separateur","0","0", 2,tss); strcpy(saveOP,$1);} | mul{rechercher ($1,"Separateur","0","0", 2,tss); strcpy(saveOP,$1);}| divv {rechercher ($1,"Separateur","0","0", 2,tss); strcpy(saveOP,$1);}
;
CHAINE : string {
strcpy(typeval,"CHARACTER");
sprintf(idfNewValue, "%s", $1);
}
;
LOGICAL : booleen {strcpy(typeval,"LOGICAL");
sprintf(idfNewValue, "%s", $1);
if(strcmp(idfNewValue,"TRUE")==0)
strcpy(saveCst,"1");
else
strcpy(saveCst,"0");
h=1;}
;
ES : mc_read po IDF pf {rechercher ($1,"Mot cle ","","0", 1,tss); rechercher ($2,"Separateur","0","0", 2,tss);rechercher1 ($3,"IDF","Identifier","0", 0,tss); rechercher ($4,"Separateur","0","0", 2,tss);}
| mc_write po STRING pf {rechercher ($1,"Mot cle ","","0", 1,tss); rechercher ($2,"Separateur","0","0", 2,tss); rechercher ($4,"Separateur","0","0", 2,tss);}
;
STRING : CHAINE vrg IDF vrg CHAINE {rechercher ($2,"Separateur","0","0", 2,tss);rechercher1 ($3,"IDF","Identifier","0", 0,tss); rechercher ($4,"Separateur","0","0", 2,tss);}
| CHAINE
;
CONDITON : mc_if po EXPCDTT {deb_else[i_else]=qc;
i_else++;
quadr("BZ","",saveCst,"");
sprintf(tmp,"%d",qc);
ajour_quad(or_b,1,tmp);
ajour_quad(or_b+1,1,tmp);
}
pf mc_then INST mc_else {
fin_if[i_if]=qc;
i_if++;
quadr("BR","","","");
sprintf(tmp,"%d",qc);
ajour_quad(deb_else[i_else-1],1,tmp);
i_else--;
AND_or_OR=0;
}
INST mc_endif {
rechercher ($1,"Mot cle ","","0", 1,tss);
rechercher ($2,"Separateur","0","0", 2,tss);
rechercher ($5,"Separateur","0","0", 2,tss);
rechercher ($6,"Mot cle ","","0", 1,tss);
rechercher ($8,"Mot cle ","","0", 1,tss);
rechercher ($11,"Mot cle ","","0", 1,tss);
sprintf(tmp,"%d",qc);
ajour_quad(fin_if[i_if-1],1,tmp);
i_if--;
AND_or_OR=0;
}
;
EXPCDTT : EXPRESSION {
if(AND_or_OR!=0){
if(AND_or_OR==1){
and_b=qc;
quadr("BZ","",saveCst);
quadr("=","1","","TEMP");
and_f=qc;
quadr("BR","","","");
sprintf(tmp,"%d",qc);
ajour_quad(and_b,1,tmp);
ajour_quad(and_b+1,1,tmp);
quadr("=","0","","TEMP");
sprintf(tmp,"%d",qc);
ajour_quad(and_f,1,tmp);
}else{
or_b=qc;
// quadr("BNZ","",s,"");
quadr("BNZ","",saveCst);
quadr("=","0","","TEMP");
or_f=qc;
quadr("BR","","","");
sprintf(tmp,"%d",qc);ajour_quad(or_b,1,tmp);ajour_quad(or_b+1,1,tmp);
quadr("=","1","","TEMP");sprintf(tmp,"%d",qc);
ajour_quad(or_f,1,tmp);
}
}
}
| EXPRESSION {if(strcmp(saveCst,"TEMP")==0){
ajour_quad(qc-1,3,"TEMP2");
strcpy(s,"TEMP2");
} else{
strcpy(s,saveCst);
}
if(AND_or_OR!=0){
if(AND_or_OR==1){
and_b=qc;
// quadr("BZ","",s,"");
quadr("BZ","",saveCst,"");
quadr("=","1","","TEMP");
and_f=qc;
quadr("BR","","","");
sprintf(tmp,"%d",qc);
ajour_quad(and_b,1,tmp);
ajour_quad(and_b+1,1,tmp);
quadr("=","0","","TEMP");
sprintf(tmp,"%d",qc);
ajour_quad(and_f,1,tmp);
}else{
strcpy(saveCst,"TEMP");
or_b=qc;
printf("%s\n",s);
quadr("BNZ","",saveCst,"");
quadr("BNZ","",saveCst,"");
}
}if(o){strcpy(saveCst,"TEMP");ajour_quad(qc-3,3,"TEMP2");printf("\n\n\n\nyaaaaaaaaaaaaaaa");}
o = 1;
}
CDTT EXPCDTT {
if(strcmp(saveOpLo,"GT")==0){quadr(">",s,saveCst,"TEMP");}
if(strcmp(saveOpLo,"GE")==0){quadr(">=",s,saveCst,"TEMP");}
if(strcmp(saveOpLo,"LT")==0){quadr("<",s,saveCst,"TEMP");}
if(strcmp(saveOpLo,"LE")==0){quadr("<=",s,saveCst,"TEMP");}
if(strcmp(saveOpLo,"EQ")==0){quadr("==",s,saveCst,"TEMP");}
if(strcmp(saveOpLo,"NE")==0){quadr("!=",s,saveCst,"TEMP");}
strcpy(saveCst,"TEMP");o=0;
}
| LOGICAL
| po EXPCDTT pf CDTT po EXPCDTT pf {rechercher ($1,"Separateur","0","0", 2,tss); rechercher ($3,"Separateur","0","0", 2,tss);rechercher ($5,"Separateur","0","0", 2,tss);rechercher ($7,"Separateur","0","0", 2,tss);}
;
CDTT : point CDT point {rechercher ($1,"Separateur","0","0", 2,tss); rechercher ($3,"Separateur","0","0", 2,tss);}
;
CDT : mc_eq {rechercher ($1,"Mot cle ","","0", 1,tss);strcpy(saveOpLo,$1);}
| mc_ne {rechercher ($1,"Mot cle ","","0", 1,tss);strcpy(saveOpLo,$1);}
| mc_ge {rechercher ($1,"Mot cle ","","0", 1,tss);strcpy(saveOpLo,$1);}
| mc_gt {rechercher ($1,"Mot cle ","","0", 1,tss);strcpy(saveOpLo,$1);}
| mc_le {rechercher ($1,"Mot cle ","","0", 1,tss);strcpy(saveOpLo,$1);}
| mc_lt {rechercher ($1,"Mot cle ","","0", 1,tss);strcpy(saveOpLo,$1);}
| mc_and {rechercher ($1,"Mot cle ","","0", 1,tss);strcpy(saveOpLo,$1);AND_or_OR=1;}
| mc_or {rechercher ($1,"Mot cle ","","0", 1,tss);strcpy(saveOpLo,$1);AND_or_OR=-1;}
;
LOOP: mc_dowhile po {Deb_while=qc;} EXPCDTT {
Fin_while=qc;
quadr("BZ","",saveCst,"");
}
pf INST mc_enddo {
rechercher ($1,"Mot cle ","","0", 1,tss);
rechercher ($2,"Separateur","0","0", 2,tss);
rechercher ($6,"Separateur","0","0", 2,tss);
rechercher ($8,"Mot cle ","","0", 1,tss);
sprintf(tmp,"%d",Deb_while);
quadr("BR",tmp,"","");
sprintf(tmp,"%d",qc);
ajour_quad(Fin_while,1,tmp);
}
;
CALLING : IDF aff mc_call IDF po PARAMETRE1 pf {
if(functionExists($4,nbParams)==0) {printf("Erreur semantique : Fonction non declarer %d,%d\n",nb_ligne,nbCol); exit(EXIT_FAILURE);};
if(functionExists($4,nbParams)==2) {printf("Erreur semantique : Nombre de parametre %d,%d\n",nb_ligne,nbCol); exit(EXIT_FAILURE);};
rechercher1 ($1,"IDF","Identifier","0", 0,tss);
rechercher ($2,"Separateur","0","0", 2,tss);
rechercher ($3,"Mot cle ","","0", 1,tss);
rechercher ($5,"Separateur","0","0", 2,tss);
rechercher ($7,"Separateur","0","0", 2,tss);
}
;
EQUIV: mc_equivalence po PARAMETRE1 pf vrg po PARAMETRE1 pf {rechercher ($1,"Mot cle ","","0", 1,tss);rechercher ($4,"Separateur","0","0", 2,tss);rechercher ($5,"Separateur","0","0", 2,tss);rechercher ($6,"Separateur","0","0", 2,tss);rechercher ($8,"Separateur","0","0", 2,tss);}
;
PARAMETRE1 : IDF {rechercher1 ($1,"IDF","Identifier","0", 0,tss); nbParams=1}
| IDF vrg PARAMETRE1 {rechercher1 ($1,"IDF","Identifier","0", 0,tss); rechercher ($2,"Separateur","0","0", 2,tss); nbParams++;}
| IDF po TAILLE pf {rechercher1 ($1,"IDF","Identifier","0", 0,tss);rechercher ($2,"Separateur","0","0", 2,tss);rechercher ($4,"Separateur","0","0", 2,tss); ;strcpy(xx, (char*)getValueOfIDF($1, tss));xx1=atoi(xx) ;printf("l");if( vv1 ==1 && idfNewValue2 > xx1) printf("erreur symantique car la taile non disponible\n");vv1=0;jj=nbb2($1);if(bb == 1 && (nb11 > nbb1($1) || nb22 > nbb2($1)))printf("erreur dans la matrice la taille non disponible");bb=0;}
| IDF po TAILLE pf PARAMETRE1 {rechercher1 ($1,"IDF","Identifier","0", 0,tss);rechercher ($2,"Separateur","0","0", 2,tss);rechercher ($4,"Separateur","0","0", 2,tss);;strcpy(xx, (char*)getValueOfIDF($1, tss));xx1=atoi(xx) ;printf("l");if( vv1 ==1 && idfNewValue2 > xx1) printf("erreur symantique car la taile non disponible\n");vv1=0; }
;
%%
int main(int argc, char **argv) {
if (argc > 0) {
yyin = fopen(argv[1], "r");
filename = argv[1];
} else {
printf("Aucun fichier à compiler\n");
return 1;
}
yyparse();
fclose(yyin);
afficher();
afficher_qdr();
executer(tss);
return 0;
}
yywrap ()
{}
int yyerror ( char* msg )
{
printf ("Erreur Syntaxique : fichier %s , ligne %d , colonne %d \n", filename,nb_ligne,col);
exit(EXIT_FAILURE);
}