void Assignment() { char Name = GetName(); Match('='); BoolExpression(); sprintf(tmp, "mov [%c], rax", Name); EmitLn(tmp); }
void Assignment() { char Name[100]; strcpy(Name, Value); Match('='); BoolExpression(); Store(Name); }
void DoWhile(void) { char code[MAXMSG]; char l1[MAXLBL]; char l2[MAXLBL]; Match('w'); NewLabel(); strncpy(l1, label, MAXLBL); NewLabel(); strncpy(l2, label, MAXLBL); PostLabel(l1); BoolExpression(); snprintf(code, MAXMSG, "je .%s", l2); EmitLn(code); Block(l2); Match('e'); // ENDWHILE printf("#ENDWHILE\n"); snprintf(code, MAXMSG, "jmp .%s", l1); EmitLn(code); PostLabel(l2); }
void DoIf(char *L) { char L1[MAX_BUF]; char L2[MAX_BUF]; strcpy(L1, NewLabel()); strcpy(L2, L1); Match('i'); BoolExpression(); sprintf(tmp, "jz %s", L1); EmitLn(tmp); Block(L); dprint("DoIf: Got Look = %c\n", Look); if (Look == 'l') { /* match *else* statement */ Match('l'); strcpy(L2, NewLabel()); sprintf(tmp, "jmp %s", L2); EmitLn(tmp); PostLabel(L1); Block(L); } Match('e'); PostLabel(L2); }
void DoIf(char *exit_label) { char code[MAXMSG]; char l1[MAXLBL]; char l2[MAXLBL]; Match('i'); printf("# IF\n"); NewLabel(); strncpy(l1, label, MAXLBL); strncpy(l2, label, MAXLBL); BoolExpression(); snprintf(code, MAXMSG, "je .%s", l1); EmitLn(code); printf("# TRUE\n"); // here, tutorial 05 only matches 'e' once, after the if statement // this doesn't seem to work unless i add Look=='l' to the test in // Blocks(). Block(exit_label); if (Look=='l') { Match('l'); printf("#ELSE\n"); NewLabel(); strncpy(l2, label, MAXLBL); snprintf(code, MAXMSG, "jmp .%s", l2); EmitLn(code); PostLabel(l1); Block(exit_label); } Match('e'); // ENDIF printf("#ENDIF\n"); PostLabel(l2); }
void Assignment() { char name[MAX_BUF]; sprintf(name, Value); Next(); MatchString("="); BoolExpression(); Store(name); }
void Assignment() { char c = GetName(); Match('='); BoolExpression(); sprintf(tmp, "lea %c, %%ebx", c); EmitLn(tmp); EmitLn("movl %eax, (%ebx)"); }
void DoRepeat() { char L[100]; Match('r'); strcpy(L, NewLabel()); PostLabel(L); Block(); Match('u'); BoolExpression(); sprintf(tmp, "jmp %s", L); EmitLn(tmp); }
void Factor() { if(Look == '(') { Match('('); BoolExpression(); Match(')'); } else if(IsAlpha(Look)) { GetName(); LoadVar(Value); } else { LoadConst(GetNum()); } }
void DoWhile() { char L1[100]; char L2[100]; strcpy(L1, NewLabel()); strcpy(L2, NewLabel()); PostLabel(L1); BoolExpression(); BranchFalse(L2); Block(); MatchString("ENDWHILE"); Branch(L1); PostLabel(L2); }
void DoWhile() { Next(); char L1[MAX_BUF]; char L2[MAX_BUF]; sprintf(L1, NewLabel()); sprintf(L2, NewLabel()); PostLabel(L1); BoolExpression(); BranchFalse(L2); Block(); MatchString("ENDWHILE"); Branch(L1); PostLabel(L2); }
void DoRepeat() { char L1[MAX_BUF]; char L2[MAX_BUF]; Match('r'); strcpy(L1, NewLabel()); strcpy(L2, NewLabel()); PostLabel(L1); Block(L2); Match('u'); BoolExpression(); sprintf(tmp, "jz %s", L1); EmitLn(tmp); PostLabel(L2); }
void DoWhile() { char L1[100]; char L2[100]; Match('w'); strcpy(L1, NewLabel()); strcpy(L2, NewLabel()); PostLabel(L1); BoolExpression(); sprintf(tmp, "jz %s", L2); EmitLn(tmp); Block(); Match('e'); sprintf(tmp, "jmp %s", L1); EmitLn(tmp); PostLabel(L2); }
void Factor() { if (Token == '(') { Next(); BoolExpression(); MatchString(")"); } else { if (Token == 'x') { LoadVar(Value); } else if (Token == '#') { LoadConst(Value); } else { Expected("Math Factor"); } Next(); } }
void DoIf() { char L1[100]; char L2[100]; BoolExpression(); strcpy(L1, NewLabel()); strcpy(L2, L1); BranchFalse(L1); Block(); if(Token == 'l') { Match('l'); strcpy(L2, NewLabel()); Branch(L2); PostLabel(L1); Block(); } PostLabel(L2); MatchString("ENDIF"); }
/* Recognize and Translate an IF construct */ void DoIf() { Next(); char L1[MAX_BUF]; char L2[MAX_BUF]; sprintf(L1, NewLabel()); sprintf(L2, L1); BoolExpression(); BranchFalse(L1); Block(); if (Token == 'l') { Next(); sprintf(L2, NewLabel()); Branch(L2); PostLabel(L1); Block(); } PostLabel(L2); MatchString("ENDIF"); }
void DoIf() { char L1[100]; char L2[100]; Match('i'); BoolExpression(); strcpy(L1, NewLabel()); strcpy(L2, L1); sprintf(tmp, "jz %s", L1); EmitLn(tmp); Block(); if(Look == 'l') { Match('l'); strcpy(L2, NewLabel()); sprintf(tmp, "jmp %s", L2); EmitLn(tmp); PostLabel(L1); Block(); } Match('e'); PostLabel(L2); }
void DoRepeat(void) { char code[MAXMSG]; char l1[MAXLBL]; char l2[MAXLBL]; Match('r'); printf("# REPEAT\n"); NewLabel(); strncpy(l1, label, MAXLBL); NewLabel(); strncpy(l2, label, MAXLBL); PostLabel(l1); Block(l2); Match('u'); printf("# UNTIL\n"); BoolExpression(); snprintf(code, MAXMSG, "je .%s\t\t#repeat loop", l1); EmitLn(code); PostLabel(l2); // exit point }