public class NFAFactory extends Object
Constructor and Description |
---|
NFAFactory(NFA nfa) |
Modifier and Type | Method and Description |
---|---|
StateCluster |
build_AB(StateCluster A,
StateCluster B)
From A B build A-e->B (that is, build an epsilon arc from right
of A to left of B).
|
StateCluster |
build_Action(GrammarAST action)
Build what amounts to an epsilon transition with an action.
|
StateCluster |
build_AlternativeBlock(List<StateCluster> alternativeStateClusters)
From A|B|..|Z alternative block build
o->o-A->o->o (last NFAState is blockEndNFAState pointed to by all alts)
| ^
o->o-B->o--|
| |
...
|
StateCluster |
build_AlternativeBlockFromSet(StateCluster set)
From a set ('a'|'b') build
o->o-'a'..'b'->o->o (last NFAState is blockEndNFAState pointed to by all alts)
|
StateCluster |
build_Aoptional(StateCluster A)
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
|
StateCluster |
build_Aplus(StateCluster A)
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 NFAState in A points back to A's left Transition NFAState
and we add a new begin/end NFAState.
|
StateCluster |
build_Astar(StateCluster A)
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) NFAState in A points back to A's
left side NFAState and we add 3 new NFAStates (the
optional branch is built just like an optional subrule).
|
StateCluster |
build_Atom(GrammarAST atomAST) |
StateCluster |
build_Atom(int label,
GrammarAST associatedAST)
From label A build Graph o-A->o
|
StateCluster |
build_CharLiteralAtom(GrammarAST charLiteralAST)
From char 'c' build StateCluster o-intValue(c)->o
|
StateCluster |
build_CharRange(String a,
String b)
From char 'c' build StateCluster o-intValue(c)->o
can include unicode spec likes '$' later.
|
int |
build_EOFStates(Collection<Rule> rules)
add an EOF transition to any rule end NFAState that points to nothing
(i.e., for all those rules not invoked by another rule).
|
StateCluster |
build_Epsilon()
From an empty alternative build StateCluster o-e->o
|
StateCluster |
build_Range(int a,
int b)
Can only complement block of simple alts; can complement build_Set()
result, that is.
|
StateCluster |
build_RuleRef(Rule refDef,
NFAState ruleStart)
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.
|
StateCluster |
build_SemanticPredicate(GrammarAST pred)
Build what amounts to an epsilon transition with a semantic
predicate action.
|
StateCluster |
build_Set(IntSet set,
GrammarAST associatedAST)
From set build single edge graph o->o-set->o.
|
StateCluster |
build_StringLiteralAtom(GrammarAST stringLiteralAST)
For a non-lexer, just build a simple token reference atom.
|
StateCluster |
build_Wildcard(GrammarAST associatedAST)
Build an atom with all possible values in its label
|
StateCluster |
build_WildcardTree(GrammarAST associatedAST)
Build a subrule matching ^(.
|
protected IntSet |
getCollapsedBlockAsSet(State blk)
Given a collapsed block of alts (a set of atoms), pull out
the set and return it.
|
Rule |
getCurrentRule() |
NFAState |
newState() |
void |
optimizeAlternative(StateCluster alt)
Optimize an alternative (list of grammar elements).
|
void |
setCurrentRule(Rule currentRule) |
public NFAFactory(NFA nfa)
public Rule getCurrentRule()
public void setCurrentRule(Rule currentRule)
public NFAState newState()
public void optimizeAlternative(StateCluster alt)
public StateCluster build_Atom(int label, GrammarAST associatedAST)
public StateCluster build_Atom(GrammarAST atomAST)
public StateCluster build_Set(IntSet set, GrammarAST associatedAST)
public StateCluster build_Range(int a, int b)
public StateCluster build_CharLiteralAtom(GrammarAST charLiteralAST)
public StateCluster build_CharRange(String a, String b)
public StateCluster build_StringLiteralAtom(GrammarAST stringLiteralAST)
public StateCluster build_RuleRef(Rule refDef, NFAState ruleStart)
public StateCluster build_Epsilon()
public StateCluster build_SemanticPredicate(GrammarAST pred)
public StateCluster build_Action(GrammarAST action)
public int build_EOFStates(Collection<Rule> rules)
public StateCluster build_AB(StateCluster A, StateCluster B)
public StateCluster build_AlternativeBlockFromSet(StateCluster set)
public StateCluster build_AlternativeBlock(List<StateCluster> alternativeStateClusters)
public StateCluster build_Aoptional(StateCluster A)
public StateCluster build_Aplus(StateCluster A)
public StateCluster build_Astar(StateCluster A)
public StateCluster build_Wildcard(GrammarAST associatedAST)
public StateCluster build_WildcardTree(GrammarAST associatedAST)
Copyright © 1992–2015 ANTLR. All rights reserved.