Java Doc for NFAFactory.java in  » Parser » antlr-3.0.1 » org » antlr » tool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Parser » antlr 3.0.1 » org.antlr.tool 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.antlr.tool.NFAFactory

NFAFactory
public class NFAFactory (Code)
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
 StringcurrentRuleName
    
 NFAnfa
     This factory is attached to a specifc NFA that it is building.
protected  intstateCounter
    

Constructor Summary
public  NFAFactory(NFA nfa)
    

Method Summary
public  StateClusterbuild_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).
public  StateClusterbuild_AlternativeBlock(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--| | | ...
public  StateClusterbuild_AlternativeBlockFromSet(StateCluster set)
    
public  StateClusterbuild_Aoptional(StateCluster A)
    
public  StateClusterbuild_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.
public  StateClusterbuild_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). 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.
public  StateClusterbuild_Atom(int label)
    
public  StateClusterbuild_CharLiteralAtom(String charLiteral)
    
public  StateClusterbuild_CharRange(String a, String b)
     From char 'c' build StateCluster o-intValue(c)->o can include unicode spec likes '\u0024' later.
public  intbuild_EOFStates(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).
public  StateClusterbuild_Epsilon()
    
public  StateClusterbuild_Range(int a, int b)
     Can only complement block of simple alts; can complement build_Set() result, that is.
public  StateClusterbuild_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.
public  StateClusterbuild_SemanticPredicate(GrammarAST pred)
     Build what amounts to an epsilon transition with a semantic predicate action.
public  StateClusterbuild_Set(IntSet set)
     From set build single edge graph o->o-set->o.
public  StateClusterbuild_StringLiteralAtom(String stringLiteral)
     For a non-lexer, just build a simple token reference atom. For a lexer, a string is a sequence of char to match.
public  StateClusterbuild_Wildcard()
    
protected  IntSetgetCollapsedBlockAsSet(State blk)
     Given a collapsed block of alts (a set of atoms), pull out the set and return it.
public  intgetNumberOfStates()
    
public  NFAStatenewState()
    
public  voidoptimizeAlternative(StateCluster alt)
     Optimize an alternative (list of grammar elements). Walk the chain of elements (which can be complicated loop blocks...) and throw away any epsilon transitions used to link up simple elements. This only removes 195 states from the java.g's NFA, but every little bit helps.

Field Detail
currentRuleName
String currentRuleName(Code)



nfa
NFA nfa(Code)
This factory is attached to a specifc NFA that it is building. The NFA will be filled up with states and transitions.



stateCounter
protected int stateCounter(Code)
Used to assign state numbers




Constructor Detail
NFAFactory
public NFAFactory(NFA nfa)(Code)




Method Detail
build_AB
public StateCluster build_AB(StateCluster A, StateCluster B)(Code)
From A B build A-e->B (that is, build an epsilon arc from right of A to left of B). As a convenience, return B if A is null or return A if B is null.



build_AlternativeBlock
public StateCluster build_AlternativeBlock(List alternativeStateClusters)(Code)
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--| | | ... | | | o->o-Z->o--| So every alternative gets begin NFAState connected by epsilon and every alt right side points at a block end NFAState. There is a new NFAState in the NFAState in the StateCluster for each alt plus one for the end NFAState. 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 NFAState.



build_AlternativeBlockFromSet
public StateCluster build_AlternativeBlockFromSet(StateCluster set)(Code)
From a set ('a'|'b') build o->o-'a'..'b'->o->o (last NFAState is blockEndNFAState pointed to by all alts)



build_Aoptional
public StateCluster build_Aoptional(StateCluster A)(Code)
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



build_Aplus
public StateCluster build_Aplus(StateCluster A)(Code)
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. 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.



build_Astar
public StateCluster build_Astar(StateCluster A)(Code)
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). 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 NFA 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



build_Atom
public StateCluster build_Atom(int label)(Code)
From label A build Graph o-A->o



build_CharLiteralAtom
public StateCluster build_CharLiteralAtom(String charLiteral)(Code)
From char 'c' build StateCluster o-intValue(c)->o



build_CharRange
public StateCluster build_CharRange(String a, String b)(Code)
From char 'c' build StateCluster o-intValue(c)->o can include unicode spec likes '\u0024' later. Accepts actual unicode 16-bit now, of course, by default. TODO not supplemental char clean!



build_EOFStates
public int build_EOFStates(List rules)(Code)
add an EOF transition to any rule end NFAState that points to nothing (i.e., for all those rules not invoked by another rule). These are start symbols then. Return the number of grammar entry points; i.e., how many rules are not invoked by another rule (they can only be invoked from outside). These are the start rules.



build_Epsilon
public StateCluster build_Epsilon()(Code)
From an empty alternative build StateCluster o-e->o



build_Range
public StateCluster build_Range(int a, int b)(Code)
Can only complement block of simple alts; can complement build_Set() result, that is. Get set and complement, replace old with complement. public StateCluster build_AlternativeBlockComplement(StateCluster blk) { State s0 = blk.left; IntSet set = getCollapsedBlockAsSet(s0); if ( set!=null ) { // if set is available, then structure known and blk is a set set = nfa.grammar.complement(set); Label label = s0.transition(0).target.transition(0).label; label.setSet(set); } return blk; }



build_RuleRef
public StateCluster build_RuleRef(int ruleIndex, NFAState ruleStart)(Code)
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 NFA->DFA construction. TODO add to codegen: collapse alt blks that are sets into single matchSet



build_SemanticPredicate
public StateCluster build_SemanticPredicate(GrammarAST pred)(Code)
Build what amounts to an epsilon transition with a semantic predicate action. The pred is a pointer into the AST of the SEMPRED token.



build_Set
public StateCluster build_Set(IntSet set)(Code)
From set build single edge graph o->o-set->o. To conform to what an alt block looks like, must have extra state on left.



build_StringLiteralAtom
public StateCluster build_StringLiteralAtom(String stringLiteral)(Code)
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.



build_Wildcard
public StateCluster build_Wildcard()(Code)
Build an atom with all possible values in its label



getCollapsedBlockAsSet
protected IntSet getCollapsedBlockAsSet(State blk)(Code)
Given a collapsed block of alts (a set of atoms), pull out the set and return it.



getNumberOfStates
public int getNumberOfStates()(Code)



newState
public NFAState newState()(Code)



optimizeAlternative
public void optimizeAlternative(StateCluster alt)(Code)
Optimize an alternative (list of grammar elements). Walk the chain of elements (which can be complicated loop blocks...) and throw away any epsilon transitions used to link up simple elements. This only removes 195 states from the java.g's NFA, but every little bit helps. Perhaps I can improve in the future.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.