Class: Flexr::Automaton::NFA
- Inherits:
-
Object
- Object
- Flexr::Automaton::NFA
- Defined in:
- lib/flexr/automaton/nfa.rb
Instance Attribute Summary collapse
-
#byte_classes ⇒ Object
readonly
Returns the value of attribute byte_classes.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#states ⇒ Object
readonly
Returns the value of attribute states.
Instance Method Summary collapse
- #epsilon(from, to) ⇒ Object
-
#initialize ⇒ NFA
constructor
A new instance of NFA.
- #new_state ⇒ Object
- #transition(from, lo, hi, to) ⇒ Object
Constructor Details
#initialize ⇒ NFA
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_classes ⇒ Object (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 |
#start ⇒ Object (readonly)
Returns the value of attribute start.
9 10 11 |
# File 'lib/flexr/automaton/nfa.rb', line 9 def start @start end |
#states ⇒ Object (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_state ⇒ Object
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 |