%union { int nombre; } %{ #include "tables.h" #include FILE * file; FILE * file2; %} %token tMUL tDIV tADD tSUB %token tAFC tCPY %token tNB %% Programme : Instruction Programme; Programme : Instruction; Instruction : tMUL tNB tNB tNB {increment_time(); int added_instruction = 0; int reg_src1 = get_reg_read($3, &added_instruction); int reg_src2 = get_reg_read($4, &added_instruction); int reg_dest = get_reg_write($2, &added_instruction); add_instruction(MUL, reg_dest, reg_src1, reg_src2); new_instruction(added_instruction + 1);}; Instruction : tADD tNB tNB tNB {increment_time(); int added_instruction = 0; int reg_src1 = get_reg_read($3, &added_instruction); int reg_src2 = get_reg_read($4, &added_instruction); int reg_dest = get_reg_write($2, &added_instruction); add_instruction(ADD, reg_dest, reg_src1, reg_src2); new_instruction(added_instruction + 1);}; Instruction : tDIV tNB tNB tNB {increment_time(); int added_instruction = 0; int reg_src1 = get_reg_read($3, &added_instruction); int reg_src2 = get_reg_read($4, &added_instruction); int reg_dest = get_reg_write($2, &added_instruction); add_instruction(DIV, reg_dest, reg_src1, reg_src2); new_instruction(added_instruction + 1);}; Instruction : tSUB tNB tNB tNB {increment_time(); int added_instruction = 0; int reg_src1 = get_reg_read($3, &added_instruction); int reg_src2 = get_reg_read($4, &added_instruction); int reg_dest = get_reg_write($2, &added_instruction); add_instruction(SUB, reg_dest, reg_src1, reg_src2); new_instruction(added_instruction + 1);}; Instruction : tAFC tNB tNB {increment_time(); int added_instruction = 0; int reg_dest = get_reg_write($2, &added_instruction); add_instruction(AFC, reg_dest, $3, 0); new_instruction(added_instruction + 1);}; Instruction : tCPY tNB tNB {increment_time(); int added_instruction = 0; int reg_src = get_reg_read($3, &added_instruction); int reg_dest = get_reg_write($2, &added_instruction); add_instruction(CPY, reg_dest, reg_src, 0); new_instruction(added_instruction + 1);}; %% int main(void) { file = fopen("output.asm", "w"); file2 = fopen("output_bin.txt", "w"); init(); yyparse(); flush_and_init(); write_asm(file); write_code_machine(file2); return 0; }