예제 #1
0
파일: dpda.py 프로젝트: xrick/automata
 def _check_for_input_rejection(self, current_state, stack):
     """Raise an error if the given config indicates rejected input."""
     # If current state is not a final state and stack is not empty
     if current_state not in self.final_states and stack:
         raise exceptions.RejectionError(
             'the DPDA stopped in a non-accepting configuration '
             '({}, {})'.format(current_state, ''.join(stack)))
예제 #2
0
파일: dtm.py 프로젝트: xrick/automata
 def _get_transition(self, state, tape_symbol):
     """Get the transiton tuple for the given state and tape symbol."""
     if (state in self.transitions
             and tape_symbol in self.transitions[state]):
         return self.transitions[state][tape_symbol]
     else:
         raise exceptions.RejectionError(
             'The machine entered a non-final configuration for which no '
             'transition is defined ({}, {})'.format(state, tape_symbol))
예제 #3
0
파일: dfa.py 프로젝트: xrick/automata
    def _get_next_current_state(self, current_state, input_symbol):
        """
        Follow the transition for the given input symbol on the current state.

        Raise an error if the transition does not exist.
        """
        if input_symbol in self.transitions[current_state]:
            return self.transitions[current_state][input_symbol]
        else:
            raise exceptions.RejectionError(
                '{} is not a valid input symbol'.format(input_symbol))
예제 #4
0
파일: dpda.py 프로젝트: xrick/automata
 def _get_transition(self, state, input_symbol, stack_symbol):
     """Get the transiton tuple for the given state and symbols."""
     if (state in self.transitions
             and input_symbol in self.transitions[state]
             and stack_symbol in self.transitions[state][input_symbol]):
         return self.transitions[state][input_symbol][stack_symbol]
     else:
         raise exceptions.RejectionError(
             'The automaton entered a configuration for which no '
             'transition is defined ({}, {}, {})'.format(
                 state, input_symbol, stack_symbol))
예제 #5
0
파일: dfa.py 프로젝트: xrick/automata
 def _check_for_input_rejection(self, current_state):
     """Raise an error if the given config indicates rejected input."""
     if current_state not in self.final_states:
         raise exceptions.RejectionError(
             'the DFA stopped on a non-final state ({})'.format(
                 current_state))
예제 #6
0
 def _check_for_input_rejection(self, current_states):
     """Raise an error if the given config indicates rejected input."""
     if not (current_states & self.final_states):
         raise exceptions.RejectionError(
             'the NFA stopped on all non-final states ({})'.format(
                 ', '.join(current_states)))