This commit is contained in:
Raphaël LACROIX 2023-04-20 10:23:32 +02:00
parent 18f64a1653
commit 358e98d6d6
2 changed files with 12 additions and 10 deletions

View file

@ -49,6 +49,7 @@ void addLine(char* s) {
/*inserts the address in case of jumps*/ /*inserts the address in case of jumps*/
void setJumpLine(int index, int addr) { void setJumpLine(int index, int addr) {
asmTable[index].jumpLine = addr; asmTable[index].jumpLine = addr;
printf("\n%d aaaaa %d\n",index,addr);
displayASMTable(); displayASMTable();
} }

21
yacc.y
View file

@ -48,6 +48,7 @@ void yyerror (const char *);
%type <addr> Declaration %type <addr> Declaration
%type <addr> NbOrVariable %type <addr> NbOrVariable
%token <nbInt> tIF %token <nbInt> tIF
%type <nbInt> IfStatement1
%start Program %start Program
%% %%
@ -100,17 +101,17 @@ NumericalOperator : tLE | tGE | tEQ | tNE | tLT | tGT;
Operation: tADD | tMUL | tSUB | tDIV; Operation: tADD | tMUL | tSUB | tDIV;
*/ */
IfStatement : tIF Condition { IfStatement1 : %empty {
int ligne =getCurrentLineNumber(); addLine("JMPF"); $1 = ligne ; int ligne =getCurrentLineNumber(); addLine("JMPF"); $<nbInt>$ = ligne ;
} InnerBlock { };
int current = getCurrentLineNumber(); printf("current Line %d", current); addLine("JMP"); $1 = current + 1; setJumpLine($1, current+1);
} tELSE InnerBlock { IfStatement : tIF Condition IfStatement1 InnerBlock tELSE {
int current = getCurrentLineNumber() ; setJumpLine($1, current); int current = getCurrentLineNumber(); printf("current Line %d", current); addLine("JMP"); $1 = current; setJumpLine($3, current+1);
} InnerBlock {
int current = getCurrentLineNumber() ; printf("%d, %d",$1, current);setJumpLine($1, current);
} }
| tIF Condition { | tIF Condition IfStatement1 InnerBlock {
int ligne =getCurrentLineNumber(); addLine("JMPF"); $1 = ligne ; int current = getCurrentLineNumber(); printf("current Line %d", current); setJumpLine($3, current);
} InnerBlock {
int current = getCurrentLineNumber(); printf("current Line %d", current); setJumpLine($1, current);
}; };
// todo it does either one of the two but not the two // todo it does either one of the two but not the two