def do(self, RequiredLocalVariablesDB): LanguageDB = Setup.language_db # (*) Initialize the label and variable trackers variable_db.init(RequiredLocalVariablesDB) variable_db.require("input") init_address_handling({}) # (*) Pre Context State Machine # (If present: All pre-context combined in single backward analyzer.) pre_context = self.__code_pre_context_state_machine() # (*) Main State Machine -- try to match core patterns main = self.__code_main_state_machine() # (*) Backward input position detection # (Seldomly present -- only for Pseudo-Ambiguous Post Contexts) bipd = self.__code_backward_input_position_detection() # (*) Determine required labels and variables routed_address_set = get_address_set_subject_to_routing() routed_address_set.add(get_address("$terminal-EOF", U=True)) routed_state_info_list = state_router_generator.get_info(routed_address_set) state_router = [ state_router_generator.do(routed_state_info_list) ] variable_db.require("target_state_index", Condition_ComputedGoto=False) if is_label_referenced("$reload-FORWARD") or is_label_referenced("$reload-BACKWARD"): variable_db.require("target_state_else_index") variable_db.require("target_state_index") # Following function refers to the global 'variable_db' variable_definitions = self.language_db.VARIABLE_DEFINITIONS(variable_db) function_body = [] function_body.extend(pre_context) # implementation of pre-contexts (if there are some) function_body.extend(main) # main pattern matcher function_body.extend(bipd) # (seldom != empty; only for pseudo-ambiguous post contexts) function_body.extend(state_router) # route to state by index (only if no computed gotos) # (*) Pack Pre-Context and Core State Machine into a single function analyzer_function = self.language_db["$analyzer-func"](self.state_machine_name, Setup, variable_definitions, function_body, self.mode_name_list) txt = [ LanguageDB["$header-definitions"](LanguageDB, self.on_after_match) ] txt += get_plain_strings(analyzer_function) for i, element in enumerate(txt): if not isinstance(element, (str, unicode)): print element.__class__.__name__ for k in range(max(0,i-10)): print "before:", k, txt[k] for k in range(i+1, min(i+10, len(txt))): print "after: ", k, txt[k] assert False return txt
def get_code(CodeFragmentList, variable_db={}, IndentationBase=1): global Lexeme_matcher code_str = "" for code_info in CodeFragmentList: result = code_info.get_code() if type(result) == tuple: result, add_variable_db = result variable_db.update(add_variable_db) if type(result) == list: code_str += "".join(get_plain_strings(result)) else: code_str += result # If 'Lexeme' occurs as an isolated word, then ensure the generation of # a terminating zero. Note, that the occurence of 'LexemeBegin' does not # ensure the preparation of a terminating zero. require_terminating_zero_f = (Lexeme_matcher.search(code_str) is not None) return pretty_code(code_str, IndentationBase), require_terminating_zero_f
def get_code(CodeFragmentList, variable_db={}, IndentationBase=1): global Lexeme_matcher code_str = "" for code_info in CodeFragmentList: result = code_info.get_code() if type(result) == tuple: result, add_variable_db = result variable_db.update(add_variable_db) if type(result) == list: code_str += "".join(get_plain_strings(result)) else: code_str += result # If 'Lexeme' occurs as an isolated word, then ensure the generation of # a terminating zero. Note, that the occurence of 'LexemeBegin' does not # ensure the preparation of a terminating zero. require_terminating_zero_f = (Lexeme_matcher.search(code_str) is not None) return pretty_code(code_str, IndentationBase), require_terminating_zero_f
def do(self, RequiredLocalVariablesDB): LanguageDB = Setup.language_db # (*) Initialize the label and variable trackers variable_db.init(RequiredLocalVariablesDB) variable_db.require("input") init_address_handling({}) # (*) Pre Context State Machine # (If present: All pre-context combined in single backward analyzer.) pre_context = self.__code_pre_context_state_machine() # (*) Main State Machine -- try to match core patterns main = self.__code_main_state_machine() # (*) Backward input position detection # (Seldomly present -- only for Pseudo-Ambiguous Post Contexts) bipd = self.__code_backward_input_position_detection() # (*) Determine required labels and variables routed_address_set = get_address_set_subject_to_routing() routed_address_set.add(get_address("$terminal-EOF", U=True)) routed_state_info_list = state_router_generator.get_info( routed_address_set) state_router = [state_router_generator.do(routed_state_info_list)] variable_db.require("target_state_index", Condition_ComputedGoto=False) if is_label_referenced("$reload-FORWARD") or is_label_referenced( "$reload-BACKWARD"): variable_db.require("target_state_else_index") variable_db.require("target_state_index") # Following function refers to the global 'variable_db' variable_definitions = self.language_db.VARIABLE_DEFINITIONS( variable_db) function_body = [] function_body.extend( pre_context) # implementation of pre-contexts (if there are some) function_body.extend(main) # main pattern matcher function_body.extend( bipd) # (seldom != empty; only for pseudo-ambiguous post contexts) function_body.extend( state_router ) # route to state by index (only if no computed gotos) # (*) Pack Pre-Context and Core State Machine into a single function analyzer_function = self.language_db["$analyzer-func"]( self.state_machine_name, Setup, variable_definitions, function_body, self.mode_name_list) txt = [ LanguageDB["$header-definitions"](LanguageDB, self.on_after_match) ] txt += get_plain_strings(analyzer_function) for i, element in enumerate(txt): if not isinstance(element, (str, unicode)): print element.__class__.__name__ for k in range(max(0, i - 10)): print "before:", k, txt[k] for k in range(i + 1, min(i + 10, len(txt))): print "after: ", k, txt[k] assert False return txt