fstdfa.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:symautomata 作者: GeorgeArgyros 项目源码 文件源码
def consume_input(self, inp):
        """
        Return True/False if the machine accepts/reject the input.
        Args:
            inp (str): input string to be consumed
        Returns:
            bool: A true or false value depending on if the DFA
                accepts the provided input
        """
        cur_state = sorted(
            self.states,
            key=attrgetter('initial'),
            reverse=True)[0]
        while len(inp) > 0:
            found = False
            for arc in cur_state.arcs:
                if self.isyms.find(arc.ilabel) == inp[0]:
                    cur_state = self[arc.nextstate]
                    inp = inp[1:]
                    found = True
                    break
            if not found:
                return False
        return cur_state.final != TropicalWeight(float('inf'))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号