當前位置: 首頁>>代碼示例>>Python>>正文


Python StateMachine.states[new_state_index]方法代碼示例

本文整理匯總了Python中quex.engine.state_machine.core.StateMachine.states[new_state_index]方法的典型用法代碼示例。如果您正苦於以下問題:Python StateMachine.states[new_state_index]方法的具體用法?Python StateMachine.states[new_state_index]怎麽用?Python StateMachine.states[new_state_index]使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在quex.engine.state_machine.core.StateMachine的用法示例。


在下文中一共展示了StateMachine.states[new_state_index]方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_state_machine

# 需要導入模塊: from quex.engine.state_machine.core import StateMachine [as 別名]
# 或者: from quex.engine.state_machine.core.StateMachine import states[new_state_index] [as 別名]
def create_state_machine(SM, Result, Class_StateMachine, Class_State):
    # If all states are of size one, this means, that there were no states that
    # could have been combined. In this case a simple copy of the original
    # state machine will do.
    if len(filter(lambda state_set: len(state_set) != 1, Result.state_set_list)) == 0:
        return SM.clone()
    
    # Define a mapping from the state set to a new target state index
    #
    # map:  state_set_index  --->  index of the state that represents it
    #
    map_new_state_index = dict([(i, state_machine_index.get()) for i in xrange(len(Result.state_set_list))])
                
    # The state set that contains the initial state becomes the initial state of 
    # the new state machine.   
    state_set_containing_initial_state_i = Result.map[SM.init_state_index]
    new_init_state_index                 = map_new_state_index[state_set_containing_initial_state_i]

    result = StateMachine(new_init_state_index)

    # Ensure that each target state index has a state inside the state machine
    # Build up the state machine out of the state sets
    for state_set_idx, state_set in enumerate(Result.state_set_list):

        new_state_index = map_new_state_index[state_set_idx]

        # Merge all core information of the states inside the state set.
        # If one state set contains an acceptance state, then the result is 'acceptance'.
        # (Note: The initial split separates acceptance states from those that are not
        #  acceptance states. There can be no state set containing acceptance and 
        #  non-acceptance states) 
        # (Note, that the prototype's info has not been included yet, consider whole set)
        result.states[new_state_index] = Class_State.new_merged_core_state(SM.states[i] for i in state_set)

    for state_set_idx, state_set in enumerate(Result.state_set_list):
        # The prototype: States in one set behave all equivalent with respect to target state sets
        # thus only one state from the start set has to be considered.      
        prototype    = SM.states[state_set[0]]
        representative = result.states[map_new_state_index[state_set_idx]]

        # The representative must have all transitions that the prototype has
        for target_state_index, trigger_set in prototype.target_map.get_map().iteritems():
            target_state_set_index = Result.map[target_state_index]
            target_index           = map_new_state_index[target_state_set_index]
            representative.add_transition(trigger_set, target_index)

    return result    
開發者ID:dkopecek,項目名稱:amplify,代碼行數:49,代碼來源:hopcroft_minimization.py


注:本文中的quex.engine.state_machine.core.StateMachine.states[new_state_index]方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。