nfa

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Epsilon = epsilon{}

Epsilon is the ε (empty string) input.

Functions

This section is empty.

Types

type State

type State struct {
	// ID of the state.
	// It is assigned by the NFA and should be read-only.
	ID uint32

	// Transitions of the state.
	// Transitions should only be added using NFA.AddTransitions.
	Transitions stablemap.Map[any, *array.Array[*State]]

	// Accept indicates that the state machine should accept/recognize the input.
	// You set this yourself.
	Accept bool

	// NonGreedy, in combination with Accept, indicate that the state machine
	// should accept the current string without consuming additional input.
	NonGreedy bool

	// Data is some user-data associated with this state.
	// Your set this yourself (or don't, I don't care).
	Data any
}

State is a state in a NFA. NFA represents a Nondeterministic Finite Automaton. https://en.wikipedia.org/wiki/Nondeterministic_finite_automaton The NFA is state machine where: - A state is allowed to have multiple transitions for the same input. - The input ε (empty string) is allowed. State should only created using StateFactory.

func (*State) AddTransition

func (s *State) AddTransition(to *State, input any)

AddTransition adds a transition between two states on a given input. The input can be any comparable data, including Epsilon.

func (*State) Print

func (n *State) Print(out io.Writer)

type StateFactory

type StateFactory struct {
	// contains filtered or unexported fields
}

func NewStateFactory

func NewStateFactory() *StateFactory

func (*StateFactory) NewState

func (n *StateFactory) NewState() *State

NewState creates a new state in the NFA.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL