Top Inners Methods
org.antlr.v4.automata

public Interface ATNFactory

Known Direct Implementers
org.antlr.v4.automata.ParserATNFactory
Imports
org.antlr.v4.runtime.atn.ATN, .ATNState, org.antlr.v4.tool.ast.ActionAST, .BlockAST, .GrammarAST, .PredAST, .TerminalAST, java.util.List

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ATNFactory.Handle

A pair of states pointing to the left/right (start and end) states of a state submachine.

Method Summary

Modifier and TypeMethod and Description
public ATNFactory.Handle
action(ActionAST action)

Build what amounts to an epsilon transition with an action.

public ATNFactory.Handle
action(String action)

public ATNFactory.Handle
public ATNFactory.Handle
block(BlockAST blockAST, GrammarAST ebnfRoot, List<ATNFactory.Handle> alternativeGrips)

From A|B|..|Z alternative block build o->o-A->o->o (last ATNState is blockEndATNState pointed to by all alts) | ^ o->o-B->o--| | | ...

public ATNFactory.Handle
public ATN
public ATNFactory.Handle
epsilon(GrammarAST node)

From an empty alternative build Grip o-e->o

public ATNFactory.Handle
public ATNFactory.Handle
public ATNFactory.Handle
public ATNFactory.Handle
public ATNFactory.Handle
public ATNState
public ATNFactory.Handle
optional(GrammarAST optAST, ATNFactory.Handle blk)

From (A)?

public ATNFactory.Handle
plus(GrammarAST plusAST, ATNFactory.Handle blk)

From (A)+ build |---| (Transition 2 from A.right points at alt 1) v | (follow of loop is Transition 1) o->o-A-o->o Meaning that the last ATNState in A points back to A's left Transition ATNState and we add a new begin/end ATNState.

public ATNFactory.Handle
public ATNFactory.Handle
rule(GrammarAST ruleAST, String name, ATNFactory.Handle blk)

public ATNFactory.Handle
ruleRef(GrammarAST node)

For reference to rule r, build o-e->(r) o where (r) is the start of rule r and the trailing o is not linked to from rule ref state directly (it's done thru the transition(0) RuleClosureTransition.

public ATNFactory.Handle
sempred(PredAST pred)

Build what amounts to an epsilon transition with a semantic predicate action.

public ATNFactory.Handle
set(GrammarAST associatedAST, List<GrammarAST> alts, boolean invert)

public void
public void
public ATNFactory.Handle
star(GrammarAST starAST, ATNFactory.Handle blk)

From (A)* build |---| v | o->o-A-o--o (Transition 2 from block end points at alt 1; follow is Transition 1) | ^ o---------| (optional branch is 2nd alt of optional block containing A+) Meaning that the last (end) ATNState in A points back to A's left side ATNState and we add 3 new ATNStates (the optional branch is built just like an optional subrule).

public ATNFactory.Handle
stringLiteral(TerminalAST stringLiteralAST)

For a non-lexer, just build a simple token reference atom.

public ATNFactory.Handle
public ATNFactory.Handle
wildcard(GrammarAST associatedAST)

Build an atom with all possible values in its label

Method Detail

actionback to summary
public ATNFactory.Handle action(ActionAST action)

Build what amounts to an epsilon transition with an action. The action goes into ATN though it is ignored during analysis.

actionback to summary
public ATNFactory.Handle action(String action)
altback to summary
public ATNFactory.Handle alt(List<ATNFactory.Handle> els)
blockback to summary
public ATNFactory.Handle block(BlockAST blockAST, GrammarAST ebnfRoot, List<ATNFactory.Handle> alternativeGrips)

From A|B|..|Z alternative block build o->o-A->o->o (last ATNState is blockEndATNState pointed to by all alts) | ^ o->o-B->o--| | | ... | | | o->o-Z->o--| So every alternative gets begin ATNState connected by epsilon and every alt right side points at a block end ATNState. There is a new ATNState in the ATNState in the Grip for each alt plus one for the end ATNState. Special case: only one alternative: don't make a block with alt begin/end. Special case: if just a list of tokens/chars/sets, then collapse to a single edge'd o-set->o graph. Set alt number (1..n) in the left-Transition ATNState.

charSetLiteralback to summary
public ATNFactory.Handle charSetLiteral(GrammarAST charSetAST)
createATNback to summary
public ATN createATN()
epsilonback to summary
public ATNFactory.Handle epsilon(GrammarAST node)

From an empty alternative build Grip o-e->o

labelback to summary
public ATNFactory.Handle label(ATNFactory.Handle t)
lexerAltCommandsback to summary
public ATNFactory.Handle lexerAltCommands(ATNFactory.Handle alt, ATNFactory.Handle cmds)
lexerCallCommandback to summary
public ATNFactory.Handle lexerCallCommand(GrammarAST ID, GrammarAST arg)
lexerCommandback to summary
public ATNFactory.Handle lexerCommand(GrammarAST ID)
listLabelback to summary
public ATNFactory.Handle listLabel(ATNFactory.Handle t)
newStateback to summary
public ATNState newState()
optionalback to summary
public ATNFactory.Handle optional(GrammarAST optAST, ATNFactory.Handle blk)

From (A)? build either: o--A->o | ^ o---->| or, if A is a block, just add an empty alt to the end of the block

plusback to summary
public ATNFactory.Handle plus(GrammarAST plusAST, ATNFactory.Handle blk)

From (A)+ build |---| (Transition 2 from A.right points at alt 1) v | (follow of loop is Transition 1) o->o-A-o->o Meaning that the last ATNState in A points back to A's left Transition ATNState and we add a new begin/end ATNState. A can be single alternative or multiple. During analysis we'll call the follow link (transition 1) alt n+1 for an n-alt A block.

rangeback to summary
public ATNFactory.Handle range(GrammarAST a, GrammarAST b)
ruleback to summary
public ATNFactory.Handle rule(GrammarAST ruleAST, String name, ATNFactory.Handle blk)
ruleRefback to summary
public ATNFactory.Handle ruleRef(GrammarAST node)

For reference to rule r, build o-e->(r) o where (r) is the start of rule r and the trailing o is not linked to from rule ref state directly (it's done thru the transition(0) RuleClosureTransition. If the rule r is just a list of tokens, it's block will be just a set on an edge o->o->o-set->o->o->o, could inline it rather than doing the rule reference, but i'm not doing this yet as I'm not sure it would help much in the ATN->DFA construction. TODO add to codegen: collapse alt blks that are sets into single matchSet

sempredback to summary
public ATNFactory.Handle sempred(PredAST pred)

Build what amounts to an epsilon transition with a semantic predicate action. The pred is a pointer into the AST of the SEMPRED token.

setback to summary
public ATNFactory.Handle set(GrammarAST associatedAST, List<GrammarAST> alts, boolean invert)
setCurrentOuterAltback to summary
public void setCurrentOuterAlt(int alt)
setCurrentRuleNameback to summary
public void setCurrentRuleName(String name)
starback to summary
public ATNFactory.Handle star(GrammarAST starAST, ATNFactory.Handle blk)

From (A)* build |---| v | o->o-A-o--o (Transition 2 from block end points at alt 1; follow is Transition 1) | ^ o---------| (optional branch is 2nd alt of optional block containing A+) Meaning that the last (end) ATNState in A points back to A's left side ATNState and we add 3 new ATNStates (the optional branch is built just like an optional subrule). See the Aplus() method for more on the loop back Transition. The new node on right edge is set to RIGHT_EDGE_OF_CLOSURE so we can detect nested (A*)* loops and insert an extra node. Previously, two blocks shared same EOB node. There are 2 or 3 decision points in a A*. If A is not a block (i.e., it only has one alt), then there are two decisions: the optional bypass and then loopback. If A is a block of alts, then there are three decisions: bypass, loopback, and A's decision point. Note that the optional bypass must be outside the loop as (A|B)* is not the same thing as (A|B|)+. This is an accurate ATN representation of the meaning of (A)*, but for generating code, I don't need a DFA for the optional branch by virtue of how I generate code. The exit-loopback-branch decision is sufficient to let me make an appropriate enter, exit, loop determination. See codegen.g

stringLiteralback to summary
public ATNFactory.Handle stringLiteral(TerminalAST stringLiteralAST)

For a non-lexer, just build a simple token reference atom. For a lexer, a string is a sequence of char to match. That is, "fog" is treated as 'f' 'o' 'g' not as a single transition in the DFA. Machine== o-'f'->o-'o'->o-'g'->o and has n+1 states for n characters.

tokenRefback to summary
public ATNFactory.Handle tokenRef(TerminalAST node)
wildcardback to summary
public ATNFactory.Handle wildcard(GrammarAST associatedAST)

Build an atom with all possible values in its label

org.antlr.v4.automata back to summary

public Class ATNFactory.Handle

extends Object
Class Inheritance

A pair of states pointing to the left/right (start and end) states of a state submachine. Used to build ATNs.

Field Summary

Modifier and TypeField and Description
public ATNState
public ATNState

Constructor Summary

AccessConstructor and Description
public
Handle(ATNState left, ATNState right)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

leftback to summary
public ATNState left
rightback to summary
public ATNState right

Constructor Detail

Handleback to summary
public Handle(ATNState left, ATNState right)

Method Detail

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