Class: Flexr::Automaton::NFA

Inherits:
Object
  • Object
show all
Defined in:
lib/flexr/automaton/nfa.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNFA

Returns a new instance of NFA.



11
12
13
14
15
# File 'lib/flexr/automaton/nfa.rb', line 11

def initialize
  @states = []
  @start = new_state
  @byte_classes = ByteClassSet.new
end

Instance Attribute Details

#byte_classesObject (readonly)

Returns the value of attribute byte_classes.



9
10
11
# File 'lib/flexr/automaton/nfa.rb', line 9

def byte_classes
  @byte_classes
end

#startObject (readonly)

Returns the value of attribute start.



9
10
11
# File 'lib/flexr/automaton/nfa.rb', line 9

def start
  @start
end

#statesObject (readonly)

Returns the value of attribute states.



9
10
11
# File 'lib/flexr/automaton/nfa.rb', line 9

def states
  @states
end

Instance Method Details

#epsilon(from, to) ⇒ Object



23
24
25
# File 'lib/flexr/automaton/nfa.rb', line 23

def epsilon(from, to)
  @states[from].epsilon << to
end

#new_stateObject



17
18
19
20
21
# File 'lib/flexr/automaton/nfa.rb', line 17

def new_state
  id = @states.length
  @states << NFAState.new(epsilon: [], transitions: [], accepts: [])
  id
end

#transition(from, lo, hi, to) ⇒ Object



27
28
29
30
# File 'lib/flexr/automaton/nfa.rb', line 27

def transition(from, lo, hi, to)
  @states[from].transitions << NFATransition.new(lo: lo, hi: hi, to: to)
  @byte_classes.add_range(lo, hi)
end