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

antlr.JavaCodeGenerator Class Reference

Inheritance diagram for antlr.JavaCodeGenerator:
antlr.CodeGenerator

List of all members.

Public Member Functions

 JavaCodeGenerator ()
void println (String code)
void println (String code, int sourceStartLine)
void exitIfError ()
void gen ()
void gen (ActionElement action)
void gen (AlternativeBlock blk)
void gen (BlockEndElement end)
void gen (CharLiteralElement atom)
void gen (CharRangeElement r)
void gen (LexerGrammar g) throws IOException
void gen (OneOrMoreBlock blk)
void gen (ParserGrammar g) throws IOException
void gen (RuleRefElement rr)
void gen (StringLiteralElement atom)
void gen (TokenRangeElement r)
void gen (TokenRefElement atom)
void gen (TreeElement t)
void gen (TreeWalkerGrammar g) throws IOException
void gen (WildcardElement wc)
void gen (ZeroOrMoreBlock blk)
JavaBlockFinishingInfo genCommonBlock (AlternativeBlock blk, boolean noTestForSingle)
void genNextToken ()
void genRule (RuleSymbol s, boolean startSymbol, int ruleNum)
void genTokenStrings ()
String getASTCreateString (Vector v)
String getASTCreateString (GrammarAtom atom, String astCtorArgs)
String getASTCreateString (String astCtorArgs)
String getRangeExpression (int k, int[] elems)
String mapTreeId (String idParam, ActionTransInfo transInfo)
JavaCodeGeneratorPrintWriterManager getPrintWriterManager ()
void setPrintWriterManager (JavaCodeGeneratorPrintWriterManager printWriterManager)
void setTool (Tool tool)

Static Public Attributes

static final int NO_MAPPING = -999
static final int CONTINUE_LAST_MAPPING = -888
static final int caseSizeThreshold = 127

Protected Member Functions

void printAction (String code)
void printAction (String code, int sourceStartLine)
void print (String code)
void print (String code, int sourceStartLine)
void _print (String code)
void _print (String code, int sourceStartLine)
void _println (String code)
void _println (String code, int sourceStartLine)
int addSemPred (String predicate)
void genAlt (Alternative alt, AlternativeBlock blk)
void genBitsets (Vector bitsetList, int maxVocabulary)
void genBlockInitAction (AlternativeBlock blk)
void genBlockPreamble (AlternativeBlock blk)
void genCases (BitSet p, int line)
void genASTDeclaration (AlternativeElement el)
void genASTDeclaration (AlternativeElement el, String node_type)
void genASTDeclaration (AlternativeElement el, String var_name, String node_type)
void genHeader ()
void genMatch (BitSet b)
void genMatch (GrammarAtom atom)
void genMatchUsingAtomText (GrammarAtom atom)
void genMatchUsingAtomTokenType (GrammarAtom atom)
void genSemPred (String pred, int line)
void genSemPredMap ()
void genSynPred (SynPredBlock blk, String lookaheadExpr)
void genTokenASTNodeMap ()
void genTokenTypes (TokenManager tm) throws IOException
String getLookaheadTestExpression (Lookahead[] look, int k)
String getLookaheadTestExpression (Alternative alt, int maxDepth)
String getLookaheadTestTerm (int k, BitSet p)
boolean lookaheadIsEmpty (Alternative alt, int maxDepth)
String processActionForSpecialSymbols (String actionStr, int line, RuleBlock currentRule, ActionTransInfo tInfo)

Protected Attributes

int syntacticPredLevel = 0
boolean genAST = false
boolean saveText = false

Static Protected Attributes

static final String NONUNIQUE = new String()

Package Attributes

String labeledElementType
String labeledElementASTType
String labeledElementInit
String commonExtraArgs
String commonExtraParams
String commonLocalVars
String lt1Value
String exceptionThrown
String throwNoViable
RuleBlock currentRule
String currentASTResult
Hashtable treeVariableMap = new Hashtable()
Hashtable declaredASTVariables = new Hashtable()
int astVarNumber = 1

Detailed Description

Generate MyParser.java, MyLexer.java and MyParserTokenTypes.java


Constructor & Destructor Documentation

antlr.JavaCodeGenerator.JavaCodeGenerator (  ) 

Create a Java code-generator using the given Grammar. The caller must still call setTool, setBehavior, and setAnalyzer before generating code.

References antlr.CodeGenerator.charFormatter.


Member Function Documentation

void antlr.JavaCodeGenerator._print ( String  s  )  [protected]

Output a String to the currentOutput stream. Ignored if string is null.

Parameters:
s The string to output

Reimplemented from antlr.CodeGenerator.

Referenced by antlr.JavaCodeGenerator.gen(), antlr.JavaCodeGenerator.genCases(), antlr.JavaCodeGenerator.genMatchUsingAtomText(), antlr.JavaCodeGenerator.genRule(), and antlr.JavaCodeGenerator.genTokenStrings().

void antlr.JavaCodeGenerator._println ( String  s  )  [protected]
int antlr.JavaCodeGenerator.addSemPred ( String  predicate  )  [protected]

Adds a semantic predicate string to the sem pred vector These strings will be used to build an array of sem pred names when building a debugging parser. This method should only be called when the debug option is specified

References antlr.collections.impl.Vector.appendElement(), and antlr.collections.impl.Vector.size().

Referenced by antlr.JavaCodeGenerator.genCommonBlock(), and antlr.JavaCodeGenerator.genSemPred().

void antlr.JavaCodeGenerator.exitIfError (  ) 
void antlr.JavaCodeGenerator.gen ( BlockEndElement  end  )  [virtual]

Generate code for the given grammar element.

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

Implements antlr.CodeGenerator.

References antlr.CodeGenerator.DEBUG_CODE_GENERATOR.

void antlr.JavaCodeGenerator.gen ( CharLiteralElement  atom  )  [virtual]
void antlr.JavaCodeGenerator.gen ( LexerGrammar  g  )  throws IOException [virtual]

Generate the lexer Java file

Implements antlr.CodeGenerator.

References antlr.JavaCodeGenerator._println(), antlr.CodeGenerator.antlrTool, antlr.CodeGenerator.behavior, antlr.CodeGenerator.bitsetsUsed, antlr.Grammar.classMemberAction, antlr.Grammar.comment, antlr.CodeGenerator.currentOutput, antlr.JavaCodeGenerator.currentRule, antlr.Grammar.debuggingOutput, antlr.collections.impl.Vector.elements(), antlr.JavaCodeGenerator.exitIfError(), antlr.JavaCodeGeneratorPrintWriterManager.finishOutput(), antlr.JavaCodeGenerator.genAST, antlr.JavaCodeGenerator.genBitsets(), antlr.JavaCodeGenerator.genHeader(), antlr.JavaCodeGenerator.genNextToken(), antlr.JavaCodeGenerator.genRule(), antlr.JavaCodeGenerator.genSemPredMap(), antlr.Grammar.getClassName(), antlr.DefineGrammarSymbols.getHeaderAction(), antlr.DefineGrammarSymbols.getHeaderActionLine(), antlr.GrammarSymbol.getId(), antlr.Token.getLine(), antlr.TokenManager.getName(), antlr.JavaCodeGenerator.getPrintWriterManager(), antlr.Grammar.getSuperClass(), antlr.Token.getText(), antlr.TokenManager.getTokenSymbol(), antlr.TokenManager.getTokenSymbolKeys(), antlr.TokenSymbol.getTokenType(), antlr.CodeGenerator.grammar, antlr.JavaCodeGenerator.NO_MAPPING, antlr.Grammar.options, antlr.Tool.panic(), antlr.Grammar.preambleAction, antlr.JavaCodeGenerator.print(), antlr.JavaCodeGenerator.println(), antlr.JavaCodeGenerator.processActionForSpecialSymbols(), antlr.Grammar.rules, antlr.JavaCodeGenerator.saveText, antlr.CodeGenerator.setGrammar(), antlr.JavaCodeGeneratorPrintWriterManager.setupOutput(), antlr.collections.impl.Vector.size(), antlr.Grammar.superClass, antlr.CodeGenerator.tabs, antlr.Grammar.tokenManager, and antlr.CodeGenerator.TokenTypesFileSuffix.

void antlr.JavaCodeGenerator.gen ( ParserGrammar  g  )  throws IOException [virtual]

Generate the parser Java file

Implements antlr.CodeGenerator.

References antlr.JavaCodeGenerator._println(), antlr.CodeGenerator.antlrTool, antlr.CodeGenerator.behavior, antlr.CodeGenerator.bitsetsUsed, antlr.Grammar.buildAST, antlr.Grammar.classMemberAction, antlr.Grammar.comment, antlr.CodeGenerator.currentOutput, antlr.JavaCodeGenerator.currentRule, antlr.Grammar.debuggingOutput, antlr.collections.impl.Vector.elements(), antlr.JavaCodeGenerator.exitIfError(), antlr.JavaCodeGeneratorPrintWriterManager.finishOutput(), antlr.JavaCodeGenerator.genAST, antlr.JavaCodeGenerator.genBitsets(), antlr.JavaCodeGenerator.genHeader(), antlr.JavaCodeGenerator.genRule(), antlr.JavaCodeGenerator.genSemPredMap(), antlr.JavaCodeGenerator.genTokenASTNodeMap(), antlr.JavaCodeGenerator.genTokenStrings(), antlr.Grammar.getClassName(), antlr.DefineGrammarSymbols.getHeaderAction(), antlr.DefineGrammarSymbols.getHeaderActionLine(), antlr.Token.getLine(), antlr.TokenManager.getName(), antlr.JavaCodeGenerator.getPrintWriterManager(), antlr.Grammar.getSuperClass(), antlr.Token.getText(), antlr.CodeGenerator.grammar, antlr.Grammar.maxk, antlr.TokenManager.maxTokenType(), antlr.JavaCodeGenerator.NO_MAPPING, antlr.Grammar.options, antlr.Tool.panic(), antlr.Grammar.preambleAction, antlr.JavaCodeGenerator.print(), antlr.JavaCodeGenerator.println(), antlr.JavaCodeGenerator.processActionForSpecialSymbols(), antlr.RuleSymbol.references, antlr.Grammar.rules, antlr.CodeGenerator.setGrammar(), antlr.JavaCodeGeneratorPrintWriterManager.setupOutput(), antlr.collections.impl.Vector.size(), antlr.Grammar.superClass, antlr.CodeGenerator.tabs, antlr.Grammar.tokenManager, and antlr.CodeGenerator.TokenTypesFileSuffix.

void antlr.JavaCodeGenerator.gen ( TokenRangeElement  r  )  [virtual]
void antlr.JavaCodeGenerator.gen ( TreeWalkerGrammar  g  )  throws IOException [virtual]

Generate the tree-parser Java file

Implements antlr.CodeGenerator.

References antlr.JavaCodeGenerator._println(), antlr.CodeGenerator.antlrTool, antlr.CodeGenerator.behavior, antlr.CodeGenerator.bitsetsUsed, antlr.Grammar.buildAST, antlr.Grammar.classMemberAction, antlr.Grammar.comment, antlr.CodeGenerator.currentOutput, antlr.JavaCodeGenerator.currentRule, antlr.collections.impl.Vector.elements(), antlr.JavaCodeGenerator.exitIfError(), antlr.JavaCodeGeneratorPrintWriterManager.finishOutput(), antlr.JavaCodeGenerator.genAST, antlr.JavaCodeGenerator.genBitsets(), antlr.JavaCodeGenerator.genHeader(), antlr.JavaCodeGenerator.genRule(), antlr.JavaCodeGenerator.genTokenStrings(), antlr.Grammar.getClassName(), antlr.DefineGrammarSymbols.getHeaderAction(), antlr.DefineGrammarSymbols.getHeaderActionLine(), antlr.Token.getLine(), antlr.TokenManager.getName(), antlr.JavaCodeGenerator.getPrintWriterManager(), antlr.Grammar.getSuperClass(), antlr.Token.getText(), antlr.CodeGenerator.grammar, antlr.TokenManager.maxTokenType(), antlr.JavaCodeGenerator.NO_MAPPING, antlr.Grammar.options, antlr.Tool.panic(), antlr.Grammar.preambleAction, antlr.JavaCodeGenerator.print(), antlr.JavaCodeGenerator.println(), antlr.JavaCodeGenerator.processActionForSpecialSymbols(), antlr.RuleSymbol.references, antlr.Grammar.rules, antlr.CodeGenerator.setGrammar(), antlr.JavaCodeGeneratorPrintWriterManager.setupOutput(), antlr.collections.impl.Vector.size(), antlr.Grammar.superClass, antlr.CodeGenerator.tabs, antlr.Grammar.tokenManager, and antlr.CodeGenerator.TokenTypesFileSuffix.

void antlr.JavaCodeGenerator.genASTDeclaration ( AlternativeElement  el  )  [protected]
void antlr.JavaCodeGenerator.genASTDeclaration ( AlternativeElement  el,
String  node_type 
) [protected]
void antlr.JavaCodeGenerator.genASTDeclaration ( AlternativeElement  el,
String  var_name,
String  node_type 
) [protected]
void antlr.JavaCodeGenerator.genBitsets ( Vector  bitsetList,
int  maxVocabulary 
) [protected]

Generate all the bitsets to be used in the parser or lexer Generate the raw bitset data like "long _tokenSet1_data[] = {...};" and the BitSet object declarations like "BitSet _tokenSet1 = new BitSet(_tokenSet1_data);" Note that most languages do not support object initialization inside a class definition, so other code-generators may have to separate the bitset declarations from the initializations (e.g., put the initializations in the generated constructor instead).

Parameters:
bitsetList The list of bitsets to generate.
maxVocabulary Ensure that each generated bitset can contain at least this value.

References antlr.collections.impl.Vector.elementAt(), antlr.collections.impl.BitSet.growToInclude(), antlr.JavaCodeGenerator.NO_MAPPING, antlr.JavaCodeGenerator.println(), and antlr.collections.impl.Vector.size().

Referenced by antlr.JavaCodeGenerator.gen().

void antlr.JavaCodeGenerator.genBlockInitAction ( AlternativeBlock  blk  )  [protected]

Generate the init action for a block, which may be a RuleBlock or a plain AlternativeBLock. The block for which the preamble is to be generated.

References antlr.JavaCodeGenerator.currentRule, antlr.GrammarElement.getLine(), antlr.AlternativeBlock.initAction, antlr.JavaCodeGenerator.printAction(), and antlr.JavaCodeGenerator.processActionForSpecialSymbols().

Referenced by antlr.JavaCodeGenerator.gen(), and antlr.JavaCodeGenerator.genRule().

void antlr.JavaCodeGenerator.genCases ( BitSet  p,
int  line 
) [protected]

Generate a series of case statements that implement a BitSet test.

Parameters:
p The Bitset for which cases are to be generated

References antlr.JavaCodeGenerator._print(), antlr.JavaCodeGenerator._println(), antlr.CodeGenerator.DEBUG_CODE_GENERATOR, antlr.CodeGenerator.grammar, antlr.JavaCodeGenerator.print(), and antlr.collections.impl.BitSet.toArray().

Referenced by antlr.JavaCodeGenerator.genCommonBlock().

JavaBlockFinishingInfo antlr.JavaCodeGenerator.genCommonBlock ( AlternativeBlock  blk,
boolean  noTestForSingle 
)

Generate common code for a block of alternatives; return a postscript that needs to be generated at the end of the block. Other routines may append else-clauses and such for error checking before the postfix is generated. If the grammar is a lexer, then generate alternatives in an order where alternatives requiring deeper lookahead are generated first, and EOF in the lookahead set reduces the depth of the lookahead.

Parameters:
blk The block to generate
noTestForSingle If true, then it does not generate a test for a single alternative.

References antlr.JavaCodeGenerator.addSemPred(), antlr.AlternativeBlock.alternatives, antlr.CodeGenerator.analyzer, antlr.CodeGenerator.antlrTool, antlr.Alternative.cache, antlr.JavaCodeGenerator.caseSizeThreshold, antlr.CodeGenerator.charFormatter, antlr.Lookahead.containsEpsilon(), antlr.JavaCodeGenerator.currentRule, antlr.CodeGenerator.DEBUG_CODE_GENERATOR, antlr.Grammar.debuggingOutput, antlr.collections.impl.BitSet.degree(), antlr.CharFormatter.escapeString(), antlr.Lookahead.fset, antlr.JavaCodeGenerator.genAlt(), antlr.JavaCodeGenerator.genAST, antlr.JavaCodeGenerator.genCases(), antlr.JavaBlockFinishingInfo.generatedAnIf, antlr.JavaBlockFinishingInfo.generatedSwitch, antlr.JavaCodeGenerator.genSemPred(), antlr.JavaCodeGenerator.genSynPred(), antlr.AlternativeBlock.getAlternativeAt(), antlr.AlternativeBlock.getAlternatives(), antlr.AlternativeBlock.getAutoGen(), antlr.CodeGenerator.getBitsetName(), antlr.GrammarElement.getColumn(), antlr.Grammar.getFilename(), antlr.AlternativeBlock.getLabel(), antlr.GrammarElement.getLine(), antlr.JavaCodeGenerator.getLookaheadTestExpression(), antlr.CodeGenerator.grammar, antlr.Alternative.head, antlr.GrammarElement.line, antlr.LLkGrammarAnalyzer.look(), antlr.Alternative.lookaheadDepth, antlr.JavaCodeGenerator.lookaheadIsEmpty(), antlr.JavaCodeGenerator.lt1Value, antlr.CodeGenerator.makeSwitchThreshold, antlr.CodeGenerator.markBitsetForGen(), antlr.Grammar.maxk, antlr.JavaBlockFinishingInfo.needAnErrorClause, antlr.JavaCodeGenerator.NO_MAPPING, antlr.AlternativeBlock.not, antlr.JavaBlockFinishingInfo.postscript, antlr.JavaCodeGenerator.println(), antlr.JavaCodeGenerator.processActionForSpecialSymbols(), antlr.JavaCodeGenerator.saveText, antlr.Alternative.semPred, antlr.collections.impl.Vector.size(), antlr.LLkGrammarAnalyzer.subruleCanBeInverted(), antlr.Alternative.synPred, antlr.JavaCodeGenerator.syntacticPredLevel, antlr.CodeGenerator.tabs, and antlr.Tool.warning().

Referenced by antlr.JavaCodeGenerator.gen(), antlr.JavaCodeGenerator.genNextToken(), and antlr.JavaCodeGenerator.genRule().

void antlr.JavaCodeGenerator.genMatch ( BitSet  b  )  [protected]
void antlr.JavaCodeGenerator.genMatchUsingAtomTokenType ( GrammarAtom  atom  )  [protected]
void antlr.JavaCodeGenerator.genRule ( RuleSymbol  s,
boolean  startSymbol,
int  ruleNum 
)

Gen a named rule block. ASTs are generated for each element of an alternative unless the rule or the alternative have a '!' modifier.

If an alternative defeats the default tree construction, it must set <rule>_AST to the root of the returned AST.

Each alternative that does automatic tree construction, builds up root and child list pointers in an ASTPair structure.

A rule finishes by setting the returnAST variable from the ASTPair.

Parameters:
rule The name of the rule to generate
startSymbol true if the rule is a start symbol (i.e., not referenced elsewhere)

References antlr.JavaCodeGenerator._print(), antlr.JavaCodeGenerator._println(), antlr.RuleSymbol.access, antlr.AlternativeBlock.alternatives, antlr.CodeGenerator.antlrTool, antlr.RuleBlock.argAction, antlr.Grammar.buildAST, antlr.RuleSymbol.comment, antlr.JavaCodeGenerator.commonExtraParams, antlr.JavaCodeGenerator.commonLocalVars, antlr.JavaCodeGenerator.currentASTResult, antlr.JavaCodeGenerator.currentRule, antlr.CodeGenerator.DEBUG_CODE_GENERATOR, antlr.Grammar.debuggingOutput, antlr.JavaCodeGenerator.declaredASTVariables, antlr.LLkGrammarAnalyzer.deterministic(), antlr.RuleBlock.endNode, antlr.Tool.error(), antlr.JavaCodeGenerator.exceptionThrown, antlr.CodeGenerator.extractIdOfAction(), antlr.CodeGenerator.extractTypeOfAction(), antlr.RuleBlock.findExceptionSpec(), antlr.LLkGrammarAnalyzer.FOLLOW(), antlr.Lookahead.fset, antlr.JavaCodeGenerator.genAlt(), antlr.JavaCodeGenerator.genAST, antlr.JavaCodeGenerator.genBlockInitAction(), antlr.JavaCodeGenerator.genBlockPreamble(), antlr.JavaCodeGenerator.genCommonBlock(), antlr.JavaCodeGenerator.genSemPred(), antlr.AlternativeBlock.getAlternativeAt(), antlr.AlternativeBlock.getAutoGen(), antlr.CodeGenerator.getBitsetName(), antlr.RuleSymbol.getBlock(), antlr.GrammarElement.getColumn(), antlr.RuleBlock.getDefaultErrorHandler(), antlr.Grammar.getFilename(), antlr.GrammarSymbol.getId(), antlr.GrammarElement.getLine(), antlr.RuleBlock.getTestLiterals(), antlr.CodeGenerator.grammar, antlr.Grammar.hasSyntacticPredicate, antlr.RuleSymbol.isDefined(), antlr.JavaCodeGenerator.labeledElementASTType, antlr.GrammarElement.line, antlr.CodeGenerator.markBitsetForGen(), antlr.JavaCodeGenerator.NO_MAPPING, antlr.JavaCodeGenerator.print(), antlr.JavaCodeGenerator.println(), antlr.RuleBlock.returnAction, antlr.RuleBlock.ruleName, antlr.JavaCodeGenerator.saveText, antlr.Alternative.semPred, antlr.collections.impl.Vector.size(), antlr.Alternative.synPred, antlr.Grammar.theLLkAnalyzer, antlr.JavaCodeGenerator.throwNoViable, antlr.RuleBlock.throwsSpec, antlr.Grammar.traceRules, and antlr.Tool.warning().

Referenced by antlr.JavaCodeGenerator.gen().

void antlr.JavaCodeGenerator.genSemPredMap (  )  [protected]

Write an array of Strings which are the semantic predicate expressions. The debugger will reference them by number only

References antlr.collections.impl.Vector.elements(), antlr.JavaCodeGenerator.NO_MAPPING, and antlr.JavaCodeGenerator.println().

Referenced by antlr.JavaCodeGenerator.gen().

void antlr.JavaCodeGenerator.genTokenStrings (  ) 

Generate a static array containing the names of the tokens, indexed by the token type values. This static array is used to format error messages so that the token identifers or literal strings are displayed instead of the token numbers.

If a lexical rule has a paraphrase, use it rather than the token label.

References antlr.JavaCodeGenerator._print(), antlr.JavaCodeGenerator._println(), antlr.CodeGenerator.charFormatter, antlr.collections.impl.Vector.elementAt(), antlr.TokenSymbol.getParaphrase(), antlr.TokenManager.getTokenSymbol(), antlr.TokenManager.getVocabulary(), antlr.CodeGenerator.grammar, antlr.CharFormatter.literalString(), antlr.JavaCodeGenerator.NO_MAPPING, antlr.JavaCodeGenerator.print(), antlr.JavaCodeGenerator.println(), antlr.collections.impl.Vector.size(), and antlr.Grammar.tokenManager.

Referenced by antlr.JavaCodeGenerator.gen().

String antlr.JavaCodeGenerator.getASTCreateString ( Vector  v  )  [virtual]

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.

Implements antlr.CodeGenerator.

References antlr.collections.impl.Vector.elementAt(), antlr.JavaCodeGenerator.labeledElementASTType, and antlr.collections.impl.Vector.size().

Referenced by antlr.JavaCodeGenerator.getASTCreateString().

String antlr.JavaCodeGenerator.getASTCreateString ( GrammarAtom  atom,
String  astCtorArgs 
) [virtual]

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

Parameters:
atom The grammar node for which you are creating the node
str The arguments to the AST constructor

Implements antlr.CodeGenerator.

References antlr.JavaCodeGenerator.getASTCreateString(), and antlr.GrammarAtom.getASTNodeType().

String antlr.JavaCodeGenerator.getASTCreateString ( String  astCtorArgs  ) 

Get a string for an expression to generate creating of an AST node. Parse the first (possibly only) argument looking for the token type. If the token type is a valid token symbol, ask for it's AST node type and add to the end if only 2 arguments. The forms are #[T], #[T,"t"], and as of 2.7.2 #[T,"t",ASTclassname].

Parameters:
str The arguments to the AST constructor

References antlr.TokenSymbol.getASTNodeType(), antlr.TokenManager.getTokenSymbol(), antlr.CodeGenerator.grammar, antlr.JavaCodeGenerator.labeledElementASTType, and antlr.Grammar.tokenManager.

String antlr.JavaCodeGenerator.getLookaheadTestExpression ( Alternative  alt,
int  maxDepth 
) [protected]

Generate a lookahead test expression for an alternate. This will be a series of tests joined by '&&' and enclosed by '()', the number of such tests being determined by the depth of the lookahead.

References antlr.Alternative.cache, antlr.JavaCodeGenerator.getLookaheadTestExpression(), antlr.CodeGenerator.grammar, antlr.Alternative.lookaheadDepth, and antlr.Grammar.maxk.

String antlr.JavaCodeGenerator.getLookaheadTestTerm ( int  k,
BitSet  p 
) [protected]

Generate a depth==1 lookahead test expression given the BitSet. This may be one of: 1) a series of 'x==X||' tests 2) a range test using >= && <= where possible, 3) a bitset membership test for complex comparisons

Parameters:
k The lookahead level
p The lookahead set for level k

References antlr.CodeGenerator.bitsetTestThreshold, antlr.collections.impl.BitSet.degree(), antlr.CodeGenerator.elementsAreRange(), antlr.CodeGenerator.getBitsetName(), antlr.JavaCodeGenerator.getRangeExpression(), antlr.CodeGenerator.markBitsetForGen(), and antlr.collections.impl.BitSet.toArray().

Referenced by antlr.JavaCodeGenerator.getLookaheadTestExpression().

String antlr.JavaCodeGenerator.getRangeExpression ( int  k,
int[]  elems 
)

Return an expression for testing a contiguous renage of elements

Parameters:
k The lookahead level
elems The elements representing the set, usually from BitSet.toArray().
Returns:
String containing test expression.

References antlr.CodeGenerator.antlrTool, antlr.CodeGenerator.elementsAreRange(), and antlr.Tool.panic().

Referenced by antlr.JavaCodeGenerator.getLookaheadTestTerm().

boolean antlr.JavaCodeGenerator.lookaheadIsEmpty ( Alternative  alt,
int  maxDepth 
) [protected]
String antlr.JavaCodeGenerator.mapTreeId ( String  idParam,
ActionTransInfo  transInfo 
) [virtual]

Map an identifier to it's corresponding tree-node variable. This is context-sensitive, depending on the rule and alternative being generated

Parameters:
idParam The identifier name to map
Returns:
The mapped id (which may be the same as the input), or null if the mapping is invalid due to duplicates

Implements antlr.CodeGenerator.

References antlr.CodeGenerator.antlrTool, antlr.Grammar.buildAST, antlr.JavaCodeGenerator.currentRule, antlr.collections.impl.Vector.elementAt(), antlr.Tool.error(), antlr.AlternativeElement.getLabel(), antlr.RuleBlock.getRuleName(), antlr.CodeGenerator.grammar, antlr.RuleBlock.labeledElements, antlr.JavaCodeGenerator.NONUNIQUE, antlr.ActionTransInfo.refRuleRoot, antlr.collections.impl.Vector.size(), and antlr.JavaCodeGenerator.treeVariableMap.

void antlr.JavaCodeGenerator.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 from antlr.CodeGenerator.

Referenced by antlr.JavaCodeGenerator.gen(), antlr.JavaCodeGenerator.genCases(), antlr.JavaCodeGenerator.genMatchUsingAtomText(), antlr.JavaCodeGenerator.genRule(), and antlr.JavaCodeGenerator.genTokenStrings().

void antlr.JavaCodeGenerator.printAction ( String  code,
int  sourceStartLine 
) [protected]
void antlr.JavaCodeGenerator.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 from antlr.CodeGenerator.

Referenced by antlr.JavaCodeGenerator.gen(), and antlr.JavaCodeGenerator.genBlockInitAction().

String antlr.JavaCodeGenerator.processActionForSpecialSymbols ( String  actionStr,
int  line,
RuleBlock  currentRule,
ActionTransInfo  tInfo 
) [protected, virtual]

Lexically process $var and tree-specifiers in the action. This will replace id and #(...) with the appropriate function calls and/or variables etc...

Implements antlr.CodeGenerator.

References antlr.CodeGenerator.antlrTool, antlr.Grammar.buildAST, antlr.Grammar.getFilename(), antlr.CodeGenerator.grammar, and antlr.Tool.panic().

Referenced by antlr.JavaCodeGenerator.gen(), antlr.JavaCodeGenerator.genBlockInitAction(), antlr.JavaCodeGenerator.genCommonBlock(), and antlr.JavaCodeGenerator.genSemPred().

void antlr.JavaCodeGenerator.setPrintWriterManager ( JavaCodeGeneratorPrintWriterManager  printWriterManager  ) 

Set the print writer manager

Parameters:
printWriterManager the new manager
void antlr.JavaCodeGenerator.setTool ( Tool  tool  ) 

Reimplemented from antlr.CodeGenerator.


Member Data Documentation

Constant to indicate that we should continue mapping based on the last mapping seen by the SMAP generator (there may have been intermediate mappings generated by nested elements)

Referenced by antlr.JavaCodeGenerator._print(), antlr.JavaCodeGenerator._println(), antlr.JavaCodeGenerator.gen(), antlr.JavaCodeGenerator.genAlt(), antlr.JavaCodeGenerator.print(), and antlr.JavaCodeGenerator.println().

Tracks the rule or labeled subrule being generated. Used for AST generation.

Referenced by antlr.JavaCodeGenerator.gen(), and antlr.JavaCodeGenerator.genRule().

Hashtable antlr.JavaCodeGenerator.declaredASTVariables = new Hashtable() [package]

Used to keep track of which AST variables have been defined in a rule (except for the rule_name and rule_name_in var's

Referenced by antlr.JavaCodeGenerator.genASTDeclaration(), and antlr.JavaCodeGenerator.genRule().

final String antlr.JavaCodeGenerator.NONUNIQUE = new String() [static, protected]

Special value used to mark duplicate in treeVariableMap

Referenced by antlr.JavaCodeGenerator.mapTreeId().

Hashtable antlr.JavaCodeGenerator.treeVariableMap = new Hashtable() [package]

Mapping between the ids used in the current alt, and the names of variables used to represent their AST values.

Referenced by antlr.JavaCodeGenerator.genAlt(), and antlr.JavaCodeGenerator.mapTreeId().


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