def __transition_target_data_structures(TheTemplate, SMD): """Defines the transition targets for each involved state. """ template_index = TheTemplate.core().state_index def __array_to_code(Array, ComputedGotoF=False): txt = ["{ "] for index in Array: if index != None: elm = "QUEX_LABEL(%i)" % get_address("$entry", index, U=True, R=True) else: elm = "QUEX_LABEL(%i)" % get_address("$drop-out", template_index, U=True, R=True) txt.append(elm + ", ") txt.append("}") return "".join(txt) involved_state_list = TheTemplate.template_combination().involved_state_list() involved_state_n = len(involved_state_list) target_state_list_db = TheTemplate.transitions().target_state_list_db() for target_index, target_state_index_list in enumerate(target_state_list_db): assert len(target_state_index_list) == involved_state_n variable_db.require_array("template_%i_target_%i", ElementN = involved_state_n, Initial = __array_to_code(target_state_index_list), Index = (template_index, target_index)) # If the template does not have uniform state entries, the entries # need to be routed on recursion, for example. Thus we need to map # from state-key to state. if not TheTemplate.uniform_state_entries_f(): variable_db.require_array("template_%i_map_state_key_to_state_index", ElementN = involved_state_n, Initial = __array_to_code(involved_state_list), Index = template_index)
def __path_definition(PathWalker, SMD): """Defines the transition targets for each involved state. """ PathWalkerID = PathWalker.core().state_index PathList = PathWalker.path_list() PathN = len(PathList) def __get_state_list(): result = [] for path in PathList: Sequence = path.sequence() for state_index, dummy in Sequence[:-1]: result.append("QUEX_LABEL(%i), " % get_address("$entry", state_index, R=True, U=True)) end_state_index = Sequence[-1][0] # If 'end_state_index' belongs to a non-implemented dead-end-state # => 'get_real_address()' returns address of immediately entered terminal end_state_label = "QUEX_LABEL(%i), " % get_address("$entry", end_state_index, R=True, U=True) result.append(end_state_label) return result memory = ["\n"] memory_index = 0 for path in PathList: Sequence = path.sequence() L = len(Sequence) # Last element of sequence contains only the 'end state'. memory.append(" ") sequence_str = [] for state_index, character in Sequence[:-1]: memory.append("%i, " % character) sequence_str.append(Interval(character).get_utf8_string()) memory.append("QUEX_SETTING_PATH_TERMINATION_CODE, ") memory.append(LanguageDB["$comment"]("".join(sequence_str)) + "\n") variable_db.require("path_%i", Initial = "path_walker_%i_base + %i" % (PathWalkerID, memory_index), Index = path.index()) memory_index += L # (*) Path Walker Basis # The 'base' must be defined before all --> PriorityF (see table in variable_db) variable_db.require_array("path_walker_%i_base", ElementN = memory_index + 1, Initial = ["{"] + memory + ["\n }"], Index = PathWalkerID) # (*) The State Information for each path step if not PathWalker.uniform_state_entries_f(): state_list = __get_state_list() variable_db.require_array("path_walker_%i_state", ElementN = len(state_list), Initial = ["{"] + state_list + ["}"], Index = PathWalkerID)
def __local_variable_definition(PostContextID_List, PreContextID_List, LanguageDB): PostContextN = len(PostContextID_List) variable_db.require("last_acceptance", Initial="QUEX_LABEL(%i)" % get_address("$terminal-FAILURE")) variable_db.require("last_acceptance_input_position") variable_db.require_array("post_context_start_position", ElementN = PostContextN, Initial = "{ " + ("0, " * (PostContextN - 1) + "0") + "}") variable_db.require("PostContextStartPositionN", Initial = "(size_t)" + repr(PostContextN)) variable_db.require("input") # -- pre-condition fulfillment flags for sm_id in PreContextID_List: variable_db.require("pre_context_%i_fulfilled_f", Index = sm_id) return LanguageDB["$local-variable-defs"](variable_db.get())
def __transition_target_data_structures(TheTemplate, SMD): """Defines the transition targets for each involved state. """ template_index = TheTemplate.core().state_index def __array_to_code(Array, ComputedGotoF=False): txt = ["{ "] for index in Array: if index != None: elm = "QUEX_LABEL(%i)" % get_address( "$entry", index, U=True, R=True) else: elm = "QUEX_LABEL(%i)" % get_address( "$drop-out", template_index, U=True, R=True) txt.append(elm + ", ") txt.append("}") return "".join(txt) involved_state_list = TheTemplate.template_combination( ).involved_state_list() involved_state_n = len(involved_state_list) target_state_list_db = TheTemplate.transitions().target_state_list_db() for target_index, target_state_index_list in enumerate( target_state_list_db): assert len(target_state_index_list) == involved_state_n variable_db.require_array( "template_%i_target_%i", ElementN=involved_state_n, Initial=__array_to_code(target_state_index_list), Index=(template_index, target_index)) # If the template does not have uniform state entries, the entries # need to be routed on recursion, for example. Thus we need to map # from state-key to state. if not TheTemplate.uniform_state_entries_f(): variable_db.require_array("template_%i_map_state_key_to_state_index", ElementN=involved_state_n, Initial=__array_to_code(involved_state_list), Index=template_index)
def __local_variable_definition(PostContextID_List, PreContextID_List, LanguageDB): PostContextN = len(PostContextID_List) variable_db.require("last_acceptance", Initial="QUEX_LABEL(%i)" % get_address("$terminal-FAILURE")) variable_db.require("last_acceptance_input_position") variable_db.require_array("post_context_start_position", ElementN=PostContextN, Initial="{ " + ("0, " * (PostContextN - 1) + "0") + "}") variable_db.require("PostContextStartPositionN", Initial="(size_t)" + repr(PostContextN)) variable_db.require("input") # -- pre-condition fulfillment flags for sm_id in PreContextID_List: variable_db.require("pre_context_%i_fulfilled_f", Index=sm_id) return LanguageDB["$local-variable-defs"](variable_db.get())