|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.antlr.tool.NFAFactory
public class NFAFactory
Routines to construct StateClusters from EBNF grammar constructs. No optimization is done to remove unnecessary epsilon edges. TODO: add an optimization that reduces number of states and transitions will help with speed of conversion and make it easier to view NFA. For example, o-A->o-->o-B->o should be o-A->o-B->o
Field Summary | |
---|---|
protected int |
stateCounter
Used to assign state numbers |
Constructor Summary | |
---|---|
NFAFactory(NFA nfa)
|
Method Summary | |
---|---|
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_AlternativeBlock(java.util.List 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(int label)
From label A build Graph o-A->o |
StateCluster |
build_CharLiteralAtom(java.lang.String charLiteral)
From char 'c' build StateCluster o-intValue(c)->o |
StateCluster |
build_CharRange(java.lang.String a,
java.lang.String b)
From char 'c' build StateCluster o-intValue(c)->o can include unicode spec likes '$' later. |
int |
build_EOFStates(java.util.List 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(int ruleIndex,
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)
From set build single edge graph o->o-set->o. |
StateCluster |
build_StringLiteralAtom(java.lang.String stringLiteral)
For a non-lexer, just build a simple token reference atom. |
StateCluster |
build_Wildcard()
Build an atom with all possible values in its label |
protected IntSet |
getCollapsedBlockAsSet(State blk)
Given a collapsed block of alts (a set of atoms), pull out the set and return it. |
int |
getNumberOfStates()
|
NFAState |
newState()
|
void |
optimizeAlternative(StateCluster alt)
Optimize an alternative (list of grammar elements). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int stateCounter
Constructor Detail |
---|
public NFAFactory(NFA nfa)
Method Detail |
---|
public NFAState newState()
public int getNumberOfStates()
public void optimizeAlternative(StateCluster alt)
public StateCluster build_Atom(int label)
public StateCluster build_Set(IntSet set)
public StateCluster build_Range(int a, int b)
public StateCluster build_CharLiteralAtom(java.lang.String charLiteral)
public StateCluster build_CharRange(java.lang.String a, java.lang.String b)
public StateCluster build_StringLiteralAtom(java.lang.String stringLiteral)
public StateCluster build_RuleRef(int ruleIndex, NFAState ruleStart)
public StateCluster build_Epsilon()
public StateCluster build_SemanticPredicate(GrammarAST pred)
public int build_EOFStates(java.util.List rules)
public StateCluster build_AB(StateCluster A, StateCluster B)
public StateCluster build_AlternativeBlockFromSet(StateCluster set)
public StateCluster build_AlternativeBlock(java.util.List alternativeStateClusters)
public StateCluster build_Aoptional(StateCluster A)
public StateCluster build_Aplus(StateCluster A)
public StateCluster build_Astar(StateCluster A)
public StateCluster build_Wildcard()
protected IntSet getCollapsedBlockAsSet(State blk)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |