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
- Inheritance
-
Dfa<TChar>
- Implements
-
IReadOnlyList<DfaState<TChar>>IReadOnlyCollection<DfaState<TChar>>IEnumerable<DfaState<TChar>>
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
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
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.
this[int]
Gets the DfaState<TChar> of the Dfa<TChar> with the specified index.
public DfaState<TChar> this[int index] { get; }
Parameters
indexintThe state's index, starting from zero.
Property Value
- DfaState<TChar>
Exceptions
- ArgumentOutOfRangeException
indexis less than zero or greater than or equal to Count.
StartState
The number of the Dfa<TChar>'s start state.
public int StartState { get; }
Property Value
Methods
GetEnumerator()
Gets the enumerator of the Dfa<TChar>'s states.
public Dfa<TChar>.Enumerator GetEnumerator()
Returns
- Dfa<TChar>.Enumerator
GetStartStateForGroup(GroupHandle)
Gets the index of the state of the Dfa<TChar> to start from, when tokenizing the given group.
public int GetStartStateForGroup(GroupHandle group)
Parameters
groupGroupHandleThe group's handle.
Returns
Remarks
If group points to a group that does not exist in the grammar, this method will
not fail, but return StartState.