def p_loop_end(p): ''' loop-end :''' end = jumps_stack.pop_quad() returning = jumps_stack.pop_quad() quad = Quadruple("GOTO", None, None, returning.result().id) quad_stack.push_quad(quad) end.set_jump(QuadrupleStack.next_quad_id())
def p_else_jump(p): ''' else-jump :''' inconditional_jump = Quadruple("GOTO", None, None, PendingJump()) quad_stack.push_quad(inconditional_jump) pending_jump_quad = jumps_stack.pop_quad() pending_jump_quad.set_jump(QuadrupleStack.next_quad_id()) jumps_stack.push_quad(inconditional_jump)
def p_register_function_type(p): ''' register-function-type :''' func_table = symbol_table.get_scope().parent().get_last_saved_func() func_table.return_type = p[-1] symbol_table.get_scope().parent().get_last_saved_var().var_type = p[-1] if p[-1] != 'void': symbol_table.get_scope().parent().set_variable_address() # We point our next quad to be generated as the start of the function func_table.func_start = QuadrupleStack.next_quad_id()
def p_set_main_jump(p): ''' set_main_jump :''' pending_jump_quad = jumps_stack.pop_quad() pending_jump_quad.set_jump(QuadrupleStack.next_quad_id())
def p_add_loop_jump(p): ''' add-loop-jump :''' next_quad_id = QuadrupleStack.next_quad_id() jumps_stack.push_quad(Quadruple(None, None, None, JumpHere(next_quad_id)))
def p_else_if_jump(p): ''' else-if-jump :''' pending_jump_quad = jumps_stack.pop_quad() pending_jump_quad.set_jump(QuadrupleStack.next_quad_id())
from symbol_table import SymbolTable from algorithms import attempt_create_quadruple, attempt_create_quadruple_unary, attempt_assignment_quadruple, attempt_pickle, save_param_func_table, attempt_pass_parameter from expression_handler import ExpressionHandler from semantic_error import SemanticError from quadruple import Quadruple from jumps_stack import JumpsStack, PendingJump, JumpHere from quadruple import QuadrupleStack from avail import Avail from constant_table import ConstantTable from address_handler import AddressHandler, POINTERS from helper import Helper from id_tracker import IdTracker exp_handler = ExpressionHandler.get_instance() symbol_table = SymbolTable.get_instance() quad_stack = QuadrupleStack.get_instance() const_table = ConstantTable.get_instance() address_handler = AddressHandler.get_instance() jumps_stack = JumpsStack.get_instance() id_tracker = IdTracker.get_instance() def p_program(p): ''' program : init_game init vars goto_main functions main pickle''' # EMBEDDED ACTION def p_goto_main(p): ''' goto_main :''' quad = Quadruple('GOTO', None, None, PendingJump()) jumps_stack.push_quad(quad)