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


Python StateMachine.mount_cloned_subsequent_states方法代码示例

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


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

示例1: WalkAlong

# 需要导入模块: from quex.engine.state_machine.core import StateMachine [as 别名]
# 或者: from quex.engine.state_machine.core.StateMachine import mount_cloned_subsequent_states [as 别名]
class WalkAlong(TreeWalker):
    def __init__(self, SM_A, SM_B, result=None):
        self.original    = SM_A
        self.admissible  = SM_B

        if result is None:
            init_state_index = index.map_state_combination_to_index((SM_A.init_state_index, 
                                                                     SM_B.init_state_index))
            state            = self.get_state_core(SM_A.init_state_index)
            self.result      = StateMachine(InitStateIndex = init_state_index,
                                            InitState      = state)
        else:
            self.result      = result
        self.path        = []

        # Use 'operation_index' to get a unique index that allows to indicate
        # that 'SM_B' is no longer involved. Also, it ensures that the
        # generated state indices from (a_state_index, operation_index) are
        # unique.
        self.operation_index = index.get()

        TreeWalker.__init__(self)

    def on_enter(self, Args):
        a_state_index, b_state_index, trigger_set = Args
        assert b_state_index != self.operation_index

        if self.is_on_path(Args): 
            return None

        self.path.append((a_state_index, b_state_index, trigger_set))


        a_tm = self.original.states[a_state_index].target_map.get_map()
        if self.original.states[a_state_index].is_acceptance():
            # SM_A has reached a terminal
            if self.admissible.states[b_state_index].is_acceptance():
                # SM_B cuts the path until the terminal. 
                pass
            else:
                self.integrate_path_in_result()

        if len(a_tm) == 0:
            return None # No further path to walk along

        b_tm = self.admissible.states[b_state_index].target_map.get_map()
        #print "#loop:START", a_tm
        sub_node_list = []
        for a_ti, a_trigger_set in a_tm.iteritems():
            remainder = a_trigger_set.clone()
            #print "#a_trigger_set: %s" % a_trigger_set.get_utf8_string()
            for b_ti, b_trigger_set in b_tm.iteritems():
                intersection = a_trigger_set.intersection(b_trigger_set)
                if intersection.is_empty(): 
                    continue

                #print "#intersection:", intersection.get_utf8_string()
                sub_node_list.append((a_ti, b_ti, intersection))
                remainder.subtract(intersection)

            #print "#remainder: '%s'" % remainder.get_utf8_string()
            if not remainder.is_empty():
                #print "#B"
                # SM_B is not involved --> b_ti = self.operation_index
                self.path.append((a_ti, self.operation_index, remainder))
                #print "#result0:", self.result.get_string(NormalizeF=False)
                self.integrate_path_in_result()
                self.path.pop()
                #print "#result1:", self.result.get_string(NormalizeF=False)
                self.result.mount_cloned_subsequent_states(self.original, a_ti, self.operation_index)
                #print "#result2:", self.result.get_string(NormalizeF=False)
        #print "#loop:END", sub_node_list

        return sub_node_list

    def on_finished(self, Node):
        self.path.pop()

    def is_on_path(self, Args):
        a_state_index, b_state_index, dummy = Args
        for ai, bi, dummy in self.path:
            if ai == a_state_index and bi == b_state_index:
                return True
        return False

    def integrate_path_in_result(self):
        #print "#integrate_path_in_result:"
        #for i, x in enumerate(self.path):
        #    try:    #print "# [%i] %s, %s, %s" % (i, x[0], x[1], x[2].get_string(Option="utf8"))
        #    except: #print "# [%i] %s" % (i, x)

        for k, info in r_enumerate(self.path):
            dummy, bi, dummy = info
            if bi != self.operation_index and self.admissible.states[bi].is_acceptance():
                first_remainder_k = k + 1 # (ai, bi) is cut; next state is good
                break
        else:
            first_remainder_k = 1

        if first_remainder_k == len(self.path):
#.........这里部分代码省略.........
开发者ID:mplucinski,项目名称:quex,代码行数:103,代码来源:cut_begin.py

示例2: WalkAlong

# 需要导入模块: from quex.engine.state_machine.core import StateMachine [as 别名]
# 或者: from quex.engine.state_machine.core.StateMachine import mount_cloned_subsequent_states [as 别名]
class WalkAlong(TreeWalker):
    def __init__(self, SM_A, SM_B, StartingSM=None):
        self.original   = SM_A
        self.admissible = SM_B

        if StartingSM is None:
            self.result = StateMachine(InitStateIndex = index.map_state_combination_to_index((SM_A.init_state_index, 
                                                                                              SM_B.init_state_index)), 
                                       InitState      = self.get_state_core(SM_A.init_state_index, 
                                                                            SM_B.init_state_index))
        else:
            self.result = StartingSM

        # TODO: Think if 'state_db' cannot be replaced by 'result'
        self.state_db   = {}

        self.path       = []

        # Use 'operation_index' to get a unique index that allows to indicate
        # that 'SM_B' is no longer involved. Also, it ensures that the
        # generated state indices from (a_state_index, operation_index) are
        # unique.
        self.operation_index = index.get()

        TreeWalker.__init__(self)

    def on_enter(self, Args):
        if Args in self.path: 
            return None

        a_state_index, b_state_index = Args
        self.path.append((a_state_index, b_state_index))

        state = self.get_state(Args)

        sub_node_list = []

        a_tm = self.original.states[a_state_index].target_map.get_map()
        assert b_state_index != self.operation_index

        b_tm = self.admissible.states[b_state_index].target_map.get_map()
        for a_ti, a_trigger_set in a_tm.iteritems():
            remainder = a_trigger_set.clone()
            for b_ti, b_trigger_set in b_tm.iteritems():
                # If an acceptance state in 'B' is reached, than the lexeme starts
                # with something in 'LB'. Thus, rest of paths is inadmissible.
                if self.admissible.states[b_ti].is_acceptance(): 
                    remainder.subtract(b_trigger_set)
                    continue                                     

                intersection = a_trigger_set.intersection(b_trigger_set)
                if intersection.is_empty(): 
                    continue

                combi = (a_ti, b_ti)
                state.add_transition(intersection, index.map_state_combination_to_index(combi))
                sub_node_list.append(combi)

                remainder.subtract(intersection)

            if not remainder.is_empty():
                combi = (a_ti, self.operation_index)
                state.add_transition(remainder, index.map_state_combination_to_index(combi))
                self.result.mount_cloned_subsequent_states(self.original, a_ti, self.operation_index)

        ## print "#1-sub_node_list:", sub_node_list
        return sub_node_list

    def on_finished(self, Node):
        self.path.pop()

    def get_state_core(self, AStateIndex, BStateIndex):
        acceptance_f = self.original.states[AStateIndex].is_acceptance() 
        return State(AcceptanceF=acceptance_f)

    def get_state(self, Args):
        state_index = index.map_state_combination_to_index(Args)
        state       = self.state_db.get(state_index)
        if state is None:
            a_state_index, b_state_index = Args
            state = self.get_state_core(a_state_index, b_state_index)
            self.result.states[state_index] = state
        return state
开发者ID:dkopecek,项目名称:amplify,代码行数:85,代码来源:complement_begin.py


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