Compare commits

...

2 commits

Author SHA1 Message Date
Raphaël LACROIX
6927b7da82 If Done (and todo cleaned up) 2023-04-20 10:23:57 +02:00
Raphaël LACROIX
358e98d6d6 If Done 2023-04-20 10:23:32 +02:00
2 changed files with 13 additions and 13 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();
} }

23
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,20 +101,18 @@ 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 {
int current = getCurrentLineNumber() ; setJumpLine($1, current);
}
| tIF Condition {
int ligne =getCurrentLineNumber(); addLine("JMPF"); $1 = ligne ;
} InnerBlock {
int current = getCurrentLineNumber(); printf("current Line %d", current); setJumpLine($1, current);
}; };
// todo it does either one of the two but not the two 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 IfStatement1 InnerBlock {
int current = getCurrentLineNumber(); printf("current Line %d", current); setJumpLine($3, current);
};
WhileStatement : tWHILE {} WhileStatement : tWHILE {}
Condition InnerBlock {}; Condition InnerBlock {};