Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes

antlr.CodeGenerator Class Reference

Inheritance diagram for antlr.CodeGenerator:
antlr.CppCodeGenerator antlr.CSharpCodeGenerator antlr.DiagnosticCodeGenerator antlr.DocBookCodeGenerator antlr.HTMLCodeGenerator antlr.JavaCodeGenerator antlr.PythonCodeGenerator

List of all members.

Public Member Functions

 CodeGenerator ()
abstract void gen ()
abstract void gen (ActionElement action)
abstract void gen (AlternativeBlock blk)
abstract void gen (BlockEndElement end)
abstract void gen (CharLiteralElement atom)
abstract void gen (CharRangeElement r)
abstract void gen (LexerGrammar g) throws IOException
abstract void gen (OneOrMoreBlock blk)
abstract void gen (ParserGrammar g) throws IOException
abstract void gen (RuleRefElement rr)
abstract void gen (StringLiteralElement atom)
abstract void gen (TokenRangeElement r)
abstract void gen (TokenRefElement atom)
abstract void gen (TreeElement t)
abstract void gen (TreeWalkerGrammar g) throws IOException
abstract void gen (WildcardElement wc)
abstract void gen (ZeroOrMoreBlock blk)
String processStringForASTConstructor (String str)
abstract String getASTCreateString (Vector v)
abstract String getASTCreateString (GrammarAtom atom, String str)
abstract String mapTreeId (String id, ActionTransInfo tInfo)
String getFOLLOWBitSet (String ruleName, int k)
String getFIRSTBitSet (String ruleName, int k)
void setAnalyzer (LLkGrammarAnalyzer analyzer_)
void setBehavior (DefineGrammarSymbols behavior_)
void setTool (Tool tool)

Static Public Member Functions

static boolean elementsAreRange (int[] elems)
static String encodeLexerRuleName (String id)
static String decodeLexerRuleName (String id)
static String reverseLexerRuleName (String id)

Static Public Attributes

static String TokenTypesFileSuffix = "TokenTypes"
static String TokenTypesFileExt = ".txt"

Protected Member Functions

void _print (String s)
void _printAction (String s)
void _println (String s)
String extractIdOfAction (Token t)
String extractIdOfAction (String s, int line, int column)
String extractTypeOfAction (Token t)
String extractTypeOfAction (String s, int line, int column)
void genTokenInterchange (TokenManager tm) throws IOException
String getBitsetName (int index)
int markBitsetForGen (BitSet p)
void print (String s)
void printAction (String s)
void println (String s)
void printTabs ()
abstract String processActionForSpecialSymbols (String actionStr, int line, RuleBlock currentRule, ActionTransInfo tInfo)
String removeAssignmentFromDeclaration (String d)
void setGrammar (Grammar g)

Protected Attributes

antlr.Tool antlrTool
int tabs = 0
transient PrintWriter currentOutput
Grammar grammar = null
Vector bitsetsUsed
DefineGrammarSymbols behavior
LLkGrammarAnalyzer analyzer
CharFormatter charFormatter
boolean DEBUG_CODE_GENERATOR = false
int makeSwitchThreshold = DEFAULT_MAKE_SWITCH_THRESHOLD
int bitsetTestThreshold = DEFAULT_BITSET_TEST_THRESHOLD

Static Protected Attributes

static final int DEFAULT_MAKE_SWITCH_THRESHOLD = 2
static final int DEFAULT_BITSET_TEST_THRESHOLD = 4
static final int BITSET_OPTIMIZE_INIT_THRESHOLD = 8

Detailed Description

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
antlr.DiagnosticCodeGenerator
antlr.LLkAnalyzer
antlr.Grammar
antlr.AlternativeElement
antlr.Lookahead

Constructor & Destructor Documentation

antlr.CodeGenerator.CodeGenerator (  ) 

Construct code generator base class


Member Function Documentation

void antlr.CodeGenerator._printAction ( String  s  )  [protected]

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

Reimplemented in antlr.CppCodeGenerator, and antlr.PythonCodeGenerator.

References antlr.CodeGenerator.currentOutput, and antlr.CodeGenerator.printTabs().

Referenced by antlr.DiagnosticCodeGenerator.gen(), and antlr.CodeGenerator.printAction().

static String antlr.CodeGenerator.decodeLexerRuleName ( String  id  )  [static]
static boolean antlr.CodeGenerator.elementsAreRange ( int[]  elems  )  [static]
static String antlr.CodeGenerator.encodeLexerRuleName ( String  id  )  [static]
String antlr.CodeGenerator.extractIdOfAction ( Token  t  )  [protected]

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
Returns:
A string containing the text of the identifier

References antlr.Token.getColumn(), antlr.Token.getLine(), and antlr.Token.getText().

Referenced by antlr.JavaCodeGenerator.genRule(), antlr.CSharpCodeGenerator.genRule(), and antlr.CppCodeGenerator.genRule().

String antlr.CodeGenerator.extractIdOfAction ( String  s,
int  line,
int  column 
) [protected]

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
line Line used for error reporting.
column Line used for error reporting.
Returns:
A string containing the text of the identifier

Reimplemented in antlr.PythonCodeGenerator.

References antlr.CodeGenerator.antlrTool, antlr.Grammar.getFilename(), antlr.CodeGenerator.grammar, antlr.CodeGenerator.removeAssignmentFromDeclaration(), and antlr.Tool.warning().

String antlr.CodeGenerator.extractTypeOfAction ( String  s,
int  line,
int  column 
) [protected]

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
line Line used for error reporting.
Returns:
A string containing the text of the type

Reimplemented in antlr.PythonCodeGenerator.

References antlr.CodeGenerator.antlrTool, antlr.Grammar.getFilename(), antlr.CodeGenerator.grammar, antlr.CodeGenerator.removeAssignmentFromDeclaration(), and antlr.Tool.warning().

String antlr.CodeGenerator.extractTypeOfAction ( Token  t  )  [protected]

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
Returns:
A string containing the text of the type

References antlr.Token.getColumn(), antlr.Token.getLine(), and antlr.Token.getText().

Referenced by antlr.JavaCodeGenerator.genRule(), antlr.CSharpCodeGenerator.genRule(), antlr.CppCodeGenerator.genRule(), and antlr.CppCodeGenerator.genRuleHeader().

abstract void antlr.CodeGenerator.gen ( OneOrMoreBlock  blk  )  [pure virtual]

Generate code for the given grammar element.

Parameters:
blk The (...)+ block to generate

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

abstract void antlr.CodeGenerator.gen ( ParserGrammar  g  )  throws IOException [pure virtual]
abstract void antlr.CodeGenerator.gen ( RuleRefElement  rr  )  [pure virtual]

Generate code for the given grammar element.

Parameters:
rr The rule-reference to generate

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

abstract void antlr.CodeGenerator.gen ( StringLiteralElement  atom  )  [pure virtual]

Generate code for the given grammar element.

Parameters:
atom The string-literal reference to generate

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

abstract void antlr.CodeGenerator.gen ( ActionElement  action  )  [pure virtual]

Generate code for the given grammar element.

Parameters:
action The {...} action to generate

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

abstract void antlr.CodeGenerator.gen ( TokenRangeElement  r  )  [pure virtual]

Generate code for the given grammar element.

Parameters:
r The token-range reference to generate

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

abstract void antlr.CodeGenerator.gen ( TokenRefElement  atom  )  [pure virtual]

Generate code for the given grammar element.

Parameters:
atom The token-reference to generate

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

abstract void antlr.CodeGenerator.gen ( AlternativeBlock  blk  )  [pure virtual]

Generate code for the given grammar element.

Parameters:
blk The "x|y|z|..." block to generate

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

abstract void antlr.CodeGenerator.gen ( TreeElement  t  )  [pure virtual]

Generate code for the given grammar element.

Parameters:
blk The tree to generate code for.

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

abstract void antlr.CodeGenerator.gen ( TreeWalkerGrammar  g  )  throws IOException [pure virtual]
abstract void antlr.CodeGenerator.gen ( BlockEndElement  end  )  [pure virtual]

Generate code for the given grammar element.

Parameters:
end The block-end element to generate. Block-end elements are synthesized by the grammar parser to represent the end of a block.

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

abstract void antlr.CodeGenerator.gen ( WildcardElement  wc  )  [pure virtual]

Generate code for the given grammar element.

Parameters:
wc The wildcard element to generate

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

abstract void antlr.CodeGenerator.gen ( ZeroOrMoreBlock  blk  )  [pure virtual]

Generate code for the given grammar element.

Parameters:
blk The (...)* block to generate

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

abstract void antlr.CodeGenerator.gen ( CharLiteralElement  atom  )  [pure virtual]

Generate code for the given grammar element.

Parameters:
atom The character literal reference to generate

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

abstract void antlr.CodeGenerator.gen ( CharRangeElement  r  )  [pure virtual]

Generate code for the given grammar element.

Parameters:
r The character-range reference to generate

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

abstract void antlr.CodeGenerator.gen ( LexerGrammar  g  )  throws IOException [pure virtual]
abstract String antlr.CodeGenerator.getASTCreateString ( GrammarAtom  atom,
String  str 
) [pure virtual]

Get a string for an expression to generate creating of an AST node

Parameters:
str The text of the arguments to the AST construction

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

String antlr.CodeGenerator.getBitsetName ( int  index  )  [protected]
abstract String antlr.CodeGenerator.mapTreeId ( String  id,
ActionTransInfo  tInfo 
) [pure virtual]

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
forInput true if the input tree node variable is to be returned, otherwise the output variable is returned.
Returns:
The mapped id (which may be the same as the input), or null if the mapping is invalid due to duplicates

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

Referenced by antlr.actions.python.ActionLexer.mAST_ITEM(), antlr.actions.java.ActionLexer.mAST_ITEM(), antlr.actions.csharp.ActionLexer.mAST_ITEM(), antlr.actions.cpp.ActionLexer.mAST_ITEM(), antlr.actions.python.ActionLexer.mID_ELEMENT(), antlr.actions.java.ActionLexer.mID_ELEMENT(), antlr.actions.csharp.ActionLexer.mID_ELEMENT(), antlr.actions.cpp.ActionLexer.mID_ELEMENT(), antlr.actions.python.ActionLexer.mTREE_ELEMENT(), antlr.actions.java.ActionLexer.mTREE_ELEMENT(), antlr.actions.csharp.ActionLexer.mTREE_ELEMENT(), and antlr.actions.cpp.ActionLexer.mTREE_ELEMENT().

int antlr.CodeGenerator.markBitsetForGen ( BitSet  p  )  [protected]

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
forParser true if the bitset is used for the parser, false for the lexer
Returns:
The position of the bitset in the list.

References antlr.collections.impl.Vector.appendElement(), antlr.CodeGenerator.bitsetsUsed, antlr.collections.impl.BitSet.clone(), antlr.collections.impl.Vector.elementAt(), antlr.collections.impl.BitSet.equals(), and antlr.collections.impl.Vector.size().

Referenced by antlr.PythonCodeGenerator.genCommonBlock(), antlr.JavaCodeGenerator.genCommonBlock(), antlr.CSharpCodeGenerator.genCommonBlock(), antlr.CppCodeGenerator.genCommonBlock(), antlr.PythonCodeGenerator.genRule(), antlr.JavaCodeGenerator.genRule(), antlr.CSharpCodeGenerator.genRule(), antlr.CppCodeGenerator.genRule(), antlr.CodeGenerator.getFIRSTBitSet(), antlr.CodeGenerator.getFOLLOWBitSet(), antlr.PythonCodeGenerator.getLookaheadTestTerm(), antlr.JavaCodeGenerator.getLookaheadTestTerm(), antlr.CSharpCodeGenerator.getLookaheadTestTerm(), and antlr.CppCodeGenerator.getLookaheadTestTerm().

void antlr.CodeGenerator.print ( String  s  )  [protected]

Output tab indent followed by a String, to the currentOutput stream. Ignored if string is null.

Parameters:
s The string to output.

Reimplemented in antlr.JavaCodeGenerator.

References antlr.CodeGenerator.currentOutput, and antlr.CodeGenerator.printTabs().

Referenced by antlr.PythonCodeGenerator.gen(), antlr.HTMLCodeGenerator.gen(), antlr.DocBookCodeGenerator.gen(), antlr.DiagnosticCodeGenerator.gen(), antlr.CppCodeGenerator.gen(), antlr.CSharpCodeGenerator.genBody(), antlr.CppCodeGenerator.genBody(), antlr.PythonCodeGenerator.genCases(), antlr.CSharpCodeGenerator.genCases(), antlr.CppCodeGenerator.genCases(), antlr.HTMLCodeGenerator.genCommonBlock(), antlr.DocBookCodeGenerator.genCommonBlock(), antlr.DiagnosticCodeGenerator.genCommonBlock(), antlr.HTMLCodeGenerator.genGenericBlock(), antlr.DocBookCodeGenerator.genGenericBlock(), antlr.CppCodeGenerator.genInclude(), antlr.PythonCodeGenerator.genMatchUsingAtomText(), antlr.CSharpCodeGenerator.genMatchUsingAtomText(), antlr.CppCodeGenerator.genMatchUsingAtomText(), antlr.PythonCodeGenerator.genRule(), antlr.HTMLCodeGenerator.genRule(), antlr.DocBookCodeGenerator.genRule(), antlr.CSharpCodeGenerator.genRule(), antlr.CppCodeGenerator.genRule(), antlr.CppCodeGenerator.genRuleHeader(), antlr.CodeGenerator.genTokenInterchange(), antlr.PythonCodeGenerator.genTokenStrings(), antlr.CSharpCodeGenerator.genTokenStrings(), antlr.CppCodeGenerator.genTokenStrings(), antlr.HTMLCodeGenerator.printSet(), antlr.DocBookCodeGenerator.printSet(), and antlr.DiagnosticCodeGenerator.printSet().

void antlr.CodeGenerator.printAction ( String  s  )  [protected]

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

Reimplemented in antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

References antlr.CodeGenerator._printAction(), and antlr.CodeGenerator.printTabs().

Referenced by antlr.DiagnosticCodeGenerator.gen(), antlr.CSharpCodeGenerator.gen(), antlr.CSharpCodeGenerator.genBlockInitAction(), antlr.DiagnosticCodeGenerator.genBlockPreamble(), antlr.DiagnosticCodeGenerator.genHeader(), and antlr.DiagnosticCodeGenerator.genRule().

void antlr.CodeGenerator.println ( String  s  )  [protected]

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

Reimplemented in antlr.CppCodeGenerator, and antlr.JavaCodeGenerator.

References antlr.CodeGenerator.currentOutput, and antlr.CodeGenerator.printTabs().

Referenced by antlr.PythonCodeGenerator.flushTokens(), antlr.PythonCodeGenerator.gen(), antlr.HTMLCodeGenerator.gen(), antlr.DocBookCodeGenerator.gen(), antlr.DiagnosticCodeGenerator.gen(), antlr.CSharpCodeGenerator.gen(), antlr.PythonCodeGenerator.genAlt(), antlr.DiagnosticCodeGenerator.genAlt(), antlr.CSharpCodeGenerator.genAlt(), antlr.PythonCodeGenerator.genASTDeclaration(), antlr.CSharpCodeGenerator.genASTDeclaration(), antlr.PythonCodeGenerator.genBitsets(), antlr.CSharpCodeGenerator.genBitsets(), antlr.PythonCodeGenerator.genBlockPreamble(), antlr.CSharpCodeGenerator.genBlockPreamble(), antlr.CSharpCodeGenerator.genBody(), antlr.PythonCodeGenerator.genCommonBlock(), antlr.DocBookCodeGenerator.genCommonBlock(), antlr.DiagnosticCodeGenerator.genCommonBlock(), antlr.CSharpCodeGenerator.genCommonBlock(), antlr.PythonCodeGenerator.genHeader(), antlr.HTMLCodeGenerator.genHeader(), antlr.DocBookCodeGenerator.genHeader(), antlr.DiagnosticCodeGenerator.genHeader(), antlr.CSharpCodeGenerator.genHeader(), antlr.PythonCodeGenerator.genHeaderInit(), antlr.PythonCodeGenerator.genHeaderMain(), antlr.CSharpCodeGenerator.genInitFactory(), antlr.PythonCodeGenerator.genLexerTest(), antlr.HTMLCodeGenerator.genLookaheadSetForAlt(), antlr.DocBookCodeGenerator.genLookaheadSetForAlt(), antlr.DiagnosticCodeGenerator.genLookaheadSetForAlt(), antlr.PythonCodeGenerator.genMatchUsingAtomText(), antlr.CSharpCodeGenerator.genMatchUsingAtomText(), antlr.PythonCodeGenerator.genMatchUsingAtomTokenType(), antlr.CSharpCodeGenerator.genMatchUsingAtomTokenType(), antlr.PythonCodeGenerator.genNextToken(), antlr.HTMLCodeGenerator.genNextToken(), antlr.DocBookCodeGenerator.genNextToken(), antlr.DiagnosticCodeGenerator.genNextToken(), antlr.CSharpCodeGenerator.genNextToken(), antlr.PythonCodeGenerator.genRule(), antlr.HTMLCodeGenerator.genRule(), antlr.DocBookCodeGenerator.genRule(), antlr.DiagnosticCodeGenerator.genRule(), antlr.CSharpCodeGenerator.genRule(), antlr.PythonCodeGenerator.genSemPred(), antlr.CSharpCodeGenerator.genSemPred(), antlr.PythonCodeGenerator.genSemPredMap(), antlr.CSharpCodeGenerator.genSemPredMap(), antlr.PythonCodeGenerator.genSynPred(), antlr.CSharpCodeGenerator.genSynPred(), antlr.HTMLCodeGenerator.genTail(), antlr.DocBookCodeGenerator.genTail(), antlr.PythonCodeGenerator.genTokenASTNodeMap(), antlr.CSharpCodeGenerator.genTokenDefinitions(), antlr.CodeGenerator.genTokenInterchange(), antlr.PythonCodeGenerator.genTokenStrings(), antlr.CSharpCodeGenerator.genTokenStrings(), antlr.PythonCodeGenerator.genTokenTypes(), antlr.HTMLCodeGenerator.genTokenTypes(), antlr.DocBookCodeGenerator.genTokenTypes(), antlr.DiagnosticCodeGenerator.genTokenTypes(), antlr.CSharpCodeGenerator.genTokenTypes(), antlr.PythonCodeGenerator.printGrammarAction(), and antlr.PythonCodeGenerator.printMainFunc().

void antlr.CodeGenerator.printTabs (  )  [protected]
abstract String antlr.CodeGenerator.processActionForSpecialSymbols ( String  actionStr,
int  line,
RuleBlock  currentRule,
ActionTransInfo  tInfo 
) [protected, pure virtual]

Lexically process $ and # references within the action. This will replace id and #(...) with the appropriate function calls and/or variables etc...

Implemented in antlr.CppCodeGenerator, antlr.CSharpCodeGenerator, antlr.DiagnosticCodeGenerator, antlr.DocBookCodeGenerator, antlr.HTMLCodeGenerator, antlr.JavaCodeGenerator, and antlr.PythonCodeGenerator.

String antlr.CodeGenerator.processStringForASTConstructor ( 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.

Parameters:
str A String.

Reimplemented in antlr.CppCodeGenerator, and antlr.CSharpCodeGenerator.

Referenced by antlr.actions.csharp.ActionLexer.mAST_CONSTRUCTOR(), antlr.actions.cpp.ActionLexer.mAST_CONSTRUCTOR(), antlr.actions.csharp.ActionLexer.mTREE(), and antlr.actions.cpp.ActionLexer.mTREE().

String antlr.CodeGenerator.removeAssignmentFromDeclaration ( String  d  )  [protected]

Remove the assignment portion of a declaration, if any.

Parameters:
d the declaration
Returns:
the declaration without any assignment portion

Referenced by antlr.PythonCodeGenerator.extractIdOfAction(), antlr.CodeGenerator.extractIdOfAction(), and antlr.CodeGenerator.extractTypeOfAction().

static String antlr.CodeGenerator.reverseLexerRuleName ( String  id  )  [static]
void antlr.CodeGenerator.setAnalyzer ( LLkGrammarAnalyzer  analyzer_  ) 
void antlr.CodeGenerator.setBehavior ( DefineGrammarSymbols  behavior_  ) 
void antlr.CodeGenerator.setTool ( Tool  tool  ) 

Member Data Documentation

Referenced by antlr.PythonCodeGenerator.exitIfError(), antlr.JavaCodeGenerator.exitIfError(), antlr.CSharpCodeGenerator.exitIfError(), antlr.CppCodeGenerator.exitIfError(), antlr.CodeGenerator.extractIdOfAction(), antlr.CodeGenerator.extractTypeOfAction(), antlr.PythonCodeGenerator.gen(), antlr.JavaCodeGenerator.gen(), antlr.HTMLCodeGenerator.gen(), antlr.DocBookCodeGenerator.gen(), antlr.DiagnosticCodeGenerator.gen(), antlr.CSharpCodeGenerator.gen(), antlr.CppCodeGenerator.gen(), antlr.PythonCodeGenerator.genAlt(), antlr.JavaCodeGenerator.genAlt(), antlr.CSharpCodeGenerator.genAlt(), antlr.CppCodeGenerator.genAlt(), antlr.CppCodeGenerator.genBody(), antlr.PythonCodeGenerator.genCommonBlock(), antlr.JavaCodeGenerator.genCommonBlock(), antlr.CSharpCodeGenerator.genCommonBlock(), antlr.CppCodeGenerator.genCommonBlock(), antlr.PythonCodeGenerator.genHeader(), antlr.JavaCodeGenerator.genHeader(), antlr.HTMLCodeGenerator.genHeader(), antlr.DocBookCodeGenerator.genHeader(), antlr.DiagnosticCodeGenerator.genHeader(), antlr.CSharpCodeGenerator.genHeader(), antlr.CppCodeGenerator.genHeader(), antlr.CppCodeGenerator.genInclude(), antlr.CppCodeGenerator.genInitFactory(), antlr.CppCodeGenerator.genLineNo(), antlr.PythonCodeGenerator.genMatch(), antlr.JavaCodeGenerator.genMatch(), antlr.CSharpCodeGenerator.genMatch(), antlr.CppCodeGenerator.genMatch(), antlr.PythonCodeGenerator.genNextToken(), antlr.JavaCodeGenerator.genNextToken(), antlr.CSharpCodeGenerator.genNextToken(), antlr.CppCodeGenerator.genNextToken(), antlr.PythonCodeGenerator.genRule(), antlr.JavaCodeGenerator.genRule(), antlr.CSharpCodeGenerator.genRule(), antlr.CppCodeGenerator.genRule(), antlr.CppCodeGenerator.genRuleHeader(), antlr.CSharpCodeGenerator.genTokenDefinitions(), antlr.CodeGenerator.genTokenInterchange(), antlr.PythonCodeGenerator.genTokenTypes(), antlr.JavaCodeGenerator.genTokenTypes(), antlr.HTMLCodeGenerator.genTokenTypes(), antlr.DocBookCodeGenerator.genTokenTypes(), antlr.DiagnosticCodeGenerator.genTokenTypes(), antlr.CppCodeGenerator.genTokenTypes(), antlr.CppCodeGenerator.getASTCreateString(), antlr.PythonCodeGenerator.getRangeExpression(), antlr.JavaCodeGenerator.getRangeExpression(), antlr.CSharpCodeGenerator.getRangeExpression(), antlr.CppCodeGenerator.getRangeExpression(), antlr.PythonCodeGenerator.mapTreeId(), antlr.JavaCodeGenerator.mapTreeId(), antlr.CSharpCodeGenerator.mapTreeId(), antlr.CppCodeGenerator.mapTreeId(), antlr.PythonCodeGenerator.processActionCode(), antlr.PythonCodeGenerator.processActionForSpecialSymbols(), antlr.JavaCodeGenerator.processActionForSpecialSymbols(), antlr.CSharpCodeGenerator.processActionForSpecialSymbols(), antlr.CppCodeGenerator.processActionForSpecialSymbols(), antlr.CodeGenerator.setGrammar(), antlr.CodeGenerator.setTool(), antlr.PythonCodeGenerator.setupOutput(), and antlr.CSharpCodeGenerator.setupOutput().

final int antlr.CodeGenerator.BITSET_OPTIMIZE_INIT_THRESHOLD = 8 [static, protected]

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.

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"

Referenced by antlr.PythonCodeGenerator.getLookaheadTestTerm(), antlr.JavaCodeGenerator.getLookaheadTestTerm(), antlr.CSharpCodeGenerator.getLookaheadTestTerm(), antlr.CppCodeGenerator.getLookaheadTestTerm(), and antlr.CodeGenerator.setGrammar().

final int antlr.CodeGenerator.DEFAULT_BITSET_TEST_THRESHOLD = 4 [static, protected]
final int antlr.CodeGenerator.DEFAULT_MAKE_SWITCH_THRESHOLD = 2 [static, protected]

Default values for code-generation thresholds

The grammar for which we generate code

Referenced by antlr.CodeGenerator.extractIdOfAction(), antlr.CodeGenerator.extractTypeOfAction(), antlr.PythonCodeGenerator.gen(), antlr.JavaCodeGenerator.gen(), antlr.HTMLCodeGenerator.gen(), antlr.DocBookCodeGenerator.gen(), antlr.DiagnosticCodeGenerator.gen(), antlr.CSharpCodeGenerator.gen(), antlr.CppCodeGenerator.gen(), antlr.PythonCodeGenerator.genAlt(), antlr.JavaCodeGenerator.genAlt(), antlr.CSharpCodeGenerator.genAlt(), antlr.CppCodeGenerator.genAlt(), antlr.CppCodeGenerator.genBitsets(), antlr.PythonCodeGenerator.genBlockPreamble(), antlr.JavaCodeGenerator.genBlockPreamble(), antlr.CSharpCodeGenerator.genBlockPreamble(), antlr.CppCodeGenerator.genBlockPreamble(), antlr.CSharpCodeGenerator.genBody(), antlr.CppCodeGenerator.genBody(), antlr.PythonCodeGenerator.genCases(), antlr.JavaCodeGenerator.genCases(), antlr.CSharpCodeGenerator.genCases(), antlr.PythonCodeGenerator.genCommonBlock(), antlr.JavaCodeGenerator.genCommonBlock(), antlr.CSharpCodeGenerator.genCommonBlock(), antlr.CppCodeGenerator.genCommonBlock(), antlr.HTMLCodeGenerator.genFollowSetForRuleBlock(), antlr.DocBookCodeGenerator.genFollowSetForRuleBlock(), antlr.DiagnosticCodeGenerator.genFollowSetForRuleBlock(), antlr.PythonCodeGenerator.genHeader(), antlr.JavaCodeGenerator.genHeader(), antlr.HTMLCodeGenerator.genHeader(), antlr.DocBookCodeGenerator.genHeader(), antlr.CSharpCodeGenerator.genHeader(), antlr.CppCodeGenerator.genInclude(), antlr.CppCodeGenerator.genInitFactory(), antlr.PythonCodeGenerator.genLexerTest(), antlr.HTMLCodeGenerator.genLookaheadSetForAlt(), antlr.DocBookCodeGenerator.genLookaheadSetForAlt(), antlr.DiagnosticCodeGenerator.genLookaheadSetForAlt(), antlr.HTMLCodeGenerator.genLookaheadSetForBlock(), antlr.DocBookCodeGenerator.genLookaheadSetForBlock(), antlr.DiagnosticCodeGenerator.genLookaheadSetForBlock(), antlr.PythonCodeGenerator.genMatch(), antlr.JavaCodeGenerator.genMatch(), antlr.CSharpCodeGenerator.genMatch(), antlr.CppCodeGenerator.genMatch(), antlr.PythonCodeGenerator.genMatchUsingAtomText(), antlr.JavaCodeGenerator.genMatchUsingAtomText(), antlr.CSharpCodeGenerator.genMatchUsingAtomText(), antlr.CppCodeGenerator.genMatchUsingAtomText(), antlr.PythonCodeGenerator.genMatchUsingAtomTokenType(), antlr.JavaCodeGenerator.genMatchUsingAtomTokenType(), antlr.CSharpCodeGenerator.genMatchUsingAtomTokenType(), antlr.CppCodeGenerator.genMatchUsingAtomTokenType(), antlr.PythonCodeGenerator.genNextToken(), antlr.JavaCodeGenerator.genNextToken(), antlr.HTMLCodeGenerator.genNextToken(), antlr.DocBookCodeGenerator.genNextToken(), antlr.DiagnosticCodeGenerator.genNextToken(), antlr.CSharpCodeGenerator.genNextToken(), antlr.CppCodeGenerator.genNextToken(), antlr.PythonCodeGenerator.genRule(), antlr.JavaCodeGenerator.genRule(), antlr.DiagnosticCodeGenerator.genRule(), antlr.CSharpCodeGenerator.genRule(), antlr.CppCodeGenerator.genRule(), antlr.PythonCodeGenerator.genSemPred(), antlr.JavaCodeGenerator.genSemPred(), antlr.CSharpCodeGenerator.genSemPred(), antlr.CppCodeGenerator.genSemPred(), antlr.PythonCodeGenerator.genSynPred(), antlr.JavaCodeGenerator.genSynPred(), antlr.CSharpCodeGenerator.genSynPred(), antlr.CppCodeGenerator.genSynPred(), antlr.PythonCodeGenerator.genTokenASTNodeMap(), antlr.JavaCodeGenerator.genTokenASTNodeMap(), antlr.PythonCodeGenerator.genTokenStrings(), antlr.JavaCodeGenerator.genTokenStrings(), antlr.CSharpCodeGenerator.genTokenStrings(), antlr.CppCodeGenerator.genTokenStrings(), antlr.PythonCodeGenerator.getASTCreateString(), antlr.JavaCodeGenerator.getASTCreateString(), antlr.CSharpCodeGenerator.getASTCreateString(), antlr.CppCodeGenerator.getASTCreateString(), antlr.CodeGenerator.getFIRSTBitSet(), antlr.CodeGenerator.getFOLLOWBitSet(), antlr.PythonCodeGenerator.getLookaheadTestExpression(), antlr.JavaCodeGenerator.getLookaheadTestExpression(), antlr.CSharpCodeGenerator.getLookaheadTestExpression(), antlr.CppCodeGenerator.getLookaheadTestExpression(), antlr.CSharpCodeGenerator.getTokenTypesClassName(), antlr.PythonCodeGenerator.lookaheadIsEmpty(), antlr.JavaCodeGenerator.lookaheadIsEmpty(), antlr.CSharpCodeGenerator.lookaheadIsEmpty(), antlr.CppCodeGenerator.lookaheadIsEmpty(), antlr.PythonCodeGenerator.mapTreeId(), antlr.JavaCodeGenerator.mapTreeId(), antlr.CSharpCodeGenerator.mapTreeId(), antlr.CppCodeGenerator.mapTreeId(), antlr.HTMLCodeGenerator.printSet(), antlr.DocBookCodeGenerator.printSet(), antlr.DiagnosticCodeGenerator.printSet(), antlr.PythonCodeGenerator.processActionCode(), antlr.PythonCodeGenerator.processActionForSpecialSymbols(), antlr.JavaCodeGenerator.processActionForSpecialSymbols(), antlr.CSharpCodeGenerator.processActionForSpecialSymbols(), antlr.CppCodeGenerator.processActionForSpecialSymbols(), antlr.CSharpCodeGenerator.processStringForASTConstructor(), antlr.CppCodeGenerator.processStringForASTConstructor(), and antlr.CodeGenerator.setGrammar().

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"

Referenced by antlr.PythonCodeGenerator.genCommonBlock(), antlr.JavaCodeGenerator.genCommonBlock(), antlr.CSharpCodeGenerator.genCommonBlock(), antlr.CppCodeGenerator.genCommonBlock(), and antlr.CodeGenerator.setGrammar().

int antlr.CodeGenerator.tabs = 0 [protected]

Current tab indentation for code output

Referenced by antlr.PythonCodeGenerator.gen(), antlr.JavaCodeGenerator.gen(), antlr.HTMLCodeGenerator.gen(), antlr.DocBookCodeGenerator.gen(), antlr.DiagnosticCodeGenerator.gen(), antlr.CSharpCodeGenerator.gen(), antlr.CppCodeGenerator.gen(), antlr.PythonCodeGenerator.genAlt(), antlr.JavaCodeGenerator.genAlt(), antlr.CSharpCodeGenerator.genAlt(), antlr.CppCodeGenerator.genAlt(), antlr.CSharpCodeGenerator.genBody(), antlr.CppCodeGenerator.genBody(), antlr.PythonCodeGenerator.genCommonBlock(), antlr.JavaCodeGenerator.genCommonBlock(), antlr.HTMLCodeGenerator.genCommonBlock(), antlr.DocBookCodeGenerator.genCommonBlock(), antlr.DiagnosticCodeGenerator.genCommonBlock(), antlr.CSharpCodeGenerator.genCommonBlock(), antlr.CppCodeGenerator.genCommonBlock(), antlr.DiagnosticCodeGenerator.genHeader(), antlr.PythonCodeGenerator.genHeaderInit(), antlr.PythonCodeGenerator.genHeaderMain(), antlr.CSharpCodeGenerator.genInitFactory(), antlr.CppCodeGenerator.genInitFactory(), antlr.PythonCodeGenerator.genLexerTest(), antlr.PythonCodeGenerator.genNextToken(), antlr.CSharpCodeGenerator.genNextToken(), antlr.PythonCodeGenerator.genRule(), antlr.HTMLCodeGenerator.genRule(), antlr.DocBookCodeGenerator.genRule(), antlr.DiagnosticCodeGenerator.genRule(), antlr.CSharpCodeGenerator.genRule(), antlr.PythonCodeGenerator.genSemPred(), antlr.PythonCodeGenerator.genSemPredMap(), antlr.CSharpCodeGenerator.genSemPredMap(), antlr.PythonCodeGenerator.genSynPred(), antlr.CSharpCodeGenerator.genSynPred(), antlr.PythonCodeGenerator.genTokenASTNodeMap(), antlr.CodeGenerator.genTokenInterchange(), antlr.PythonCodeGenerator.genTokenStrings(), antlr.CSharpCodeGenerator.genTokenStrings(), antlr.PythonCodeGenerator.genTokenTypes(), antlr.HTMLCodeGenerator.genTokenTypes(), antlr.DocBookCodeGenerator.genTokenTypes(), antlr.DiagnosticCodeGenerator.genTokenTypes(), antlr.CSharpCodeGenerator.genTokenTypes(), antlr.PythonCodeGenerator.printMainFunc(), antlr.HTMLCodeGenerator.printSet(), antlr.DocBookCodeGenerator.printSet(), antlr.DiagnosticCodeGenerator.printSet(), antlr.PythonCodeGenerator.printTabs(), and antlr.CodeGenerator.printTabs().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties