%union { int nombre; } %{ #include "tables.h" #include FILE * file; %} %token tMUL tDIV tADD tSUB tINF tSUP tEQU %token tAFC tCPY tAFCA tCPYA %token tREAD tWR %token tJMP tJMF %token tGET tPRI %token tCALL tRET %token tSTOP %token tNB %% Programme : Instruction Programme; Programme : Instruction; Instruction : tMUL tNB tNB tNB {increment_time(); int reg_dest = get_reg_write($2, file); int reg_src1 = get_reg_read($3, file); int reg_src2 = get_reg_read($4, file); fprintf(file, "MUL %d %d %d\n", reg_dest, reg_src1, reg_src2);}; Instruction : tADD tNB tNB tNB {increment_time(); int reg_dest = get_reg_write($2, file); int reg_src1 = get_reg_read($3, file); int reg_src2 = get_reg_read($4, file); fprintf(file, "ADD %d %d %d\n", reg_dest, reg_src1, reg_src2);}; Instruction : tDIV tNB tNB tNB {increment_time(); int reg_dest = get_reg_write($2, file); int reg_src1 = get_reg_read($3, file); int reg_src2 = get_reg_read($4, file); fprintf(file, "DIV %d %d %d\n", reg_dest, reg_src1, reg_src2);}; Instruction : tSUB tNB tNB tNB {increment_time(); int reg_dest = get_reg_write($2, file); int reg_src1 = get_reg_read($3, file); int reg_src2 = get_reg_read($4, file); fprintf(file, "SUB %d %d %d\n", reg_dest, reg_src1, reg_src2);}; Instruction : tINF tNB tNB tNB {increment_time(); int reg_dest = get_reg_write($2, file); int reg_src1 = get_reg_read($3, file); int reg_src2 = get_reg_read($4, file); fprintf(file, "INF %d %d %d\n", reg_dest, reg_src1, reg_src2);}; Instruction : tSUP tNB tNB tNB {increment_time(); int reg_dest = get_reg_write($2, file); int reg_src1 = get_reg_read($3, file); int reg_src2 = get_reg_read($4, file); fprintf(file, "SUP %d %d %d\n", reg_dest, reg_src1, reg_src2);}; Instruction : tEQU tNB tNB tNB {increment_time(); int reg_dest = get_reg_write($2, file); int reg_src1 = get_reg_read($3, file); int reg_src2 = get_reg_read($4, file); fprintf(file, "EQU %d %d %d\n", reg_dest, reg_src1, reg_src2);}; Instruction : tAFC tNB tNB {increment_time(); int reg_dest = get_reg_write($2, file); fprintf(file, "AFC %d %d\n", reg_dest, $3);}; Instruction : tCPY tNB tNB {increment_time(); int reg_dest = get_reg_write($2, file); int reg_src = get_reg_read($3, file); fprintf(file, "CPY %d %d\n", reg_dest, reg_src);}; Instruction : tAFCA tNB tNB {increment_time(); int reg_dest = get_reg_write($2, file); fprintf(file, "AFCA %d %d\n", reg_dest, $3);}; Instruction : tCPYA tNB tNB {increment_time(); int reg_dest = get_reg_write($2, file); int reg_src = get_reg_read($3, file); fprintf(file, "CPYA %d %d\n", reg_dest, reg_src);}; Instruction : tJMP tNB {increment_time(); fprintf(file, "JMP %d\n", $2);}; Instruction : tJMF tNB tNB {increment_time(); int reg_src = get_reg_read($2, file); int reg_aux = get_reg_write(-1, file); fprintf(file, "SUB %d %d %d\n", reg_aux, reg_aux, reg_src); fprintf(file, "JMZ %d\n", $3);}; Instruction : tWR tNB tNB {increment_time(); int reg_dest = get_reg_write($2, file); int reg_addr = get_reg_read($3, file); fprintf(file, "LOADA %d %d\n", reg_dest, reg_addr);}; Instruction : tREAD tNB tNB {increment_time(); int reg_addr = get_reg_read($2, file); int reg_value = get_reg_read($3, file); fprintf(file, "STOREA %d %d\n", reg_addr, reg_value);}; Instruction : tGET tNB {increment_time(); int reg_dest = get_reg_write($2, file); fprintf(file, "GET %d\n", reg_dest);}; Instruction : tPRI tNB {increment_time(); int reg_src = get_reg_read($2, file); fprintf(file, "PRI %d\n", reg_src);}; Instruction : tCALL tNB tNB {increment_time(); flush_and_init(file); fprintf(file, "CALL %d %d\n", $2, $3);}; Instruction : tRET {increment_time(); flush_and_init(file); fprintf(file, "RET\n");}; Instruction : tSTOP {increment_time(); fprintf(file, "STOP\n");}; %% int main(void) { file = stdout; init(); yyparse(); return 0; }