当前位置: 首页>>代码示例>>Python>>正文


Python StateMachine.mount_to_initial_state方法代码示例

本文整理汇总了Python中quex.engine.state_machine.core.StateMachine.mount_to_initial_state方法的典型用法代码示例。如果您正苦于以下问题:Python StateMachine.mount_to_initial_state方法的具体用法?Python StateMachine.mount_to_initial_state怎么用?Python StateMachine.mount_to_initial_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在quex.engine.state_machine.core.StateMachine的用法示例。


在下文中一共展示了StateMachine.mount_to_initial_state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: do

# 需要导入模块: from quex.engine.state_machine.core import StateMachine [as 别名]
# 或者: from quex.engine.state_machine.core.StateMachine import mount_to_initial_state [as 别名]
def do(StateMachineList, CommonTerminalStateF=True, CloneF=True):
    """Connect state machines paralell.

       CommonTerminalStateF tells whether the state machines shall trigger 
                            to a common terminal. This may help nfa-to-dfa
                            or hopcroft minimization for ISOLATED patterns.

                            A state machine that consists of the COMBINATION
                            of patterns MUST set this flag to 'False'.

       CloneF               Controls if state machine list is cloned or not.
                            If the single state machines are no longer required after
                            construction, the CloneF can be set to False.

                            If Cloning is disabled the state machines themselves
                            will be altered--which brings some advantage in speed.
    """
    assert type(StateMachineList) == list
    assert len(StateMachineList) != 0
    for x in StateMachineList:
        assert isinstance(x, StateMachine), x.__class__.__name__
              
    # filter out empty state machines from the consideration          
    state_machine_list       = [ sm for sm in StateMachineList if not (sm.is_empty() or special.is_none(sm))]
    empty_state_machine_list = [ sm for sm in StateMachineList if     (sm.is_empty() or special.is_none(sm))]

    if len(state_machine_list) < 2:
        if len(state_machine_list) < 1: result = StateMachine()
        elif CloneF:                    result = state_machine_list[0].clone()
        else:                           result = state_machine_list[0]

        return __consider_empty_state_machines(result, empty_state_machine_list)

    # (*) need to clone the state machines, i.e. provide their internal
    #     states with new ids, but the 'behavior' remains. This allows
    #     state machines to appear twice, or being used in 'larger'
    #     conglomerates.
    if CloneF: clone_list = map(lambda sm: sm.clone(), state_machine_list)
    else:      clone_list = state_machine_list

    # (*) collect all transitions from both state machines into a single one
    #     (clone to ensure unique identifiers of states)
    new_init_state = State.new_merged_core_state((clone.get_init_state() for clone in clone_list), 
                                                 ClearF=True)
    result         = StateMachine(InitState=new_init_state)

    for clone in clone_list:
        result.states.update(clone.states)

    # (*) add additional **init** and **end** state
    #     NOTE: when the result state machine was created, it already contains a 
    #           new initial state index. thus at this point only the new terminal
    #           state has to be created. 
    #     NOTE: it is essential that the acceptance flag stays False, at this
    #           point in time, so that the mounting operations only happen on
    #           the old acceptance states. Later the acceptance state is raised
    #           to 'accepted' (see below)
    new_terminal_state_index = -1L
    if CommonTerminalStateF:
        new_terminal_state_index = index.get()
        result.states[new_terminal_state_index] = \
                    State.new_merged_core_state(result.get_acceptance_state_list(), \
                                                ClearF=True)
    
    # (*) Connect from the new initial state to the initial states of the
    #     clones via epsilon transition. 
    #     Connect from each success state of the clones to the new end state
    #     via epsilon transition.
    for clone in clone_list:
        result.mount_to_initial_state(clone.init_state_index)

    if CommonTerminalStateF:
        result.mount_to_acceptance_states(new_terminal_state_index,
                                          CancelStartAcceptanceStateF=False)

    return __consider_empty_state_machines(result, empty_state_machine_list)
开发者ID:dkopecek,项目名称:amplify,代码行数:78,代码来源:parallelize.py


注:本文中的quex.engine.state_machine.core.StateMachine.mount_to_initial_state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。