Java Doc for CodeGenerator.java in  » IDE-Netbeans » cnd » antlr » 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 » IDE Netbeans » cnd » antlr 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   antlr.CodeGenerator

All known Subclasses:   antlr.DiagnosticCodeGenerator,  antlr.DocBookCodeGenerator,  antlr.JavaCodeGenerator,  antlr.HTMLCodeGenerator,
CodeGenerator
abstract public class CodeGenerator (Code)
A generic ANTLR code generator. All code generators Derive from this class.

A CodeGenerator knows about a Grammar data structure and a grammar analyzer. The Grammar is walked to generate the appropriate code for both a parser and lexer (if present). This interface may change slightly so that the lexer is itself living inside of a Grammar object (in which case, this class generates only one recognizer). The main method to call is gen(), which initiates all code gen.

The interaction of the code generator with the analyzer is simple: each subrule block calls deterministic() before generating code for the block. Method deterministic() sets lookahead caches in each Alternative object. Technically, a code generator doesn't need the grammar analyzer if all lookahead analysis is done at runtime, but this would result in a slower parser.

This class provides a set of support utilities to handle argument list parsing and so on.
author:
   Terence Parr, John Lilley
version:
   2.00a
See Also:   antlr.JavaCodeGenerator
See Also:   antlr.DiagnosticCodeGenerator
See Also:   antlr.LLkAnalyzer
See Also:   antlr.Grammar
See Also:   antlr.AlternativeElement
See Also:   antlr.Lookahead



Field Summary
final protected static  intBITSET_OPTIMIZE_INIT_THRESHOLD
     If there are more than 8 long words to init in a bitset, try to optimize it; e.g., detect runs of -1L and 0L.
protected  booleanDEBUG_CODE_GENERATOR
    
final protected static  intDEFAULT_BITSET_TEST_THRESHOLD
    
final protected static  intDEFAULT_MAKE_SWITCH_THRESHOLD
    
public static  StringTokenTypesFileExt
    
public static  StringTokenTypesFileSuffix
    
protected  LLkGrammarAnalyzeranalyzer
    
protected  antlr.ToolantlrTool
    
protected  DefineGrammarSymbolsbehavior
    
protected  intbitsetTestThreshold
     This is a hint for the language-specific code generator.
protected  VectorbitsetsUsed
     List of all bitsets that must be dumped.
protected  CharFormattercharFormatter
     Object used to format characters in the target language.
protected transient  PrintWritercurrentOutput
    
protected  Grammargrammar
    
protected  intmakeSwitchThreshold
     This is a hint for the language-specific code generator.
protected  inttabs
    

Constructor Summary
public  CodeGenerator()
    

Method Summary
protected  void_print(String s)
     Output a String to the currentOutput stream.
protected  void_printAction(String s)
     Print an action without leading tabs, attempting to preserve the current indentation level for multi-line actions Ignored if string is null.
protected  void_println(String s)
     Output a String followed by newline, to the currentOutput stream.
public static  StringdecodeLexerRuleName(String id)
    
public static  booleanelementsAreRange(int[] elems)
     Test if a set element array represents a contiguous range.
Parameters:
  elems - The array of elements representing the set, usually from BitSet.toArray().
public static  StringencodeLexerRuleName(String id)
    
protected  StringextractIdOfAction(Token t)
     Get the identifier portion of an argument-action token.
protected  StringextractIdOfAction(String s, int line, int column)
     Get the identifier portion of an argument-action. The ID of an action is assumed to be a trailing identifier. Specific code-generators may want to override this if the language has unusual declaration syntax.
Parameters:
  s - The action text
Parameters:
  line - Line used for error reporting.
Parameters:
  column - Line used for error reporting.
protected  StringextractTypeOfAction(Token t)
     Get the type string out of an argument-action token.
protected  StringextractTypeOfAction(String s, int line, int column)
     Get the type portion of an argument-action. The type of an action is assumed to precede a trailing identifier Specific code-generators may want to override this if the language has unusual declaration syntax.
Parameters:
  s - The action text
Parameters:
  line - Line used for error reporting.
abstract public  voidgen()
    
abstract public  voidgen(ActionElement action, Context context)
     Generate code for the given grammar element.
abstract public  voidgen(AlternativeBlock blk, Context context)
     Generate code for the given grammar element.
abstract public  voidgen(BlockEndElement end, Context context)
     Generate code for the given grammar element.
Parameters:
  end - The block-end element to generate.
abstract public  voidgen(CharLiteralElement atom, Context context)
     Generate code for the given grammar element.
abstract public  voidgen(CharRangeElement r, Context context)
     Generate code for the given grammar element.
abstract public  voidgen(LexerGrammar g)
    
abstract public  voidgen(OneOrMoreBlock blk, Context context)
     Generate code for the given grammar element.
abstract public  voidgen(ParserGrammar g)
    
abstract public  voidgen(RuleRefElement rr, Context context)
     Generate code for the given grammar element.
abstract public  voidgen(StringLiteralElement atom, Context context)
     Generate code for the given grammar element.
abstract public  voidgen(TokenRangeElement r, Context context)
     Generate code for the given grammar element.
abstract public  voidgen(TokenRefElement atom, Context context)
     Generate code for the given grammar element.
abstract public  voidgen(TreeElement t, Context context)
     Generate code for the given grammar element.
abstract public  voidgen(TreeWalkerGrammar g)
    
abstract public  voidgen(WildcardElement wc, Context context)
     Generate code for the given grammar element.
abstract public  voidgen(ZeroOrMoreBlock blk, Context context)
     Generate code for the given grammar element.
protected  voidgenTokenInterchange(TokenManager tm)
    
abstract public  StringgetASTCreateString(Vector v)
     Get a string for an expression to generate creation of an AST subtree.
abstract public  StringgetASTCreateString(GrammarAtom atom, String str)
    
protected  StringgetBitsetName(int index)
     Given the index of a bitset in the bitset list, generate a unique name.
public  StringgetFIRSTBitSet(String ruleName, int k)
    
public  StringgetFOLLOWBitSet(String ruleName, int k)
    
abstract public  StringmapTreeId(String id, ActionTransInfo tInfo)
     Map an identifier to it's corresponding tree-node variable. This is context-sensitive, depending on the rule and alternative being generated
Parameters:
  id - The identifier name to map
Parameters:
  forInput - true if the input tree node variable is to be returned, otherwise the output variable is returned.
protected  intmarkBitsetForGen(BitSet p)
     Add a bitset to the list of bitsets to be generated.
protected  voidprint(String s)
     Output tab indent followed by a String, to the currentOutput stream.
protected  voidprintAction(String s)
     Print an action with leading tabs, attempting to preserve the current indentation level for multi-line actions Ignored if string is null.
protected  voidprintTabs()
     Output the current tab indentation.
protected  voidprintln(String s)
     Output tab indent followed by a String followed by newline, to the currentOutput stream.
abstract protected  StringprocessActionForSpecialSymbols(String actionStr, int line, RuleBlock currentRule, ActionTransInfo tInfo)
     Lexically process $ and # references within the action.
public  StringprocessStringForASTConstructor(String str)
     Process a string for an simple expression for use in xx/action.g it is used to cast simple tokens/references to the right type for the generated language.
protected  StringremoveAssignmentFromDeclaration(String d)
     Remove the assignment portion of a declaration, if any.
public static  StringreverseLexerRuleName(String id)
    
public  voidsetAnalyzer(LLkGrammarAnalyzer analyzer_)
    
public  voidsetBehavior(DefineGrammarSymbols behavior_)
    
protected  voidsetGrammar(Grammar g)
    
public  voidsetTool(Tool tool)
    

Field Detail
BITSET_OPTIMIZE_INIT_THRESHOLD
final protected static int BITSET_OPTIMIZE_INIT_THRESHOLD(Code)
If there are more than 8 long words to init in a bitset, try to optimize it; e.g., detect runs of -1L and 0L.



DEBUG_CODE_GENERATOR
protected boolean DEBUG_CODE_GENERATOR(Code)
Use option "codeGenDebug" to generate debugging output



DEFAULT_BITSET_TEST_THRESHOLD
final protected static int DEFAULT_BITSET_TEST_THRESHOLD(Code)



DEFAULT_MAKE_SWITCH_THRESHOLD
final protected static int DEFAULT_MAKE_SWITCH_THRESHOLD(Code)
Default values for code-generation thresholds



TokenTypesFileExt
public static String TokenTypesFileExt(Code)



TokenTypesFileSuffix
public static String TokenTypesFileSuffix(Code)



analyzer
protected LLkGrammarAnalyzer analyzer(Code)
The LLk analyzer



antlrTool
protected antlr.Tool antlrTool(Code)



behavior
protected DefineGrammarSymbols behavior(Code)
The grammar behavior



bitsetTestThreshold
protected int bitsetTestThreshold(Code)
This is a hint for the language-specific code generator. A bitset membership test will be generated instead of an ORed series of LA(k) comparisions for lookahead sets with degree greater than or equal to this value. This is modified by the grammar option "codeGenBitsetTestThreshold"



bitsetsUsed
protected Vector bitsetsUsed(Code)
List of all bitsets that must be dumped. These are Vectors of BitSet.



charFormatter
protected CharFormatter charFormatter(Code)
Object used to format characters in the target language. subclass must initialize this to the language-specific formatter



currentOutput
protected transient PrintWriter currentOutput(Code)
Current output Stream



grammar
protected Grammar grammar(Code)
The grammar for which we generate code



makeSwitchThreshold
protected int makeSwitchThreshold(Code)
This is a hint for the language-specific code generator. A switch() or language-specific equivalent will be generated instead of a series of if/else statements for blocks with number of alternates greater than or equal to this number of non-predicated LL(1) alternates. This is modified by the grammar option "codeGenMakeSwitchThreshold"



tabs
protected int tabs(Code)
Current tab indentation for code output




Constructor Detail
CodeGenerator
public CodeGenerator()(Code)
Construct code generator base class




Method Detail
_print
protected void _print(String s)(Code)
Output a String to the currentOutput stream. Ignored if string is null.
Parameters:
  s - The string to output



_printAction
protected void _printAction(String s)(Code)
Print an action without leading tabs, attempting to preserve the current indentation level for multi-line actions Ignored if string is null.
Parameters:
  s - The action string to output



_println
protected void _println(String s)(Code)
Output a String followed by newline, to the currentOutput stream. Ignored if string is null.
Parameters:
  s - The string to output



decodeLexerRuleName
public static String decodeLexerRuleName(String id)(Code)



elementsAreRange
public static boolean elementsAreRange(int[] elems)(Code)
Test if a set element array represents a contiguous range.
Parameters:
  elems - The array of elements representing the set, usually from BitSet.toArray(). true if the elements are a contiguous range (with two or more).



encodeLexerRuleName
public static String encodeLexerRuleName(String id)(Code)



extractIdOfAction
protected String extractIdOfAction(Token t)(Code)
Get the identifier portion of an argument-action token. The ID of an action is assumed to be a trailing identifier. Specific code-generators may want to override this if the language has unusual declaration syntax.
Parameters:
  t - The action token A string containing the text of the identifier



extractIdOfAction
protected String extractIdOfAction(String s, int line, int column)(Code)
Get the identifier portion of an argument-action. The ID of an action is assumed to be a trailing identifier. Specific code-generators may want to override this if the language has unusual declaration syntax.
Parameters:
  s - The action text
Parameters:
  line - Line used for error reporting.
Parameters:
  column - Line used for error reporting. A string containing the text of the identifier



extractTypeOfAction
protected String extractTypeOfAction(Token t)(Code)
Get the type string out of an argument-action token. The type of an action is assumed to precede a trailing identifier Specific code-generators may want to override this if the language has unusual declaration syntax.
Parameters:
  t - The action token A string containing the text of the type



extractTypeOfAction
protected String extractTypeOfAction(String s, int line, int column)(Code)
Get the type portion of an argument-action. The type of an action is assumed to precede a trailing identifier Specific code-generators may want to override this if the language has unusual declaration syntax.
Parameters:
  s - The action text
Parameters:
  line - Line used for error reporting. A string containing the text of the type



gen
abstract public void gen()(Code)
Generate the code for all grammars



gen
abstract public void gen(ActionElement action, Context context)(Code)
Generate code for the given grammar element.
Parameters:
  action - The {...} action to generate



gen
abstract public void gen(AlternativeBlock blk, Context context)(Code)
Generate code for the given grammar element.
Parameters:
  blk - The "x|y|z|..." block to generate



gen
abstract public void gen(BlockEndElement end, Context context)(Code)
Generate code for the given grammar element.
Parameters:
  end - The block-end element to generate. Block-endelements are synthesized by the grammar parser to representthe end of a block.



gen
abstract public void gen(CharLiteralElement atom, Context context)(Code)
Generate code for the given grammar element.
Parameters:
  atom - The character literal reference to generate



gen
abstract public void gen(CharRangeElement r, Context context)(Code)
Generate code for the given grammar element.
Parameters:
  r - The character-range reference to generate



gen
abstract public void gen(LexerGrammar g) throws IOException(Code)
Generate the code for a parser



gen
abstract public void gen(OneOrMoreBlock blk, Context context)(Code)
Generate code for the given grammar element.
Parameters:
  blk - The (...)+ block to generate



gen
abstract public void gen(ParserGrammar g) throws IOException(Code)
Generate the code for a parser



gen
abstract public void gen(RuleRefElement rr, Context context)(Code)
Generate code for the given grammar element.
Parameters:
  rr - The rule-reference to generate



gen
abstract public void gen(StringLiteralElement atom, Context context)(Code)
Generate code for the given grammar element.
Parameters:
  atom - The string-literal reference to generate



gen
abstract public void gen(TokenRangeElement r, Context context)(Code)
Generate code for the given grammar element.
Parameters:
  r - The token-range reference to generate



gen
abstract public void gen(TokenRefElement atom, Context context)(Code)
Generate code for the given grammar element.
Parameters:
  atom - The token-reference to generate



gen
abstract public void gen(TreeElement t, Context context)(Code)
Generate code for the given grammar element.
Parameters:
  blk - The tree to generate code for.



gen
abstract public void gen(TreeWalkerGrammar g) throws IOException(Code)
Generate the code for a parser



gen
abstract public void gen(WildcardElement wc, Context context)(Code)
Generate code for the given grammar element.
Parameters:
  wc - The wildcard element to generate



gen
abstract public void gen(ZeroOrMoreBlock blk, Context context)(Code)
Generate code for the given grammar element.
Parameters:
  blk - The (...)* block to generate



genTokenInterchange
protected void genTokenInterchange(TokenManager tm) throws IOException(Code)
Generate the token types as a text file for persistence across shared lexer/parser



getASTCreateString
abstract public String getASTCreateString(Vector v)(Code)
Get a string for an expression to generate creation of an AST subtree.
Parameters:
  v - A Vector of String, where each element is an expression in the target language yielding an AST node.



getASTCreateString
abstract public String getASTCreateString(GrammarAtom atom, String str)(Code)
Get a string for an expression to generate creating of an AST node
Parameters:
  str - The text of the arguments to the AST construction



getBitsetName
protected String getBitsetName(int index)(Code)
Given the index of a bitset in the bitset list, generate a unique name. Specific code-generators may want to override this if the language does not allow '_' or numerals in identifiers.
Parameters:
  index - The index of the bitset in the bitset list.



getFIRSTBitSet
public String getFIRSTBitSet(String ruleName, int k)(Code)



getFOLLOWBitSet
public String getFOLLOWBitSet(String ruleName, int k)(Code)



mapTreeId
abstract public String mapTreeId(String id, ActionTransInfo tInfo)(Code)
Map an identifier to it's corresponding tree-node variable. This is context-sensitive, depending on the rule and alternative being generated
Parameters:
  id - The identifier name to map
Parameters:
  forInput - true if the input tree node variable is to be returned, otherwise the output variable is returned. The mapped id (which may be the same as the input), or null if the mapping is invalid due to duplicates



markBitsetForGen
protected int markBitsetForGen(BitSet p)(Code)
Add a bitset to the list of bitsets to be generated. if the bitset is already in the list, ignore the request. Always adds the bitset to the end of the list, so the caller can rely on the position of bitsets in the list. The returned position can be used to format the bitset name, since it is invariant.
Parameters:
  p - Bit set to mark for code generation
Parameters:
  forParser - true if the bitset is used for the parser, false for the lexer The position of the bitset in the list.



print
protected void print(String s)(Code)
Output tab indent followed by a String, to the currentOutput stream. Ignored if string is null.
Parameters:
  s - The string to output.



printAction
protected void printAction(String s)(Code)
Print an action with leading tabs, attempting to preserve the current indentation level for multi-line actions Ignored if string is null.
Parameters:
  s - The action string to output



printTabs
protected void printTabs()(Code)
Output the current tab indentation. This outputs the number of tabs indicated by the "tabs" variable to the currentOutput stream.



println
protected void println(String s)(Code)
Output tab indent followed by a String followed by newline, to the currentOutput stream. Ignored if string is null.
Parameters:
  s - The string to output



processActionForSpecialSymbols
abstract protected String processActionForSpecialSymbols(String actionStr, int line, RuleBlock currentRule, ActionTransInfo tInfo)(Code)
Lexically process $ and # references within the action. This will replace #id and #(...) with the appropriate function calls and/or variables etc...



processStringForASTConstructor
public String processStringForASTConstructor(String str)(Code)
Process a string for an simple expression for use in xx/action.g it is used to cast simple tokens/references to the right type for the generated language.
Parameters:
  str - A String.



removeAssignmentFromDeclaration
protected String removeAssignmentFromDeclaration(String d)(Code)
Remove the assignment portion of a declaration, if any.
Parameters:
  d - the declaration the declaration without any assignment portion



reverseLexerRuleName
public static String reverseLexerRuleName(String id)(Code)



setAnalyzer
public void setAnalyzer(LLkGrammarAnalyzer analyzer_)(Code)



setBehavior
public void setBehavior(DefineGrammarSymbols behavior_)(Code)



setGrammar
protected void setGrammar(Grammar g)(Code)
Set a grammar for the code generator to use



setTool
public void setTool(Tool tool)(Code)



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.