automaton

package
v0.0.0-...-73e23b8 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Automaton

type Automaton struct {
	StartState         int
	AcceptStates       []int
	TransitionFunction map[rune][]int
}

Automaton is a 3-Tuple representing a deterministic finite automaton.

func EncodeAutomaton

func EncodeAutomaton(inStream []byte) (*Automaton, error)

EncodeAutomaton reads a yaml ByteStream definition of an automata and logically encodes it into an Automata interface.

func (*Automaton) Recognize

func (a *Automaton) Recognize(word string) bool

Recognize returns true if the given word is recognized by the language represented by the Automaton.

type IntermediateAutomaton

type IntermediateAutomaton struct {
	States       *int    `yaml:"states"`
	StartState   *State  `yaml:"initial"`
	AcceptStates []State `yaml:"finalstates"`

	Transitions []Transition `yaml:"transitions"`
}

IntermediateAutomaton is a human accessible representation of a finite automaton.

func UnmarshalAutomaton

func UnmarshalAutomaton(in []byte) (*IntermediateAutomaton, error)

UnmarshalAutomaton deserializes the YAML input stream into an automaton object. If an error occurs during deserialization, then returns the error.

type State

type State int

State represents an encoded digit for an automaton.

type Transition

type Transition struct {
	Input     []rune  `yaml:"input"`
	OutStates []State `yaml:"outputs"`
}

Transition represents the set of state transitions a finite automaton can make given a specified input character.

func (*Transition) UnmarshalYAML

func (t *Transition) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML overrides the default YAML unmarshaling logic for the Transition struct allowing it to unmarshal input into a rune slice This method implements the yaml.Unmarshaler (v3) interface.

Jump to

Keyboard shortcuts

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