1 / 4

Preklad binárnych výrazov J M M

Konštrukcia prekladačov. Preklad binárnych výrazov J M M. Preklad aritmetických binárnych výrazov. Vyraz: Vyraz PLUS Vyraz {$$=binAritVyraz($1,$3," iadd "," dadd ");} | Vyraz MINUS Vyraz {$$=binAritVyraz($1,$3," isub "," dsub ");}

emele
Download Presentation

Preklad binárnych výrazov J M M

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Konštrukcia prekladačov Preklad binárnych výrazovJ M M

  2. Preklad aritmetických binárnych výrazov Vyraz: Vyraz PLUS Vyraz {$$=binAritVyraz($1,$3,"iadd","dadd");} | Vyraz MINUS Vyraz {$$=binAritVyraz($1,$3,"isub","dsub");} | Vyraz KRAT Vyraz {$$=binAritVyraz($1,$3,"imul","dmul");} | Vyraz DEL Vyraz {$$=binAritVyraz($1,$3,"idiv","ddiv");} ATRV binAritVyraz (ATRV v1,ATRV v2,char* int_op,char* dbl_op){ ATRV lv; lv.kod=(char*)malloc(10+strlen(v1.kod)+strlen(v2.kod)); if(v1.sig[0]=='I' && v2.sig[0]=='I'){ lv.sig=v1.sig; sprintf(lv.kod,"%s%s\t%s\n",v1.kod,v2.kod,int_op); } else if(v1.sig[0]=='D' && v2.sig[0]=='D'){ lv.sig=v1.sig; sprintf(lv.kod,"%s%s\t%s\n",v1.kod,v2.kod,dbl_op); } else { yyerror("Nekompatibilne vyrazy pre aritmeticky operator"); lv.sig="?";sprintf(lv.kod,"%s%s????\n",v1.kod,v2.kod); } free(v1.kod);free(v2.kod); return lv; }

  3. Preklad relačných binárnych výrazov Vyraz : Vyraz LT Vyraz {$$=binRelVyraz($1,$3,"if_icmplt","dcmpl\n\tiflt",NULL);} | Vyraz LE Vyraz {$$=binRelVyraz($1,$3,"if_icmple","dcmpl\n\tifle",NULL);} | Vyraz GT Vyraz {$$=binRelVyraz($1,$3,"if_icmpgt","dcmpl\n\tifgt",NULL);} | Vyraz GE Vyraz {$$=binRelVyraz($1,$3,"if_icmpge","dcmpl\n\tifge",NULL);} | Vyraz EQ Vyraz {$$=binRelVyraz($1,$3,"if_icmpeq","dcmpl\n\tifeq","if_acmpeq");} | Vyraz NE Vyraz {$$=binRelVyraz($1,$3,"if_icmpne","dcmpl\n\tifne","if_acmpne");} ATRV binRelVyraz(ATRV v1,ATRV v2,char* int_op,char* dbl_op,char* obj_op){ ATRV lv;i nt n1,n2; lv.sig="Z"; lv.kod=(char*)malloc(100+strlen(v1.kod)+strlen(v2.kod)); if(v1.sig[0]=='I' && v2.sig[0]=='I'){ n1=navestie++;n2=navestie++; lv.kod = v1.kod + v2.kod + int_op .n1 + bipush 0 + goto n2 .n1 bipush 1 .n2 } else if(v1.sig[0]=='D' && v2.sig[0]=='D'){... } else if(v1.sig[0]=='L' && v2.sig[0]=='L'){... } else { yyerror("Nekompatibilne vyrazy pre relacny operator"); sprintf(lv.kod,"%s%s????\n",v1.kod,v2.kod);} free(v1.kod);free(v2.kod); return lv; }

  4. Preklad logických binárnych výrazov Vyraz : Vyraz OR Vyraz {$$=binLogVyraz($1,$3,"ior");} | Vyraz AND Vyraz {$$=binLogVyraz($1,$3,"iand");} ATRV binLogVyraz(ATRV v1,ATRV v2,char* log_op){ ATRV lv; lv.kod=(char*)malloc(10+strlen(v1.kod)+strlen(v2.kod)); if(v1.sig[0]=='Z' && v2.sig[0]=='Z'){ lv.sig=v1.sig; sprintf(lv.kod,"%s%s\t%s\n",v1.kod,v2.kod,log_op); } else { yyerror("Nekompatibilne vyrazy pre logicky operator"); lv.sig="?";sprintf(lv.kod,"%s%s????\n",v1.kod,v2.kod); } free(v1.kod);free(v2.kod); return lv; }

More Related