C# Class Antlr4.Runtime.Dfa.DFAState

A DFA state represents a set of possible ATN configurations.
A DFA state represents a set of possible ATN configurations. As Aho, Sethi, Ullman p. 117 says "The DFA uses its state to keep track of all possible states the ATN can be in after reading each input symbol. That is to say, after reading input a1a2..an, the DFA is in a state that represents the subset T of the states of the ATN that are reachable from the ATN's start state along some path labeled a1a2..an." In conventional NFA→DFA conversion, therefore, the subset T would be a bitset representing the set of states the ATN could be in. We need to track the alt predicted by each state as well, however. More importantly, we need to maintain a stack of states, tracking the closure operations as they jump from rule to rule, emulating rule invocations (method calls). I have to add a stack to simulate the proper lookahead sequences for the underlying LL grammar from which the ATN was derived.

I use a set of ATNConfig objects not simple states. An ATNConfig is both a state (ala normal conversion) and a RuleContext describing the chain of rules (if any) followed to arrive at that state.

A DFA state may have multiple references to a particular state, but with different ATN contexts (with same or different alts) meaning that state was reached via a different set of rule invocations.

Show file Open project: sharwell/antlr4cs Class Usage Examples

Public Properties

Property Type Description
stateNumber int

Public Methods

Method Description
DFAState ( DFA dfa, ATNConfigSet configs ) : System
DFAState ( EmptyEdgeMap emptyEdges, EmptyEdgeMap emptyContextEdges, ATNConfigSet configs ) : System
Equals ( object o ) : bool

Two DFAState instances are equal if their ATN configuration sets are the same. This method is used to see if a state already exists.

Because the number of alternatives and number of ATN configurations are finite, there is a finite number of DFA states that can be processed. This is necessary to show that the algorithm terminates.

Cannot test the DFA state numbers here because in Antlr4.Runtime.Atn.ParserATNSimulator.AddDFAState(DFA, Antlr4.Runtime.Atn.ATNConfigSet, Antlr4.Runtime.Atn.PredictionContextCache) we need to know if any other state exists that has this exact set of ATN configurations. The stateNumber is irrelevant.

GetContextTarget ( int invokingState ) : DFAState
GetHashCode ( ) : int
GetTarget ( int symbol ) : DFAState
IsContextSymbol ( int symbol ) : bool
SetContextSensitive ( ATN atn ) : void
SetContextSymbol ( int symbol ) : void
SetContextTarget ( int invokingState, DFAState target ) : void
SetTarget ( int symbol, DFAState target ) : void
ToString ( ) : string

Method Details

DFAState() public method

public DFAState ( DFA dfa, ATNConfigSet configs ) : System
dfa DFA
configs ATNConfigSet
return System

DFAState() public method

public DFAState ( EmptyEdgeMap emptyEdges, EmptyEdgeMap emptyContextEdges, ATNConfigSet configs ) : System
emptyEdges EmptyEdgeMap
emptyContextEdges EmptyEdgeMap
configs ATNConfigSet
return System

Equals() public method

Two DFAState instances are equal if their ATN configuration sets are the same. This method is used to see if a state already exists.

Because the number of alternatives and number of ATN configurations are finite, there is a finite number of DFA states that can be processed. This is necessary to show that the algorithm terminates.

Cannot test the DFA state numbers here because in Antlr4.Runtime.Atn.ParserATNSimulator.AddDFAState(DFA, Antlr4.Runtime.Atn.ATNConfigSet, Antlr4.Runtime.Atn.PredictionContextCache) we need to know if any other state exists that has this exact set of ATN configurations. The stateNumber is irrelevant.

public Equals ( object o ) : bool
o object
return bool

GetContextTarget() public method

public GetContextTarget ( int invokingState ) : DFAState
invokingState int
return DFAState

GetHashCode() public method

public GetHashCode ( ) : int
return int

GetTarget() public method

public GetTarget ( int symbol ) : DFAState
symbol int
return DFAState

IsContextSymbol() public method

public IsContextSymbol ( int symbol ) : bool
symbol int
return bool

SetContextSensitive() public method

public SetContextSensitive ( ATN atn ) : void
atn Antlr4.Runtime.Atn.ATN
return void

SetContextSymbol() public method

public SetContextSymbol ( int symbol ) : void
symbol int
return void

SetContextTarget() public method

public SetContextTarget ( int invokingState, DFAState target ) : void
invokingState int
target DFAState
return void

SetTarget() public method

public SetTarget ( int symbol, DFAState target ) : void
symbol int
target DFAState
return void

ToString() public method

public ToString ( ) : string
return string

Property Details

stateNumber public property

public int stateNumber
return int