def.y ->def.tab.c , def.tab.h def.yy->def.tab.cc, def.tab.hh Makefile: def.y def.tab.c , | | V V def.yy def.tab.cc, nowa zmienna: CPP=g++ CC -> CPP w dwóch miejscach: kompilacja def.tab.cc kompilacja całości def.yy: extern "C" int yylex(); extern "C" int yyerror(const char *msg, ...); using namespace std; zx.l: int yyerror(const char *msg, ...); int yyerror(const char *msg, ...){ kod: int a;//=26 int b = 2; int c = 3; int foo = 4; a = b + 7 * foo - (c+5)/2; strumień wyjściowy ONP: a b 7 foo * + c 5 + 2 / - = '1*' -> w1* = 7 * foo '1+' -> w1+ = b + w1* '2+' -> w2+ = c + 5 '1/' -> w1/ = w2+ / 2 '1-' -> w1- = w1+ - w1/ '1=' -> w1= = a = w1- '1*' -> t1 = 7 * foo '1+' -> t2 = b + t1 '2+' -> t3 = c + 5 '1/' -> t4 = t3 / 2 '1-' -> t5 = t2 - t4 '1=' -> t6 = a = t5 '1*' -> t1 = 7 * foo MOV R1,7 # MOV R1, 7 MOV R2,#3 # MOV R2, foo wartość 4 MUL R1,R2 # * R1,R2 w R1 7*4 MOV #4,R1 # MOV t1,R1 w #4 - 28 '1+' -> t2 = b + t1 MOV R1,#1 //2 MOV R2,#4 //28 ADD R1,R2 //30 MOV #5,R1 // '2+' -> t3 = c + 5 MOV R1,#2 //3 MOV R2,5 //5 ADD R1,R2 //8 MOV #6,R1 // '1/' -> t4 = t3 / 2 MOV R1,#6 //8 MOV R2,2 DIV R1,R2 //4 MOV #7,R1 '1-' -> t5 = t2 - t4 MOV R1,#5 //30 MOV R2,#7 //4 SUB R1,R2 //26 MOV #8,R1 '1=' -> t6 = a = t5 MOV #0,#8 wynikowy kod: 00:int b = 2; int c = 3; int foo = 4; MOV R1,7 MOV R2,#3 MUL R1,R2 MOV #4,R1 MOV R1,#1 MOV R2,#4 ADD R1,R2 MOV #5,R1 MOV R1,#2 MOV R2,5 ADD R1,R2 MOV #6,R1 MOV R1,#6 MOV R2,2 DIV R1,R2 MOV #7,R1 MOV R1,#5 MOV R2,#7 SUB R1,R2 22:MOV #8,R1 23:MOV #0,#8