Java Doc for Analyzer.java in  » Parser » Rats-Parser-Generators » xtc » parser » 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 » Rats Parser Generators » xtc.parser 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   xtc.tree.Utility
      xtc.parser.Analyzer

Analyzer
public class Analyzer extends Utility (Code)
Utility for analyzing and modifying grammars. This class provides the following functionality: To utilize this analyzer utility for a given grammar, the utility must be Analyzer.init initialized(Grammar) with the grammar, and each production must be Analyzer.process processed with the utility. Furthermore, new productions must be added through Analyzer.add(Production) and obsolete productions must be removed through Analyzer.remove(Production) .

The analyzer utility tracks the current grammar so that it need not recreate its internal state (notably, the mapping from nonterminals to productions) as long as the same analyzer utility is used across different visitors.
author:
   Robert Grimm
version:
   $Revision: 1.2 $



Field Summary
final public static  StringCHOICE
     The suffix for nonterminals representing choices.
final public static  intMAX_COUNT
     The maximum character count for turning character classes into character switches.
final public static  StringOPTION
     The suffix for nonterminals representing options.
final public static  StringPLUS
     The suffix for nonterminals representing one or more repetitions.
final public static  StringSEPARATOR
     The separator character for creating new nonterminals, which should be illegal in regular variable or nonterminal names.
final public static  StringSHARED
     The base name for nonterminals representing shared productions.
final public static  StringSTAR
     The suffix for nonterminals representing zero or more repetitions.
final public static  StringVARIABLE
     The base name for temporary variables.
protected  intchoiceCount
     The count of lifted choices for the current production.
protected  Grammargrammar
     The current grammar.
protected  intoptionCount
     The count of desugared options for the current production.
protected  ProductionpCurrent
     The current production.
protected  MappMap
     The map from nonterminals to productions.
protected  SetpMarked
     The set of nonterminals corresponding to productions having been marked.
protected  ListpNew
     The list of newly added productions.
protected  SetpProcessed
     The set of nonterminals corresponding to productions having been processed.
protected  SetpTop
     The set of top-level nonterminals.
protected  SetpWorking
     The set of nonterminals corresponding to productions currently being processed.
protected  intplusCount
     The count of desugared plus repetitions for the current production.
protected  intsharedCount
     The count of shared productions.
protected  intstarCount
     The count of desugared star repetitions for the current production.
protected  intvarCount
     The count of temporary variables for the current production.
final protected  Copierxerox
     The element copier.

Constructor Summary
public  Analyzer()
     Create a new analyzer utility.

Method Summary
public  voidadd(Production p)
     Prepare the specified production for addition to the grammar. This method adds the specified production to the list of newly generated productions.
public  intaddNewProductionsAt(int idx)
     Add the newly generated productions to the grammar itself.
public  Bindingbind(Sequence s)
     Bind the elements in the specified sequence.
public  NonTerminalchoice()
     Create a new nonterminal for a choice.
public  Elementcopy(Element e)
     Make a deep copy of the specified element.
Parameters:
  e - The element.
public  Productioncurrent()
     Get the production currently being processed.
public  booleanhasTerminalPrefix(Sequence s)
     Determine whether the specified sequence starts with terminals that can be optimized.
public  voidinit(Grammar g)
     Initialize this analyzer for the specified grammar.
public  booleanisBeingWorkedOn(NonTerminal nt)
     Determine whether the specified nonterminal is being worked on.
Parameters:
  nt - The nonterminal.
public  booleanisDefined(NonTerminal nt)
     Determine whether the specified nonterminal is defined.
public  booleanisMarked(NonTerminal nt)
     Determine whether the specified nonterminal has been marked.
Parameters:
  nt - The nonterminal.
public  booleanisProcessed(NonTerminal nt)
     Determine whether the specified nonterminal has been processed.
Parameters:
  nt - The nonterminal.
public  booleanisTopLevel(NonTerminal nt)
     Determine whether the specified nonterminal is top-level.
Parameters:
  nt - The nonterminal.
public  Elementjoin(Sequence source, Element target)
     Join the specified sequence with the specified element.
public  Productionlookup(NonTerminal nt)
     Look up the production for the specified nonterminal.
Parameters:
  nt - The nonterminal.
public  voidmark(NonTerminal nt)
     Mark the specified nonterminal.
public  Setmarked()
     Get the set of marked nonterminals.
public  booleanmatchesEmpty(Element e)
     Determine whether the specified element matches the empty input. Note that this method assumes that nonterminals do not match the empty input.
Parameters:
  e - The element.
public  StringmatchingText(Element e)
     Get the text matched by the specified element.
public  Sequencenormalize(Sequence s)
     Normalize the specified sequence for Analyzer.join(Sequence,Element) joining with other elements during terminal optimization.
public  voidnotWorkingOn(NonTerminal nt)
     Set the status of the specified nonterminal as not being worked on.
public  NonTerminaloption()
     Create a new nonterminal for an option.
public  NonTerminalplus()
     Create a new nonterminal for one or more repetitions.
public  voidprocess(Production p)
     Process the specified production.
public  voidprocessed(NonTerminal nt)
     Set the status of the specified nonterminal as processed.
public  voidremove(Production p)
     Prepare the specified production for removal from the grammar. This method removes the specified production from the mapping from nonterminals to productions and, if present, from the set of top-level nonterminals.
public  voidreset()
     Forcibly reset the analyzer utility.
public  NonTerminalshared()
     Create a new nonterminal for a shared production.
public  NonTerminalstar()
     Create a new nonterminal for zero or more repetitions.
public  voidstartAdding()
     Clear the list of newly generated productions.
public  Elementstrip(Element e)
     Strip unnecessary ordered choices and sequences from the specified element.
public  voidunmark(NonTerminal nt)
     Unmark the specified nonterminal.
public  Stringvariable()
     Create a new temporary variable.
public  Setworking()
     Get the set of nonterminals being worked on.
public  voidworkingOn(NonTerminal nt)
     Set the status of the specified nonterminal as being worked on.

Field Detail
CHOICE
final public static String CHOICE(Code)
The suffix for nonterminals representing choices.



MAX_COUNT
final public static int MAX_COUNT(Code)
The maximum character count for turning character classes into character switches.



OPTION
final public static String OPTION(Code)
The suffix for nonterminals representing options.



PLUS
final public static String PLUS(Code)
The suffix for nonterminals representing one or more repetitions.



SEPARATOR
final public static String SEPARATOR(Code)
The separator character for creating new nonterminals, which should be illegal in regular variable or nonterminal names.



SHARED
final public static String SHARED(Code)
The base name for nonterminals representing shared productions.



STAR
final public static String STAR(Code)
The suffix for nonterminals representing zero or more repetitions.



VARIABLE
final public static String VARIABLE(Code)
The base name for temporary variables.



choiceCount
protected int choiceCount(Code)
The count of lifted choices for the current production.



grammar
protected Grammar grammar(Code)
The current grammar.



optionCount
protected int optionCount(Code)
The count of desugared options for the current production.



pCurrent
protected Production pCurrent(Code)
The current production.



pMap
protected Map pMap(Code)
The map from nonterminals to productions.



pMarked
protected Set pMarked(Code)
The set of nonterminals corresponding to productions having been marked.



pNew
protected List pNew(Code)
The list of newly added productions.



pProcessed
protected Set pProcessed(Code)
The set of nonterminals corresponding to productions having been processed.



pTop
protected Set pTop(Code)
The set of top-level nonterminals.



pWorking
protected Set pWorking(Code)
The set of nonterminals corresponding to productions currently being processed.



plusCount
protected int plusCount(Code)
The count of desugared plus repetitions for the current production.



sharedCount
protected int sharedCount(Code)
The count of shared productions.



starCount
protected int starCount(Code)
The count of desugared star repetitions for the current production.



varCount
protected int varCount(Code)
The count of temporary variables for the current production.



xerox
final protected Copier xerox(Code)
The element copier.




Constructor Detail
Analyzer
public Analyzer()(Code)
Create a new analyzer utility.




Method Detail
add
public void add(Production p)(Code)
Prepare the specified production for addition to the grammar. This method adds the specified production to the list of newly generated productions. It also adds the production to the map from nonterminals to productions and marks it as Constants.SYNTHETIC synthetic . However, addition is not complete: the productions in the list of newly generated productions still need to be added into the grammar itself. This is typically done within the main loop iterating over a grammar's productions and thus through a separate Analyzer.addNewProductionsAt(int) method .
Parameters:
  p - The new production.



addNewProductionsAt
public int addNewProductionsAt(int idx)(Code)
Add the newly generated productions to the grammar itself. This method adds the productions collected through Analyzer.add(Production) add() into the current grammar at the specified index of the grammar's list of productions.
Parameters:
  idx - The index into the grammar's list of productions. The number of productions added.



bind
public Binding bind(Sequence s)(Code)
Bind the elements in the specified sequence. This method analyzes the specified sequence and, if necessary, adds in a binding for the semantic value of the elements in the sequence. If the sequence has more than one element to be bound, this method returns null to indicate that we need to rely on the CodeGenerator.VALUE semantic value to capture the sequence's value.
Parameters:
  s - The sequence to bind. The corresponding binding.



choice
public NonTerminal choice()(Code)
Create a new nonterminal for a choice. The new nonterminal.



copy
public Element copy(Element e)(Code)
Make a deep copy of the specified element.
Parameters:
  e - The element. A deep copy.



current
public Production current()(Code)
Get the production currently being processed. The current production.



hasTerminalPrefix
public boolean hasTerminalPrefix(Sequence s)(Code)
Determine whether the specified sequence starts with terminals that can be optimized. This method returns true if the terminals can be optimized through character switches. Currently, this is only the case for character and string literals.
Parameters:
  s - The sequence. true if the sequence starts with optimizableterminals.



init
public void init(Grammar g)(Code)
Initialize this analyzer for the specified grammar. This method initializes the map from nonterminals to productions and the set of top-level nonterminals. It also clears the sets of marked and processed nonterminals. It should be called before iterating over a grammar's productions.
Parameters:
  g - The grammar.



isBeingWorkedOn
public boolean isBeingWorkedOn(NonTerminal nt)(Code)
Determine whether the specified nonterminal is being worked on.
Parameters:
  nt - The nonterminal. true if the nonterminal is being workedon.



isDefined
public boolean isDefined(NonTerminal nt)(Code)
Determine whether the specified nonterminal is defined. A nonterminal is defined if the current grammar contains a production for that nonterminal.
Parameters:
  nt - The nonterminal. true if the nonterminal is defined.



isMarked
public boolean isMarked(NonTerminal nt)(Code)
Determine whether the specified nonterminal has been marked.
Parameters:
  nt - The nonterminal. true if the nonterminal has beenmarked.



isProcessed
public boolean isProcessed(NonTerminal nt)(Code)
Determine whether the specified nonterminal has been processed.
Parameters:
  nt - The nonterminal. true if the nonterminal has been processed.



isTopLevel
public boolean isTopLevel(NonTerminal nt)(Code)
Determine whether the specified nonterminal is top-level.
Parameters:
  nt - The nonterminal. true if the nonterminal is top-level.



join
public Element join(Sequence source, Element target)(Code)
Join the specified sequence with the specified element. Note that the specified sequence must have been Analyzer.normalize(Sequence) normalized . Further note that the combined element is guaranteed to either be a sequence or an ordered choice.
Parameters:
  source - The source sequence.
Parameters:
  target - The target element. The combined element.



lookup
public Production lookup(NonTerminal nt)(Code)
Look up the production for the specified nonterminal.
Parameters:
  nt - The nonterminal. The corresponding production or nullif there is no such production.



mark
public void mark(NonTerminal nt)(Code)
Mark the specified nonterminal.
Parameters:
  nt - The nonterminal.



marked
public Set marked()(Code)
Get the set of marked nonterminals. Note that the called must copy the set if it keeps the reference to the returned set after the next use of this analyzer. The marked set.



matchesEmpty
public boolean matchesEmpty(Element e)(Code)
Determine whether the specified element matches the empty input. Note that this method assumes that nonterminals do not match the empty input.
Parameters:
  e - The element. true if the specified element matches theempty input.



matchingText
public String matchingText(Element e)(Code)
Get the text matched by the specified element. This method analyzes the specified element, and, if the element always matches the same text, this method returns the constant text. Otherwise, this method returns null. Note that this method ignores predicates, actions, and value elements, as they do not change the text matched by an element. Further note that this method recursively analyzes referenced nonterminals.
Parameters:
  e - The element. The constant text.



normalize
public Sequence normalize(Sequence s)(Code)
Normalize the specified sequence for Analyzer.join(Sequence,Element) joining with other elements during terminal optimization. Currently, this method converts string literals into equivalent subsequences of character literals.
Parameters:
  s - The sequence. The optimized sequence.



notWorkingOn
public void notWorkingOn(NonTerminal nt)(Code)
Set the status of the specified nonterminal as not being worked on.
Parameters:
  nt - The nonterminal.



option
public NonTerminal option()(Code)
Create a new nonterminal for an option. The new nonterminal.



plus
public NonTerminal plus()(Code)
Create a new nonterminal for one or more repetitions. The new nonterminal.



process
public void process(Production p)(Code)
Process the specified production. This method clears the set of working nonterminals. It also resets the counters for creating new variables and nonterminals (besides the counter for shared productions). It then invokes this analyzer's visitor on the specified production. This method should be called within the loop iterating over a grammar's productions, but not at other locations within a visitor.
Parameters:
  p - The production.



processed
public void processed(NonTerminal nt)(Code)
Set the status of the specified nonterminal as processed.
Parameters:
  nt - The nonterminal.



remove
public void remove(Production p)(Code)
Prepare the specified production for removal from the grammar. This method removes the specified production from the mapping from nonterminals to productions and, if present, from the set of top-level nonterminals. However, removal is not complete: the production still needs to be removed from the grammar itself. This is typically done within the main loop iterating over a grammar's productions.
Parameters:
  p - The production.



reset
public void reset()(Code)
Forcibly reset the analyzer utility.



shared
public NonTerminal shared()(Code)
Create a new nonterminal for a shared production. The new nonterminal.



star
public NonTerminal star()(Code)
Create a new nonterminal for zero or more repetitions. The new nonterminal.



startAdding
public void startAdding()(Code)
Clear the list of newly generated productions. This method needs to be called before a processing step that may add new productions through Analyzer.add(Production) and Analyzer.addNewProductionsAt(int) .



strip
public Element strip(Element e)(Code)
Strip unnecessary ordered choices and sequences from the specified element. A choice or sequence is unnecessary if it contains only a single element.
Parameters:
  e - The element. The stripped element.



unmark
public void unmark(NonTerminal nt)(Code)
Unmark the specified nonterminal.
Parameters:
  nt - The nonterminal.



variable
public String variable()(Code)
Create a new temporary variable. The name of the temporary variable.



working
public Set working()(Code)
Get the set of nonterminals being worked on. Note that the caller must copy the set if it keeps the reference to the returned set after the next call to Analyzer.process . The working set.



workingOn
public void workingOn(NonTerminal nt)(Code)
Set the status of the specified nonterminal as being worked on.
Parameters:
  nt - The nonterminal.



Methods inherited from xtc.tree.Utility
public void register(Visitor visitor)(Code)(Java Doc)
public Visitor visitor()(Code)(Java Doc)

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.