def declarations(): global line_number line_number = get_line_number() global synch_set global memory_counter line = tokens[0] token = peek_token() if token == 'var': match('var') token = tokens[0] match('id') match(':') the_type = type_() if type(the_type) is tuple: array_size = the_type[1] the_type = the_type[0] variable_types.update({token[1]: the_type}) checking = nodes value_counter = 0 func = set_function_name() if nodes: green_node = nodes[0] while green_node.right_sibling is not None: green_node = green_node.right_sibling if green_node.right_sibling is None: new_blue_node = BlueNode(token[1], the_type) memory_counter = 0 new_blue_node.value = memory_counter if new_blue_node.w_type is 'integer': memory_counter += 4 elif new_blue_node.w_type is 'real': memory_counter += 8 elif new_blue_node.w_type == "a-real": memory_counter += 8 * array_size elif new_blue_node.w_type == "a-integer": memory_counter += 4 * array_size green_node.right_sibling = new_blue_node nodes.insert(0, green_node.right_sibling) write_to_memory_file(func, new_blue_node.data, new_blue_node.value) checking = nodes match(';') declarations_() else: # synch_set = ['function', 'begin'] del synch_set[:] synch_set.append('var') synch_set.append('begin') synch_set.append('$') handle_sync() syntax_error(token, 'var', line_number)
def paramlist_(green_node): test = tokens[0] token = peek_token() global line_number line_number = get_line_number() all_node = nodes if token == ')': pass elif token == ';': match(';') token = tokens[0] match('id') match(':') green_node.params += 1 my_type = type_() # green_node.param_types.append(my_type) if type(my_type) is tuple: my_type = my_type[0] green_node.param_types.append(my_type) else: green_node.param_types.append(my_type) variable_types.update({token[1]: my_type}) if nodes: node = nodes[0] while node.right_sibling is not None: node = node.right_sibling if node.right_sibling is None: node.right_sibling = BlueNode(token[1], my_type) nodes.insert(0, node.right_sibling) paramlist_(green_node) else: del synch_set[:] synch_set.append(')') handle_sync() syntax_error(token, '(', ';')
def idlist(): global line_number line_number = get_line_number() line = tokens[0] token = peek_token() if token == 'id': token = tokens[0] match('id') green_node = nodes[0] if green_node.right_sibling is None: green_node.right_sibling = BlueNode(token[1], "pname") nodes.insert(0, green_node.right_sibling) idlist_() else: del synch_set[:] synch_set.append(')') handle_sync() syntax_error(token, 'id')
def paramlist(): param_list = [] line = tokens[0] token = peek_token() global line_number line_number = get_line_number() green_node = nodes[0] if token == 'id': token = tokens[0] lexeme = token[1] match('id') match(':') my_type = type_() if type(my_type) is tuple: my_type = my_type[0] green_node.param_types.append(my_type) else: green_node.param_types.append(my_type) # token = tokens[0] variable_types.update({token[1]: my_type}) check_nodes = nodes if nodes: node = nodes[0] while node.right_sibling is not None: node = node.right_sibling if node.right_sibling is None: node.right_sibling = BlueNode(token[1], my_type) nodes.insert(0, node.right_sibling) green_node.params = 1 paramlist_(green_node) else: del synch_set[:] synch_set.append(')') handle_sync() syntax_error(token, 'id')
def declarations_(): line = tokens[0] token = peek_token() array_size = 0 global line_number line_number = get_line_number() global memory_counter global variable_exist variable_exist = 0 if token == 'begin': pass elif token == 'function': pass elif token == 'var': match('var') token = tokens[0] match('id') match(':') the_type = type_() if type(the_type) is tuple: array_size = the_type[1] the_type = the_type[0] variable_types.update({token[1]: the_type}) current_nodes = nodes if nodes: node = nodes[0] while node.right_sibling is not None: node = node.right_sibling if node.right_sibling is None: new_blue_node = BlueNode(token[1], the_type) new_blue_node.value = memory_counter if new_blue_node.w_type == 'integer': memory_counter += 4 elif new_blue_node.w_type == 'real': memory_counter += 8 elif new_blue_node.w_type == "a-real": memory_counter += 8 * array_size elif new_blue_node.w_type == "a-integer": memory_counter += 4 * array_size node.right_sibling = new_blue_node nodes.insert(0, node.right_sibling) next_node = nodes[1] counter = 0 current_n = new_blue_node while current_n.__class__.__name__ is not 'GreenNode': if new_blue_node.data == next_node.data: variable_exist = 1 counter += 1 current_n = nodes[counter] next_node = nodes[counter] continue counter += 1 current_n = nodes[counter] next_node = nodes[counter] write_to_memory_file('', new_blue_node.data, new_blue_node.value) if variable_exist == 1: duplicated_variable(line_number, new_blue_node.data) testing = nodes match(';') declarations_() else: # synch_set = ['function', 'begin'] del synch_set[:] synch_set.append('function') synch_set.append('begin') handle_sync() syntax_error(token, 'begin', 'function', 'var')