Package antlr
Class HTMLCodeGenerator
java.lang.Object
antlr.CodeGenerator
antlr.HTMLCodeGenerator
Generate P.html, a cross-linked representation of P with or without actions
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
true during lexer generation, false during parser generationprotected boolean
protected AlternativeElement
protected int
non-zero if inside syntactic predicate generationFields 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
ConstructorsConstructorDescriptionCreate a Diagnostic code-generator using the given Grammar The caller must still call setTool, setBehavior, and setAnalyzer before generating code. -
Method Summary
Modifier and TypeMethodDescriptionvoid
gen()
Generate the code for all grammarsvoid
gen
(ActionElement action) Generate code for the given grammar element.void
gen
(AlternativeBlock blk) Generate code for the given grammar element.void
gen
(BlockEndElement end) Generate code for the given grammar element.void
gen
(CharLiteralElement atom) Generate code for the given grammar element.void
Generate code for the given grammar element.void
gen
(LexerGrammar g) Generate the lexer HTML filevoid
gen
(OneOrMoreBlock blk) Generate code for the given grammar element.void
gen
(ParserGrammar g) Generate the parser HTML filevoid
gen
(RuleRefElement rr) Generate code for the given grammar element.void
gen
(StringLiteralElement atom) Generate code for the given grammar element.void
Generate code for the given grammar element.void
gen
(TokenRefElement atom) Generate code for the given grammar element.void
gen
(TreeElement t) Generate code for the given grammar element.void
Generate the tree-walker TXT filevoid
gen
(WildcardElement wc) Generate a wildcard elementvoid
gen
(ZeroOrMoreBlock blk) Generate code for the given grammar element.protected void
genAlt
(Alternative alt) void
Generate common code for a block of alternatives; return a postscript that needs to be generated at the end of the block.void
Generate a textual representation of the follow set for a block.protected void
genGenericBlock
(AlternativeBlock blk, String blkOp) protected void
Generate a header that is common to all TXT filesprotected void
Generate the lookahead set for an alternate.void
Generate a textual representation of the lookahead set for a block.void
Generate the nextToken rule.void
Generate code for a named rule blockprotected void
genSynPred
(SynPredBlock blk) Generate the syntactic predicate.void
genTail()
protected void
Generate the token types TXT fileGet a string for an expression to generate creation of an AST subtree.getASTCreateString
(GrammarAtom atom, String str) Get a string for an expression to generate creating of an AST node(package private) static String
HTMLEncode
(String s) Encode a string for printing in a HTML document..mapTreeId
(String id, ActionTransInfo tInfo) Map an identifier to it's corresponding tree-node variable.void
Format a lookahead or follow set.protected String
processActionForSpecialSymbols
(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
-
Field Details
-
syntacticPredLevel
protected int syntacticPredLevelnon-zero if inside syntactic predicate generation -
doingLexRules
protected boolean doingLexRulestrue during lexer generation, false during parser generation -
firstElementInAlt
protected boolean firstElementInAlt -
prevAltElem
-
-
Constructor Details
-
HTMLCodeGenerator
public HTMLCodeGenerator()Create a Diagnostic code-generator using the given Grammar The caller must still call setTool, setBehavior, and setAnalyzer before generating code.
-
-
Method Details
-
HTMLEncode
Encode a string for printing in a HTML document.. e.g. encode 'invalid input: '<'' '>' and similar stuff- Parameters:
s
- the string to encode
-
gen
public void gen()Description copied from class:CodeGenerator
Generate the code for all grammars- Specified by:
gen
in classCodeGenerator
-
gen
Generate code for the given grammar element.- Specified by:
gen
in classCodeGenerator
- Parameters:
action
- The {...} action to generateblk
- The {...} action to generate
-
gen
Generate code for the given grammar element.- Specified by:
gen
in classCodeGenerator
- Parameters:
blk
- The "x|y|z|..." block to generate
-
gen
Generate code for the given grammar element.- Specified by:
gen
in classCodeGenerator
- Parameters:
end
- The block-end element to generate. Block-end elements are synthesized by the grammar parser to represent the end of a block.blk
- The block-end element to generate. Block-end elements are synthesized by the grammar parser to represent the end of a block.
-
gen
Generate code for the given grammar element.- Specified by:
gen
in classCodeGenerator
- Parameters:
atom
- The character literal reference to generateblk
- The character literal reference to generate
-
gen
Generate code for the given grammar element.- Specified by:
gen
in classCodeGenerator
- Parameters:
r
- The character-range reference to generateblk
- The character-range reference to generate
-
gen
Generate the lexer HTML file- Specified by:
gen
in classCodeGenerator
- Throws:
IOException
-
gen
Generate code for the given grammar element.- Specified by:
gen
in classCodeGenerator
- Parameters:
blk
- The (...)+ block to generate
-
gen
Generate the parser HTML file- Specified by:
gen
in classCodeGenerator
- Throws:
IOException
-
gen
Generate code for the given grammar element.- Specified by:
gen
in classCodeGenerator
- Parameters:
rr
- The rule-reference to generateblk
- The rule-reference to generate
-
gen
Generate code for the given grammar element.- Specified by:
gen
in classCodeGenerator
- Parameters:
atom
- The string-literal reference to generateblk
- The string-literal reference to generate
-
gen
Generate code for the given grammar element.- Specified by:
gen
in classCodeGenerator
- Parameters:
r
- The token-range reference to generateblk
- The token-range reference to generate
-
gen
Generate code for the given grammar element.- Specified by:
gen
in classCodeGenerator
- Parameters:
atom
- The token-reference to generateblk
- The token-reference to generate
-
gen
Description copied from class:CodeGenerator
Generate code for the given grammar element.- Specified by:
gen
in classCodeGenerator
-
gen
Generate the tree-walker TXT file- Specified by:
gen
in classCodeGenerator
- Throws:
IOException
-
gen
Generate a wildcard element- Specified by:
gen
in classCodeGenerator
- Parameters:
wc
- The wildcard element to generate
-
gen
Generate code for the given grammar element.- Specified by:
gen
in classCodeGenerator
- Parameters:
blk
- The (...)* block to generate
-
genAlt
-
genCommonBlock
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
Generate a textual representation of the follow set for a block.- Parameters:
blk
- The rule block of interest
-
genGenericBlock
-
genHeader
protected void genHeader()Generate a header that is common to all TXT files -
genLookaheadSetForAlt
Generate the lookahead set for an alternate. -
genLookaheadSetForBlock
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
Generate code for a named rule block- Parameters:
s
- The RuleSymbol describing the rule to generate
-
genSynPred
Generate the syntactic predicate. This basically generates the alternative block, buts tracks if we are inside a synPred- Parameters:
blk
- The syntactic predicate block
-
genTail
public void genTail() -
genTokenTypes
Generate the token types TXT file- Throws:
IOException
-
getASTCreateString
Get a string for an expression to generate creation of an AST subtree.- Specified by:
getASTCreateString
in classCodeGenerator
- Parameters:
v
- A Vector of String, where each element is an expression in the target language yielding an AST node.
-
getASTCreateString
Get a string for an expression to generate creating of an AST node- Specified by:
getASTCreateString
in classCodeGenerator
- Parameters:
str
- The arguments to the AST constructor
-
mapTreeId
Map an identifier to it's corresponding tree-node variable. This is context-sensitive, depending on the rule and alternative being generated- Specified by:
mapTreeId
in 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
-
processActionForSpecialSymbols
protected String processActionForSpecialSymbols(String actionStr, int line, RuleBlock currentRule, ActionTransInfo tInfo) Description copied from class:CodeGenerator
Lexically process $ and # references within the action. This will replace #id and #(...) with the appropriate function calls and/or variables etc...- Specified by:
processActionForSpecialSymbols
in classCodeGenerator
-
printSet
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
-