lib/automata/pda.rb
def transition(state, symbol, stackTop=nil)
      dests = []

      if has_transition?(state, symbol)
        actions = @transitions[state][symbol]
        stackTop ||= @stack.last
        able = true
        @stack.push actions['push'] if actions['push']
        if actions['pop']
          able = false unless stackTop == actions['pop']
          @stack.pop if able
        end
        if able
          dests << actions['to']

          if has_transition?(actions['to'], '&')
            actions = @transitions[actions['to']]['&']
            able = true
            @stack.push actions['push'] if actions['push']
            if actions['pop']
              able = false unless @stack.last == actions['pop']
              @stack.pop if able
            end
            if able
              dests << actions['to']
            end
          end
          dests
        else
          return dests
        end
      else
        return []
      end
    end
def transition(state, symbol, stackTop=nil)
      dests = []

      if has_transition?(state, symbol)
        actions = @transitions[state][symbol]
        stackTop ||= @stack.last
        able = true
        @stack.push actions['push'] if actions['push']
        if actions['pop']
          able = false unless stackTop == actions['pop']
          @stack.pop if able
        end
        if able
          dests << actions['to']

          if has_transition?(actions['to'], '&')
            actions = @transitions[actions['to']]['&']
            able = true
            @stack.push actions['push'] if actions['push']
            if actions['pop']
              able = false unless @stack.last == actions['pop']
              @stack.pop if able
            end
            if able
              dests << actions['to']
            end
          end
          dests
        else
          return dests
        end
      else
        return []
      end
    end
Determines the transition states, if any, from a given
 beginning state and input symbol pair.

 @param [String] state state label for beginning state.
 @param [String] symbol input symbol.
 @return [Array] Array of destination transition states.