Class: Resyma::Core::Regexp

Inherits:
Object
  • Object
show all
Defined in:
lib/resyma/core/automaton/regexp.rb

Instance Method Summary collapse

Instance Method Details

#inject(ab, start_state) ⇒ Resyma::Core::State

Converts self to automaton, which is implemented by subclasses. Note that only add states and transitions by the automaton builder, do not modify starting state and accept set

Parameters:

Returns:

  • (Resyma::Core::State)

    Ending state, every implements should end their automaton with a single acceptable state

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/resyma/core/automaton/regexp.rb', line 18

def inject(ab, start_state)
  raise NotImplementedError
end

#to_automaton(eliminate_epsilon = true) ⇒ Resyma::Core::Automaton

Convert the regexp to a DFA

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/resyma/core/automaton/regexp.rb', line 27

def to_automaton(eliminate_epsilon = true)
  ab = AutomatonBuilder.new
  start = ab.new_state!
  ab.start! start
  accept = inject ab, start
  ab.accept! accept
  result = ab.build
  if eliminate_epsilon
    result.to_DFA
  else
    result
  end
end