diff --git a/asmTable.c b/asmTable.c index f2499f1..ab43810 100644 --- a/asmTable.c +++ b/asmTable.c @@ -49,6 +49,7 @@ void addLine(char* s) { /*inserts the address in case of jumps*/ void setJumpLine(int index, int addr) { asmTable[index].jumpLine = addr; + printf("\n%d aaaaa %d\n",index,addr); displayASMTable(); } diff --git a/yacc.y b/yacc.y index ad452c1..7575a57 100644 --- a/yacc.y +++ b/yacc.y @@ -48,6 +48,7 @@ void yyerror (const char *); %type Declaration %type NbOrVariable %token tIF +%type IfStatement1 %start Program %% @@ -100,17 +101,17 @@ NumericalOperator : tLE | tGE | tEQ | tNE | tLT | tGT; Operation: tADD | tMUL | tSUB | tDIV; */ -IfStatement : tIF Condition { - int ligne =getCurrentLineNumber(); addLine("JMPF"); $1 = ligne ; -} InnerBlock { - int current = getCurrentLineNumber(); printf("current Line %d", current); addLine("JMP"); $1 = current + 1; setJumpLine($1, current+1); -} tELSE InnerBlock { - int current = getCurrentLineNumber() ; setJumpLine($1, current); +IfStatement1 : %empty { + int ligne =getCurrentLineNumber(); addLine("JMPF"); $$ = ligne ; + }; + +IfStatement : tIF Condition IfStatement1 InnerBlock tELSE { + 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 { -int ligne =getCurrentLineNumber(); addLine("JMPF"); $1 = ligne ; -} InnerBlock { - int current = getCurrentLineNumber(); printf("current Line %d", current); setJumpLine($1, current); + | tIF Condition IfStatement1 InnerBlock { + int current = getCurrentLineNumber(); printf("current Line %d", current); setJumpLine($3, current); }; // todo it does either one of the two but not the two