antlr

Class DocBookCodeGenerator


public class DocBookCodeGenerator
extends CodeGenerator

Generate P.sgml, a cross-linked representation of P with or without actions

Field Summary

protected boolean
doingLexRules
true during lexer generation, false during parser generation
protected boolean
firstElementInAlt
protected AlternativeElement
prevAltElem
protected int
syntacticPredLevel
non-zero if inside syntactic predicate generation

Fields inherited from class antlr.CodeGenerator

BITSET_OPTIMIZE_INIT_THRESHOLD, DEBUG_CODE_GENERATOR, DEFAULT_BITSET_TEST_THRESHOLD, DEFAULT_MAKE_SWITCH_THRESHOLD, TokenTypesFileExt, TokenTypesFileSuffix, analyzer, antlrTool, behavior, bitsetTestThreshold, bitsetsUsed, charFormatter, currentOutput, grammar, makeSwitchThreshold, tabs

Constructor Summary

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

Method Summary

(package private) static String
HTMLEncode(String s)
Encode a string for printing in a HTML document..
(package private) static String
QuoteForId(String s)
Encode a string for printing in a HTML document..
void
gen()
Generate the code for all grammars
void
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
gen(CharRangeElement r)
Generate code for the given grammar element.
void
gen(LexerGrammar g)
Generate the lexer HTML file
void
gen(OneOrMoreBlock blk)
Generate code for the given grammar element.
void
gen(ParserGrammar g)
Generate the parser HTML file
void
gen(RuleRefElement rr)
Generate code for the given grammar element.
void
gen(StringLiteralElement atom)
Generate code for the given grammar element.
void
gen(TokenRangeElement r)
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
gen(TreeWalkerGrammar g)
Generate the tree-walker TXT file
void
gen(WildcardElement wc)
Generate a wildcard element
void
gen(ZeroOrMoreBlock blk)
Generate code for the given grammar element.
protected void
genAlt(Alternative alt)
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.
void
genFollowSetForRuleBlock(RuleBlock blk)
Generate a textual representation of the follow set for a block.
protected void
genGenericBlock(AlternativeBlock blk, String blkOp)
protected void
genHeader()
Generate a header that is common to all TXT files
protected void
genLookaheadSetForAlt(Alternative alt)
Generate the lookahead set for an alternate.
void
genLookaheadSetForBlock(AlternativeBlock blk)
Generate a textual representation of the lookahead set for a block.
void
genNextToken()
Generate the nextToken rule.
void
genRule(RuleSymbol s)
Generate code for a named rule block
protected void
genSynPred(SynPredBlock blk)
Generate the syntactic predicate.
void
genTail()
protected void
genTokenTypes(TokenManager tm)
Generate the token types TXT file
String
getASTCreateString(GrammarAtom atom, String str)
Get a string for an expression to generate creating of an AST node
String
getASTCreateString(Vector v)
Get a string for an expression to generate creation of an AST subtree.
String
mapTreeId(String id, ActionTransInfo tInfo)
Map an identifier to it's corresponding tree-node variable.
void
printSet(int depth, int k, Lookahead lookahead)
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, gen, gen, gen, gen, gen, gen, gen, gen, gen, gen, gen, gen, gen, gen, gen, gen, gen, genTokenInterchange, getASTCreateString, getASTCreateString, getBitsetName, getFIRSTBitSet, getFOLLOWBitSet, mapTreeId, markBitsetForGen, print, printAction, printTabs, println, processActionForSpecialSymbols, processStringForASTConstructor, removeAssignmentFromDeclaration, reverseLexerRuleName, setAnalyzer, setBehavior, setGrammar, setTool

Field Details

doingLexRules

protected boolean doingLexRules
true during lexer generation, false during parser generation


firstElementInAlt

protected boolean firstElementInAlt


prevAltElem

protected AlternativeElement prevAltElem


syntacticPredLevel

protected int syntacticPredLevel
non-zero if inside syntactic predicate generation

Constructor Details

DocBookCodeGenerator

public DocBookCodeGenerator()
Create a Diagnostic code-generator using the given Grammar The caller must still call setTool, setBehavior, and setAnalyzer before generating code.

Method Details

HTMLEncode

(package private) static String HTMLEncode(String s)
Encode a string for printing in a HTML document.. e.g. encode '<' '>' and similar stuff

Parameters:
s - the string to encode


QuoteForId

(package private) static String QuoteForId(String s)
Encode a string for printing in a HTML document.. e.g. encode '<' '>' and similar stuff

Parameters:
s - the string to encode


gen

public void gen()
Generate the code for all grammars
Overrides:
gen in interface CodeGenerator


gen

public void gen(ActionElement action)
Generate code for the given grammar element.
Overrides:
gen in interface CodeGenerator

Parameters:


gen

public void gen(AlternativeBlock blk)
Generate code for the given grammar element.
Overrides:
gen in interface CodeGenerator

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


gen

public void gen(BlockEndElement end)
Generate code for the given grammar element.
Overrides:
gen in interface CodeGenerator

Parameters:


gen

public void gen(CharLiteralElement atom)
Generate code for the given grammar element.
Overrides:
gen in interface CodeGenerator

Parameters:


gen

public void gen(CharRangeElement r)
Generate code for the given grammar element.
Overrides:
gen in interface CodeGenerator

Parameters:


gen

public void gen(LexerGrammar g)
            throws IOException
Generate the lexer HTML file
Overrides:
gen in interface CodeGenerator


gen

public void gen(OneOrMoreBlock blk)
Generate code for the given grammar element.
Overrides:
gen in interface CodeGenerator

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


gen

public void gen(ParserGrammar g)
            throws IOException
Generate the parser HTML file
Overrides:
gen in interface CodeGenerator


gen

public void gen(RuleRefElement rr)
Generate code for the given grammar element.
Overrides:
gen in interface CodeGenerator

Parameters:


gen

public void gen(StringLiteralElement atom)
Generate code for the given grammar element.
Overrides:
gen in interface CodeGenerator

Parameters:


gen

public void gen(TokenRangeElement r)
Generate code for the given grammar element.
Overrides:
gen in interface CodeGenerator

Parameters:


gen

public void gen(TokenRefElement atom)
Generate code for the given grammar element.
Overrides:
gen in interface CodeGenerator

Parameters:


gen

public void gen(TreeElement t)
Generate code for the given grammar element.
Overrides:
gen in interface CodeGenerator

Parameters:


gen

public void gen(TreeWalkerGrammar g)
            throws IOException
Generate the tree-walker TXT file
Overrides:
gen in interface CodeGenerator


gen

public void gen(WildcardElement wc)
Generate a wildcard element
Overrides:
gen in interface CodeGenerator


gen

public void gen(ZeroOrMoreBlock blk)
Generate code for the given grammar element.
Overrides:
gen in interface CodeGenerator

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


genAlt

protected void genAlt(Alternative alt)


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


genGenericBlock

protected void genGenericBlock(AlternativeBlock blk,
                               String blkOp)


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


genTail

public void genTail()


genTokenTypes

protected void genTokenTypes(TokenManager tm)
            throws IOException
Generate the token types TXT file


getASTCreateString

public String getASTCreateString(GrammarAtom atom,
                                 String str)
Get a string for an expression to generate creating of an AST node
Overrides:
getASTCreateString in interface CodeGenerator

Parameters:
str - The arguments to the AST constructor


getASTCreateString

public String getASTCreateString(Vector v)
Get a string for an expression to generate creation of an AST subtree.
Overrides:
getASTCreateString in interface CodeGenerator

Parameters:
v - A Vector of String, where each element is an expression in the target language yielding an AST node.


mapTreeId

public String mapTreeId(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
Overrides:
mapTreeId in interface CodeGenerator

Parameters:
id - The identifier name to map


printSet

public void printSet(int depth,
                     int k,
                     Lookahead lookahead)
Format a lookahead or follow set.

Parameters:
depth - The depth of the entire lookahead/follow
k - The lookahead level to print
lookahead - The lookahead/follow set to print


processActionForSpecialSymbols

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