Top Description Fields Constructors Methods
org.antlr.analysis

public Class NFAState

extends State
Class Inheritance
Imports
org.antlr.tool.ErrorManager, .GrammarAST, .Rule

A state within an NFA. At most 2 transitions emanate from any NFA state.

Field Summary

Modifier and TypeField and Description
public GrammarAST
associatedASTNode

Associate this NFAState with the corresponding GrammarAST node from which this node was created.

public static final int
public static final int
protected int
decisionNumber

What's its decision number from 1..n?

public int
decisionStateType

Subrules (...)* and (...)+ have more than one decision point in the NFA created for them.

protected String
description

During debugging and for nondeterminism warnings, it's useful to know what relationship this node has to the original grammar.

public Rule
enclosingRule

What rule do we live in?

public int
endOfBlockStateNumber

Jean Bovet needs in the GUI to know which state pairs correspond to the start/stop of a block.

protected boolean
EOTTargetState

Is this state the sole target of an EOT transition?

public Label
incidentEdgeLabel

For o-A->o type NFA tranitions, record the label that leads to this state.

public static final int
public static final int
public NFA
nfa

Which NFA are we in?

pack-priv int
numTransitions

How many transitions; 0, 1, or 2 transitions

public static final int
public static final int
public Transition[]
Inherited from org.antlr.analysis.State:
acceptStateINVALID_STATE_NUMBERstateNumber

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public int
public String
public int
public boolean
public boolean
public void
setDecisionASTNode(GrammarAST decisionASTNode)

What AST node is associated with this NFAState?

public void
setDecisionNumber(int decisionNumber)

public void
setDescription(String description)

public void
setEOTTargetState(boolean eot)

public void
setTransition0(Transition e)

Used during optimization to reset a state to have the (single) transition another state has.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public Transition
public int
translateDisplayAltToWalkAlt(int displayAlt)

The DFA decision for this NFA decision state always has an exit path for loops as n+1 for n alts in the loop.

Inherited from org.antlr.analysis.State:
isAcceptStatesetAcceptState

Field Detail

associatedASTNodeback to summary
public GrammarAST associatedASTNode

Associate this NFAState with the corresponding GrammarAST node from which this node was created. This is useful not only for associating the eventual lookahead DFA with the associated Grammar position, but also for providing users with nondeterminism warnings. Mainly used by decision states to report line:col info. Could also be used to track line:col for elements such as token refs.

BLOCK_STARTback to summary
public static final int BLOCK_START
BYPASSback to summary
public static final int BYPASS
decisionNumberback to summary
protected int decisionNumber

What's its decision number from 1..n?

decisionStateTypeback to summary
public int decisionStateType

Subrules (...)* and (...)+ have more than one decision point in the NFA created for them. They both have a loop-exit-or-stay-in decision node (the loop back node). They both have a normal alternative block decision node at the left edge. The (...)* is worse as it even has a bypass decision (2 alts: stay in or bypass) node at the extreme left edge. This is not how they get generated in code as a while-loop or whatever deals nicely with either. For error messages (where I need to print the nondeterministic alts) and for interpretation, I need to use the single DFA that is created (for efficiency) but interpret the results differently depending on which of the 2 or 3 decision states uses the DFA. For example, the DFA will always report alt n+1 as the exit branch for n real alts, so I need to translate that depending on the decision state. If decisionNumber>0 then this var tells you what kind of decision state it is.

descriptionback to summary
protected String description

During debugging and for nondeterminism warnings, it's useful to know what relationship this node has to the original grammar. For example, "start of alt 1 of rule a".

enclosingRuleback to summary
public Rule enclosingRule

What rule do we live in?

endOfBlockStateNumberback to summary
public int endOfBlockStateNumber

Jean Bovet needs in the GUI to know which state pairs correspond to the start/stop of a block.

EOTTargetStateback to summary
protected boolean EOTTargetState

Is this state the sole target of an EOT transition?

incidentEdgeLabelback to summary
public Label incidentEdgeLabel

For o-A->o type NFA tranitions, record the label that leads to this state. Useful for creating rich error messages when we find insufficiently (with preds) covered states.

LOOPBACKback to summary
public static final int LOOPBACK
MAX_TRANSITIONSback to summary
public static final int MAX_TRANSITIONS
nfaback to summary
public NFA nfa

Which NFA are we in?

numTransitionsback to summary
pack-priv int numTransitions

How many transitions; 0, 1, or 2 transitions

OPTIONAL_BLOCK_STARTback to summary
public static final int OPTIONAL_BLOCK_START
RIGHT_EDGE_OF_BLOCKback to summary
public static final int RIGHT_EDGE_OF_BLOCK
transitionback to summary
public Transition[] transition

Constructor Detail

NFAStateback to summary
public NFAState(NFA nfa)

Method Detail

addTransitionback to summary
public void addTransition(Transition e)

Implements abstract org.antlr.analysis.State.addTransition.

Annotations
@Override
getDecisionNumberback to summary
public int getDecisionNumber()
getDescriptionback to summary
public String getDescription()
getNumberOfTransitionsback to summary
public int getNumberOfTransitions()

Implements abstract org.antlr.analysis.State.getNumberOfTransitions.

Annotations
@Override
isDecisionStateback to summary
public boolean isDecisionState()
isEOTTargetStateback to summary
public boolean isEOTTargetState()
setDecisionASTNodeback to summary
public void setDecisionASTNode(GrammarAST decisionASTNode)

What AST node is associated with this NFAState? When you set the AST node, I set the node to point back to this NFA state.

setDecisionNumberback to summary
public void setDecisionNumber(int decisionNumber)
setDescriptionback to summary
public void setDescription(String description)
setEOTTargetStateback to summary
public void setEOTTargetState(boolean eot)
setTransition0back to summary
public void setTransition0(Transition e)

Used during optimization to reset a state to have the (single) transition another state has.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

Annotations
@Override
transitionback to summary
public Transition transition(int i)

Implements abstract org.antlr.analysis.State.transition.

Annotations
@Override
translateDisplayAltToWalkAltback to summary
public int translateDisplayAltToWalkAlt(int displayAlt)

The DFA decision for this NFA decision state always has an exit path for loops as n+1 for n alts in the loop. That is really useful for displaying nondeterministic alts and so on, but for walking the NFA to get a sequence of edge labels or for actually parsing, we need to get the real alt number. The real alt number for exiting a loop is always 1 as transition 0 points at the exit branch (we compute DFAs always for loops at the loopback state). For walking/parsing the loopback state: 1 2 3 display alt (for human consumption) 2 3 1 walk alt For walking the block start: 1 2 3 display alt 1 2 3 For walking the bypass state of a (...)* loop: 1 2 3 display alt 1 1 2 all block alts map to entering loop exit means take bypass Non loop EBNF do not need to be translated; they are ignored by this method as decisionStateType==0. Return same alt if we can't translate.