class Kleene::NFA

Defined in:

nfa.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(start_state : Kleene::State, alphabet : Set(Char) = DEFAULT_ALPHABET, transitions : Hash(Kleene::State, Hash(Char, Set(Kleene::NFATransition))) = Hash(State, Hash(Char, Set(NFATransition))).new, initial_states = nil) #

[View source]

Instance Method Detail

def accept? #

[View source]
def add_state(new_state) #

[View source]
def add_states(states) #

[View source]
def add_transition(token : Char, from_state, to_state) #

[View source]
def all_transitions : Array(NFATransition) #

[View source]
def alphabet : Set(Char) #

[View source]
def alphabet=(alphabet : Set(Char)) #

[View source]
def current_states : Set(State) #

[View source]
def current_states=(current_states : Set(State)) #

[View source]
def deep_clone #

[View source]
def epsilon_closure(state_set : Set(State)) : Set(State) #

[View source]
def epsilon_closure(state : State) : Set(State) #

Determine the epsilon closure of the given state set That is, determine what states are reachable on an epsilon transition from the current state set (@current_states). Returns a Set of State objects.


[View source]
def error_states #

[View source]
def final_states : Set(State) #

[View source]
def final_states=(final_states : Set(State)) #

[View source]
def graphviz #

[View source]
def handle_token!(input_token : Char) #

process another input token


[View source]
def match?(input : String) : MatchRef | Nil #

[View source]
def matches(input) #

Returns an array of matches found anywhere in the input string


[View source]
def matches_at_offset(input, input_start_offset) #

Returns an array of matches found in the input string, each of which begins at the offset input_start_offset


[View source]
def next_states(state_set, input_token) #

[View source]
def reachable_states(start_state) #

Returns a set of State objects which are reachable through any transition path from the NFA's start_state.


[View source]
def regex_pattern #

[View source]
def remove_state(state) #

[View source]
def reset_current_states #

[View source]
def set_regex_pattern(pattern : Nil | String) #

[View source]
def start_state : State #

[View source]
def start_state=(start_state : State) #

[View source]
def states : Set(State) #

[View source]
def states=(states : Set(State)) #

[View source]
def to_dfa #

This implements the subset construction algorithm presented on page 118 of the first edition of the dragon book. I found a similar explanation at: http://web.cecs.pdx.edu/~harry/compilers/slides/LexicalPart3.pdf


[View source]
def to_s(verbose = false) #
Description copied from class Object

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.


[View source]
def transitions : Hash(State, Hash(Char, Set(NFATransition))) #

[View source]
def transitions=(transitions : Hash(State, Hash(Char, Set(NFATransition)))) #

[View source]
def transitions_from(state_set : Set(State)) : Set(NFATransition) #

[View source]
def transitions_from(state : State) : Set(NFATransition) #

[View source]
def update_final_states #

[View source]