def fill_repeat(): '''Repeat function helper, the control variable is updated''' false = jump_stack.pop() ret = jump_stack.pop() counter = Var('int', quadruples[ret - 2][4], quadruples_addr[ret - 2][4]) one_addr = symbol_table.insert_cte('int', 1) one_var = Var('int', 1, one_addr) res = gen_quad_exp('-', counter, one_var) gen_quad_assig(counter, res) gen_quad('GOTO', '', '', ret) mod_quad(false, 4, quad_pos())
def gen_repeat(n): '''Repeat function is a while that initializes its control variable with user's input and updates it with every cycle subtracting one''' global temp_pos temp = 'temp' + str(temp_pos) temp_addr = insert_temp('int', temp) temp_var = Var('int', temp, temp_addr) temp_pos += 1 gen_quad_assig(temp_var, n) jump_stack.append(quad_pos()) zero_addr = symbol_table.insert_cte('int', 0) zero_var = Var('int', 0, zero_addr) res = gen_quad_exp('>', temp_var, zero_var) gen_gotof(res)
def p_cte_bool(p): '''cte_bool : CTE_BOOL''' addr = symbol_table.insert_cte('bool', bool(p[1])) p[0] = Var('bool', bool(p[1]), addr)
def p_cte_string(p): '''cte_string : CTE_STRING''' p[1] = p[1][1:-1] addr = symbol_table.insert_cte('string', str(p[1])) p[0] = Var('string', str(p[1]), addr)
def p_cte_f(p): '''cte_f : CTE_F''' addr = symbol_table.insert_cte('float', float(p[1])) p[0] = Var('float', float(p[1]), addr)
def p_cte_i(p): '''cte_i : CTE_I''' addr = symbol_table.insert_cte('int', int(p[1])) p[0] = Var('int', int(p[1]), addr)