Java Doc for CodeGenerator.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.Visitor
      xtc.parser.CodeGenerator

CodeGenerator
public class CodeGenerator extends Visitor (Code)
The code generator.

The code generator makes the following assumptions about the intermediate language:

  • Each Production production must have an OrderedChoice ordered choice as its element.

  • Each {link Production production} must have been annotated with the appropriate MetaData meta-data .

  • Each option of an OrderedChoice ordered choice must be a Sequence sequence .

  • Generally, all Option options , Repetitionrepetitions , and nested OrderedChoice ordered choices must have been desugared into equivalent productions. However, an ordered choice may appear as the last element of a sequence (that is not part of a predicate), and a repetition may appear if the repeated expressions need not be memoized.

  • The element of a Repetition repetition must be a Sequence sequence (with the last element possibly being an ordered choice; see previous assumption).

  • The FollowedBy.element and NotFollowedBy.element fields must reference a sequence.

  • All elements in a CharSwitch character switch must either be ordered choices or sequences. Furthermore, character switches may only appear as the last element in a sequence and not within predicates.


author:
   Robert Grimm
version:
   $Revision: 1.1 $


Field Summary
final public static  StringATT_CONSTANT_BINDING
     The Attribute attribute name for making variable bindings constant: constantBinding.
final public static  StringATT_DEBUG
     The Attribute attribute name for printing debugging information while parsing.
final public static  StringATT_LOCATION
     The Attribute attribute name for annotating instances of Node with their location information: location.
final public static  StringATT_NO_MATCHING_ERRORS
     The Attribute attribute name for not generating specific parse errors when a string literal or string match fails: noMatchingErrors.
final public static  StringCHAR
     The name for the character variable.
final public static  intCHUNK_SIZE
     The size of chunks.
final public static  StringCOLUMN
     The name for the column number variable.
final public static  StringFILE
     The name for the file name variable.
final public static  StringLINE
     The name for the line number variable.
final public static  StringMATCHED
     The name for the predicate matched variable.
final public static  StringNESTED_CHOICE
     The prefix for the parser variable for nested choices.
final public static  StringPARSER
     The name for the parser variable.
final public static  StringPARSE_CHAR
     The name for the character parsing method.
final public static  StringPARSE_ERROR
     The name for the parse error variable.
final public static  StringPRED_RESULT
     The name for the predicate result variable.
final public static  StringPREFIX
     The general prefix for internal parser fields and variables.
final public static  StringPREFIX_FIELD
     The prefix for field names that memoize the parsers results.
final public static  StringPREFIX_METHOD
     The prefix for parsing method names.
final public static  StringREPEATED
     The prefix for the flag indicating that a repetition has been matched at least once.
final public static  StringREPETITION
     The prefix for the parser variable for repetitions.
final public static  StringRESULT
     The name for the regular result variable.
final public static  StringVALUE
     The name for the value variable.
protected  intalignment
     The number of spaces to align variable declarations to.
final protected  Analyzeranalyzer
     The analyzer utility.
protected  booleanattributeConstantBinding
     The flag for making variable bindings constant.
protected  booleanattributeDebug
     The flag for generating debugging code.
protected  booleanattributeLocation
     The flag for generating code to annotate nodes with location information.
protected  booleanattributeNoMatchingErrors
     The flag for not generating matching errors.
protected  StringbaseParser
     The expression for the base parser.
protected  ElementbindingElement
     The element being bound.
protected  StringbindingName
     The name of the current binding.
protected  StringcName
     The class name for the current grammar.
protected  intchoiceLevel
     The nesting level for nested choices.
protected  intchunkCount
     The number of chunks.
protected  MapchunkMap
     The map from nonterminals to chunk numbers.
protected  booleanchunked
     Flag for whether the memoization fields are organized in chunks.
protected  IteratorelementIter
     The iterator over the elements of a sequence.
protected  booleanendsWithParseError
     Flag for whether the current choice ends with a parse error.
protected  booleanfirstElement
     The flag for the first element in a top-level choice.
protected  booleannotFollowedBy
     Flag for whether the current predicate is a not-followed-by predicate.
protected  booleanpredicate
     Flag for whether we are currently emitting a predicate.
protected  IteratorpredicateIter
     The predicate iterator.
final protected  Printerprinter
     The printer utility.
protected  booleanrepeatOnce
     The flag for at-least-once repetitions.
protected  intrepetitionLevel
     The nesting level for repetitions.
protected  StringresultName
     The name of the result variable.
protected  StringsavedBaseParser
     The saved base parser.
protected  booleansavedFirstElement
     The saved first element.
protected  intsavedRepetitionLevel
     The saved repetition level (for predicates).
protected  booleansavedUseBaseParser
     The saved flag for using the base parser.
protected  booleanseenTest
     Flag for whether a test has been emitted.
protected  booleanuseBaseParser
     The flag for using the base parser.

Constructor Summary
public  CodeGenerator(Analyzer analyzer, Printer printer)
     Create a new code generator.

Method Summary
protected  voidaction(Action a)
     Actually emit code for the specified action.
protected  voidalignment(boolean includeParser)
     Determine the variable alignment for parse method declarations.
protected  voidbinding()
     Actually emit the code for the last visited binding.
protected  voidclearBinding()
     Clear binding information after usage.
public  StringfieldName(NonTerminal nt)
     Generate the field name for the specified nonterminal.
Parameters:
  nt - The nonterminal.
protected  booleanhasBinding()
     Determine whether the current element has a binding.
public  StringmethodName(NonTerminal nt)
     Generate the method name for the specified nonterminal.
Parameters:
  nt - The nonterminal.
protected  StringnestedChoice()
     Return the name of the parser variable for the current nested choice level.
protected  voidnextElement()
     Emit the code for the next element.
protected  booleannotFollowedBy()
     Determine whether we are processing a not-followed-by predicate.
protected  voidparseError()
     Emit the code for generating a parse error.
protected  voidparseError(String text)
     Emit the code for generating a parse error.
protected  voidresult(String methodName, boolean saveParser)
     Emit the code for assigning the result variable, threading the parse error, and for testing the result.
protected  voidreturnValue()
     Emit the code for returning a semantic value.
protected  voidtested()
     Note that a test has been emitted.
protected  voidvalueTest()
     Emit the code testing whether the result has a value.
protected  voidvalueTest(String text)
     Emit the code for testing the result.
public  voidvisit(Grammar g)
     Generate code for the specified grammar.
public  voidvisit(Production p)
     Generate code for the specified production.
public  voidvisit(OrderedChoice c)
     Generate code for the specified ordered choice.
public  voidvisit(Repetition r)
     Generate code for the specified repetition.
public  voidvisit(FollowedBy p)
     Generate code for the specified followed-by predicate.
public  voidvisit(NotFollowedBy p)
     Generate code for the specified not-followed-by predicate.
public  voidvisit(SemanticPredicate p)
     Generate code for the specified semantic predicate.
public  voidvisit(Binding b)
     Generate code for the specified binding.
public  voidvisit(StringMatch m)
     Generate code for the specified string match.
public  voidvisit(NonTerminal nt)
     Generate code for the specified nonterminal.
public  voidvisit(AnyChar a)
     Generate code for the any character element.
public  voidvisit(CharLiteral l)
     Generate code for the specified character literal.
public  voidvisit(CharClass c)
     Generate code for the specified character class.
public  voidvisit(StringLiteral l)
     Generate code for the specified literal.
public  voidvisit(CharSwitch s)
     Generate code for the specified character switch.
public  voidvisit(Action a)
     Generate code for the specified action.
public  voidvisit(NullValue v)
     Generate code for the specified null value.
public  voidvisit(StringValue v)
     Generate code for the specified string value.
public  voidvisit(TextValue v)
     Generate code for the specified text value.
public  voidvisit(EmptyListValue v)
     Generate code for the specified empty list value.
public  voidvisit(SingletonListValue v)
     Generate code for the specified singleton list value.
public  voidvisit(ListValue v)
     Generate code for the specified list value.

Field Detail
ATT_CONSTANT_BINDING
final public static String ATT_CONSTANT_BINDING(Code)
The Attribute attribute name for making variable bindings constant: constantBinding. For grammars with this attribute, the code generator declares all variable bindings to be constant (in the case of Java, final).



ATT_DEBUG
final public static String ATT_DEBUG(Code)
The Attribute attribute name for printing debugging information while parsing. For grammars with this attribute, the code generator emits code that prints debugging information to the console while parsing.



ATT_LOCATION
final public static String ATT_LOCATION(Code)
The Attribute attribute name for annotating instances of Node with their location information: location. For grammars with this attribute, the code generator emits code that automatically annotates all nodes with their grammar Location location information .



ATT_NO_MATCHING_ERRORS
final public static String ATT_NO_MATCHING_ERRORS(Code)
The Attribute attribute name for not generating specific parse errors when a string literal or string match fails: noMatchingErrors. For grammars with this attribute, parse errrors are only generated at the granularity of an entire production (pointing to the beginning of the production).



CHAR
final public static String CHAR(Code)
The name for the character variable.



CHUNK_SIZE
final public static int CHUNK_SIZE(Code)
The size of chunks.



COLUMN
final public static String COLUMN(Code)
The name for the column number variable.



FILE
final public static String FILE(Code)
The name for the file name variable.



LINE
final public static String LINE(Code)
The name for the line number variable.



MATCHED
final public static String MATCHED(Code)
The name for the predicate matched variable.



NESTED_CHOICE
final public static String NESTED_CHOICE(Code)
The prefix for the parser variable for nested choices.



PARSER
final public static String PARSER(Code)
The name for the parser variable.



PARSE_CHAR
final public static String PARSE_CHAR(Code)
The name for the character parsing method.



PARSE_ERROR
final public static String PARSE_ERROR(Code)
The name for the parse error variable.



PRED_RESULT
final public static String PRED_RESULT(Code)
The name for the predicate result variable.



PREFIX
final public static String PREFIX(Code)
The general prefix for internal parser fields and variables.



PREFIX_FIELD
final public static String PREFIX_FIELD(Code)
The prefix for field names that memoize the parsers results.



PREFIX_METHOD
final public static String PREFIX_METHOD(Code)
The prefix for parsing method names.



REPEATED
final public static String REPEATED(Code)
The prefix for the flag indicating that a repetition has been matched at least once.



REPETITION
final public static String REPETITION(Code)
The prefix for the parser variable for repetitions.



RESULT
final public static String RESULT(Code)
The name for the regular result variable.



VALUE
final public static String VALUE(Code)
The name for the value variable.



alignment
protected int alignment(Code)
The number of spaces to align variable declarations to.



analyzer
final protected Analyzer analyzer(Code)
The analyzer utility.



attributeConstantBinding
protected boolean attributeConstantBinding(Code)
The flag for making variable bindings constant.



attributeDebug
protected boolean attributeDebug(Code)
The flag for generating debugging code.



attributeLocation
protected boolean attributeLocation(Code)
The flag for generating code to annotate nodes with location information.



attributeNoMatchingErrors
protected boolean attributeNoMatchingErrors(Code)
The flag for not generating matching errors.



baseParser
protected String baseParser(Code)
The expression for the base parser.



bindingElement
protected Element bindingElement(Code)
The element being bound.



bindingName
protected String bindingName(Code)
The name of the current binding.



cName
protected String cName(Code)
The class name for the current grammar.



choiceLevel
protected int choiceLevel(Code)
The nesting level for nested choices.



chunkCount
protected int chunkCount(Code)
The number of chunks.



chunkMap
protected Map chunkMap(Code)
The map from nonterminals to chunk numbers.



chunked
protected boolean chunked(Code)
Flag for whether the memoization fields are organized in chunks.



elementIter
protected Iterator elementIter(Code)
The iterator over the elements of a sequence.



endsWithParseError
protected boolean endsWithParseError(Code)
Flag for whether the current choice ends with a parse error.



firstElement
protected boolean firstElement(Code)
The flag for the first element in a top-level choice.



notFollowedBy
protected boolean notFollowedBy(Code)
Flag for whether the current predicate is a not-followed-by predicate.



predicate
protected boolean predicate(Code)
Flag for whether we are currently emitting a predicate.



predicateIter
protected Iterator predicateIter(Code)
The predicate iterator.



printer
final protected Printer printer(Code)
The printer utility.



repeatOnce
protected boolean repeatOnce(Code)
The flag for at-least-once repetitions.



repetitionLevel
protected int repetitionLevel(Code)
The nesting level for repetitions.



resultName
protected String resultName(Code)
The name of the result variable.



savedBaseParser
protected String savedBaseParser(Code)
The saved base parser.



savedFirstElement
protected boolean savedFirstElement(Code)
The saved first element.



savedRepetitionLevel
protected int savedRepetitionLevel(Code)
The saved repetition level (for predicates).



savedUseBaseParser
protected boolean savedUseBaseParser(Code)
The saved flag for using the base parser.



seenTest
protected boolean seenTest(Code)
Flag for whether a test has been emitted.



useBaseParser
protected boolean useBaseParser(Code)
The flag for using the base parser.




Constructor Detail
CodeGenerator
public CodeGenerator(Analyzer analyzer, Printer printer)(Code)
Create a new code generator.
Parameters:
  analyzer - The analyzer for the new code generator.
Parameters:
  printer - The printer for the new code generator.




Method Detail
action
protected void action(Action a)(Code)
Actually emit code for the specified action.



alignment
protected void alignment(boolean includeParser)(Code)
Determine the variable alignment for parse method declarations.
Parameters:
  includeParser - Flag for whether a parser variable needs tobe declared.



binding
protected void binding()(Code)
Actually emit the code for the last visited binding.



clearBinding
protected void clearBinding()(Code)
Clear binding information after usage.



fieldName
public String fieldName(NonTerminal nt)(Code)
Generate the field name for the specified nonterminal.
Parameters:
  nt - The nonterminal. The corresponding field name.



hasBinding
protected boolean hasBinding()(Code)
Determine whether the current element has a binding. true if the current element has a binding.



methodName
public String methodName(NonTerminal nt)(Code)
Generate the method name for the specified nonterminal.
Parameters:
  nt - The nonterminal. The corresponding method name.



nestedChoice
protected String nestedChoice()(Code)
Return the name of the parser variable for the current nested choice level. The nested choice parser variable.



nextElement
protected void nextElement()(Code)
Emit the code for the next element. If the next element is the last element in the main sequence, the code for returning a semantic value is also emitted.
See Also:   CodeGenerator.returnValue()



notFollowedBy
protected boolean notFollowedBy()(Code)
Determine whether we are processing a not-followed-by predicate. true if we are processing a not-followed-bypredicate.



parseError
protected void parseError()(Code)
Emit the code for generating a parse error.



parseError
protected void parseError(String text)(Code)
Emit the code for generating a parse error.
Parameters:
  text - The expected text.



result
protected void result(String methodName, boolean saveParser)(Code)
Emit the code for assigning the result variable, threading the parse error, and for testing the result.
Parameters:
  methodName - The name of the parser method to use.
Parameters:
  saveParser - Flag for whether to save the parser in theparser variable.



returnValue
protected void returnValue()(Code)
Emit the code for returning a semantic value.



tested
protected void tested()(Code)
Note that a test has been emitted. This method should be called at the end of the method that emitted the test.



valueTest
protected void valueTest()(Code)
Emit the code testing whether the result has a value.



valueTest
protected void valueTest(String text)(Code)
Emit the code for testing the result.
Parameters:
  text - The expected text value.



visit
public void visit(Grammar g)(Code)
Generate code for the specified grammar.



visit
public void visit(Production p)(Code)
Generate code for the specified production.



visit
public void visit(OrderedChoice c)(Code)
Generate code for the specified ordered choice.



visit
public void visit(Repetition r)(Code)
Generate code for the specified repetition.



visit
public void visit(FollowedBy p)(Code)
Generate code for the specified followed-by predicate.



visit
public void visit(NotFollowedBy p)(Code)
Generate code for the specified not-followed-by predicate.



visit
public void visit(SemanticPredicate p)(Code)
Generate code for the specified semantic predicate.



visit
public void visit(Binding b)(Code)
Generate code for the specified binding.



visit
public void visit(StringMatch m)(Code)
Generate code for the specified string match.



visit
public void visit(NonTerminal nt)(Code)
Generate code for the specified nonterminal.



visit
public void visit(AnyChar a)(Code)
Generate code for the any character element.



visit
public void visit(CharLiteral l)(Code)
Generate code for the specified character literal.



visit
public void visit(CharClass c)(Code)
Generate code for the specified character class.



visit
public void visit(StringLiteral l)(Code)
Generate code for the specified literal.



visit
public void visit(CharSwitch s)(Code)
Generate code for the specified character switch.



visit
public void visit(Action a)(Code)
Generate code for the specified action.



visit
public void visit(NullValue v)(Code)
Generate code for the specified null value.



visit
public void visit(StringValue v)(Code)
Generate code for the specified string value.



visit
public void visit(TextValue v)(Code)
Generate code for the specified text value.



visit
public void visit(EmptyListValue v)(Code)
Generate code for the specified empty list value.



visit
public void visit(SingletonListValue v)(Code)
Generate code for the specified singleton list value.



visit
public void visit(ListValue v)(Code)
Generate code for the specified list value.



Methods inherited from xtc.tree.Visitor
public Object dispatch(Node node)(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.