Package antlr
Class DiagnosticCodeGenerator
- java.lang.Object
-
- antlr.CodeGenerator
-
- antlr.DiagnosticCodeGenerator
-
public class DiagnosticCodeGenerator extends CodeGenerator
Generate MyParser.txt, MyLexer.txt and MyParserTokenTypes.txt
-
-
Field Summary
Fields Modifier and Type Field Description protected booleandoingLexRulestrue during lexer generation, false during parser generationprotected intsyntacticPredLevelnon-zero if inside syntactic predicate generation-
Fields inherited from class antlr.CodeGenerator
analyzer, antlrTool, behavior, BITSET_OPTIMIZE_INIT_THRESHOLD, bitsetsUsed, bitsetTestThreshold, charFormatter, currentOutput, DEBUG_CODE_GENERATOR, DEFAULT_BITSET_TEST_THRESHOLD, DEFAULT_MAKE_SWITCH_THRESHOLD, grammar, makeSwitchThreshold, tabs, TokenTypesFileExt, TokenTypesFileSuffix
-
-
Constructor Summary
Constructors Constructor Description DiagnosticCodeGenerator()Create a Diagnostic code-generator using the given Grammar The caller must still call setTool, setBehavior, and setAnalyzer before generating code.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidgen()Generate the parser, lexer, and token types documentationvoidgen(ActionElement action)Generate code for the given grammar element.voidgen(AlternativeBlock blk)Generate code for the given grammar element.voidgen(BlockEndElement end)Generate code for the given grammar element.voidgen(CharLiteralElement atom)Generate code for the given grammar element.voidgen(CharRangeElement r)Generate code for the given grammar element.voidgen(LexerGrammar g)Generate the lexer TXT filevoidgen(OneOrMoreBlock blk)Generate code for the given grammar element.voidgen(ParserGrammar g)Generate the parser TXT filevoidgen(RuleRefElement rr)Generate code for the given grammar element.voidgen(StringLiteralElement atom)Generate code for the given grammar element.voidgen(TokenRangeElement r)Generate code for the given grammar element.voidgen(TokenRefElement atom)Generate code for the given grammar element.voidgen(TreeElement t)Generate code for the given grammar element.voidgen(TreeWalkerGrammar g)Generate the tree-walker TXT filevoidgen(WildcardElement wc)Generate a wildcard elementvoidgen(ZeroOrMoreBlock blk)Generate code for the given grammar element.protected voidgenAlt(Alternative alt)protected voidgenBlockPreamble(AlternativeBlock blk)Generate the header for a block, which may be a RuleBlock or a plain AlternativeBLock.voidgenCommonBlock(AlternativeBlock blk)Generate common code for a block of alternatives; return a postscript that needs to be generated at the end of the block.voidgenFollowSetForRuleBlock(RuleBlock blk)Generate a textual representation of the follow set for a block.protected voidgenHeader()Generate a header that is common to all TXT filesprotected voidgenLookaheadSetForAlt(Alternative alt)Generate the lookahead set for an alternate.voidgenLookaheadSetForBlock(AlternativeBlock blk)Generate a textual representation of the lookahead set for a block.voidgenNextToken()Generate the nextToken rule.voidgenRule(RuleSymbol s)Generate code for a named rule blockprotected voidgenSynPred(SynPredBlock blk)Generate the syntactic predicate.protected voidgenTokenTypes(TokenManager tm)Generate the token types TXT filejava.lang.StringgetASTCreateString(Vector v)Get a string for an expression to generate creation of an AST subtree.java.lang.StringgetASTCreateString(GrammarAtom atom, java.lang.String str)Get a string for an expression to generate creating of an AST nodejava.lang.StringmapTreeId(java.lang.String id, ActionTransInfo tInfo)Map an identifier to it's corresponding tree-node variable.voidprintSet(int depth, int k, Lookahead lookahead)Format a lookahead or follow set.protected java.lang.StringprocessActionForSpecialSymbols(java.lang.String actionStr, int line, RuleBlock currentRule, ActionTransInfo tInfo)Lexically process $ and # references within the action.-
Methods inherited from class antlr.CodeGenerator
_print, _printAction, _println, decodeLexerRuleName, elementsAreRange, encodeLexerRuleName, extractIdOfAction, extractIdOfAction, extractTypeOfAction, extractTypeOfAction, genTokenInterchange, getBitsetName, getFIRSTBitSet, getFOLLOWBitSet, markBitsetForGen, print, printAction, println, printTabs, processStringForASTConstructor, removeAssignmentFromDeclaration, reverseLexerRuleName, setAnalyzer, setBehavior, setGrammar, setTool
-
-
-
-
Method Detail
-
gen
public void gen()
Generate the parser, lexer, and token types documentation- Specified by:
genin classCodeGenerator
-
gen
public void gen(ActionElement action)
Generate code for the given grammar element.- Specified by:
genin classCodeGenerator- Parameters:
blk- The {...} action to generate
-
gen
public void gen(AlternativeBlock blk)
Generate code for the given grammar element.- Specified by:
genin classCodeGenerator- Parameters:
blk- The "x|y|z|..." block to generate
-
gen
public void gen(BlockEndElement end)
Generate code for the given grammar element.- Specified by:
genin classCodeGenerator- Parameters:
blk- The block-end element to generate. Block-end elements are synthesized by the grammar parser to represent the end of a block.
-
gen
public void gen(CharLiteralElement atom)
Generate code for the given grammar element.- Specified by:
genin classCodeGenerator- Parameters:
blk- The character literal reference to generate
-
gen
public void gen(CharRangeElement r)
Generate code for the given grammar element.- Specified by:
genin classCodeGenerator- Parameters:
blk- The character-range reference to generate
-
gen
public void gen(LexerGrammar g) throws java.io.IOException
Generate the lexer TXT file- Specified by:
genin classCodeGenerator- Throws:
java.io.IOException
-
gen
public void gen(OneOrMoreBlock blk)
Generate code for the given grammar element.- Specified by:
genin classCodeGenerator- Parameters:
blk- The (...)+ block to generate
-
gen
public void gen(ParserGrammar g) throws java.io.IOException
Generate the parser TXT file- Specified by:
genin classCodeGenerator- Throws:
java.io.IOException
-
gen
public void gen(RuleRefElement rr)
Generate code for the given grammar element.- Specified by:
genin classCodeGenerator- Parameters:
blk- The rule-reference to generate
-
gen
public void gen(StringLiteralElement atom)
Generate code for the given grammar element.- Specified by:
genin classCodeGenerator- Parameters:
blk- The string-literal reference to generate
-
gen
public void gen(TokenRangeElement r)
Generate code for the given grammar element.- Specified by:
genin classCodeGenerator- Parameters:
blk- The token-range reference to generate
-
gen
public void gen(TokenRefElement atom)
Generate code for the given grammar element.- Specified by:
genin classCodeGenerator- Parameters:
blk- The token-reference to generate
-
gen
public void gen(TreeElement t)
Description copied from class:CodeGeneratorGenerate code for the given grammar element.- Specified by:
genin classCodeGenerator
-
gen
public void gen(TreeWalkerGrammar g) throws java.io.IOException
Generate the tree-walker TXT file- Specified by:
genin classCodeGenerator- Throws:
java.io.IOException
-
gen
public void gen(WildcardElement wc)
Generate a wildcard element- Specified by:
genin classCodeGenerator- Parameters:
wc- The wildcard element to generate
-
gen
public void gen(ZeroOrMoreBlock blk)
Generate code for the given grammar element.- Specified by:
genin classCodeGenerator- Parameters:
blk- The (...)* block to generate
-
genAlt
protected void genAlt(Alternative alt)
-
genBlockPreamble
protected void genBlockPreamble(AlternativeBlock blk)
Generate the header for a block, which may be a RuleBlock or a plain AlternativeBLock. This generates any variable declarations, init-actions, and syntactic-predicate-testing variables.
-
genCommonBlock
public void genCommonBlock(AlternativeBlock blk)
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.
-
genFollowSetForRuleBlock
public void genFollowSetForRuleBlock(RuleBlock blk)
Generate a textual representation of the follow set for a block.- Parameters:
blk- The rule block of interest
-
genHeader
protected void genHeader()
Generate a header that is common to all TXT files
-
genLookaheadSetForAlt
protected void genLookaheadSetForAlt(Alternative alt)
Generate the lookahead set for an alternate.
-
genLookaheadSetForBlock
public void genLookaheadSetForBlock(AlternativeBlock blk)
Generate a textual representation of the lookahead set for a block.- Parameters:
blk- The block of interest
-
genNextToken
public void genNextToken()
Generate the nextToken rule. nextToken is a synthetic lexer rule that is the implicit OR of all user-defined lexer rules.
-
genRule
public void genRule(RuleSymbol s)
Generate code for a named rule block- Parameters:
s- The RuleSymbol describing the rule to generate
-
genSynPred
protected void genSynPred(SynPredBlock blk)
Generate the syntactic predicate. This basically generates the alternative block, buts tracks if we are inside a synPred- Parameters:
blk- The syntactic predicate block
-
genTokenTypes
protected void genTokenTypes(TokenManager tm) throws java.io.IOException
Generate the token types TXT file- Throws:
java.io.IOException
-
getASTCreateString
public java.lang.String getASTCreateString(Vector v)
Get a string for an expression to generate creation of an AST subtree.- Specified by:
getASTCreateStringin classCodeGenerator- Parameters:
v- A Vector of String, where each element is an expression in the target language yielding an AST node.
-
getASTCreateString
public java.lang.String getASTCreateString(GrammarAtom atom, java.lang.String str)
Get a string for an expression to generate creating of an AST node- Specified by:
getASTCreateStringin classCodeGenerator- Parameters:
str- The arguments to the AST constructor
-
processActionForSpecialSymbols
protected java.lang.String processActionForSpecialSymbols(java.lang.String actionStr, int line, RuleBlock currentRule, ActionTransInfo tInfo)Description copied from class:CodeGeneratorLexically process $ and # references within the action. This will replace #id and #(...) with the appropriate function calls and/or variables etc...- Specified by:
processActionForSpecialSymbolsin classCodeGenerator
-
mapTreeId
public java.lang.String mapTreeId(java.lang.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- Specified by:
mapTreeIdin classCodeGenerator- Parameters:
id- The identifier name to mapforInput- 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
-
printSet
public void printSet(int depth, int k, Lookahead lookahead)Format a lookahead or follow set.- Parameters:
depth- The depth of the entire lookahead/followk- The lookahead level to printlookahead- The lookahead/follow set to print
-
-