Table of Contents

Class Dfa<TChar>

Namespace
Farkle.Grammars.StateMachines
Assembly
Farkle.dll

Represents a deterministic finite automaton (DFA) stored in a Grammar. It is used by tokenizers to break the input stream into a series of tokens.

public abstract class Dfa<TChar> : IReadOnlyList<DfaState<TChar>>, IReadOnlyCollection<DfaState<TChar>>, IEnumerable<DfaState<TChar>>, IEnumerable

Type Parameters

TChar

The type of characters the DFA accepts. Typically it is char or byte.

Inheritance
Dfa<TChar>
Implements

Remarks

A DFA is a state machine, with each state containing edges that point to other states based on the current character in the input stream. States can also have an accept symbol, meaning that the tokenizer has at that point encountered an instance of a specific token symbol.

Properties

Count

The number of states in the Dfa<TChar>.

public int Count { get; }

Property Value

int

HasConflicts

Whether there might be at least one state in the Dfa<TChar> with more than one possible accept symbol.

public bool HasConflicts { get; }

Property Value

bool

Remarks

Parsers can use this property to quickly determine if the DFA is usable for parsing.

Note that on some pathological grammar files it is possible for a DFA to not have conflicts and this property to have a value of true, but a value of false guarantees that it doesn't have conflicts. Farkle does not treat such DFAs as suitable for parsing.

InitialState

The number of the Dfa<TChar>'s initial state.

public int InitialState { get; }

Property Value

int

this[int]

Gets the DfaState<TChar> of the Dfa<TChar> with the specified index.

public DfaState<TChar> this[int index] { get; }

Parameters

index int

The state's index, starting from zero.

Property Value

DfaState<TChar>

Exceptions

ArgumentOutOfRangeException

index is less than zero or greater than or equal to Count.

Methods

GetEnumerator()

Gets the enumerator of the Dfa<TChar>'s states.

public Dfa<TChar>.Enumerator GetEnumerator()

Returns

Dfa<TChar>.Enumerator