当前位置: 首页>>代码示例>>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;未经允许,请勿转载。