antlr
Class HTMLCodeGenerator

java.lang.Object
  |
  +--antlr.CodeGenerator
        |
        +--antlr.HTMLCodeGenerator

public class HTMLCodeGenerator
extends CodeGenerator

Generate P.html, 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  antlr.AlternativeElement prevAltElem
           
protected  int syntacticPredLevel
          non-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
HTMLCodeGenerator()
          Create a Diagnostic code-generator using the given Grammar The caller must still call setTool, setBehavior, and setAnalyzer before generating code.
 
Method Summary
 void gen()
          Generate the code for all grammars
 void gen(antlr.ActionElement action)
          Generate code for the given grammar element.
 void gen(antlr.AlternativeBlock blk)
          Generate code for the given grammar element.
 void gen(antlr.BlockEndElement end)
          Generate code for the given grammar element.
 void gen(antlr.CharLiteralElement atom)
          Generate code for the given grammar element.
 void gen(antlr.CharRangeElement r)
          Generate code for the given grammar element.
 void gen(antlr.LexerGrammar g)
          Generate the lexer HTML file
 void gen(antlr.OneOrMoreBlock blk)
          Generate code for the given grammar element.
 void gen(antlr.ParserGrammar g)
          Generate the parser HTML file
 void gen(antlr.RuleRefElement rr)
          Generate code for the given grammar element.
 void gen(antlr.StringLiteralElement atom)
          Generate code for the given grammar element.
 void gen(antlr.TokenRangeElement r)
          Generate code for the given grammar element.
 void gen(antlr.TokenRefElement atom)
          Generate code for the given grammar element.
 void gen(antlr.TreeElement t)
          Generate code for the given grammar element.
 void gen(antlr.TreeWalkerGrammar g)
          Generate the tree-walker TXT file
 void gen(antlr.WildcardElement wc)
          Generate a wildcard element
 void gen(antlr.ZeroOrMoreBlock blk)
          Generate code for the given grammar element.
protected  void genAlt(antlr.Alternative alt)
           
 void genCommonBlock(antlr.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(antlr.AlternativeBlock blk, String blkOp)
           
protected  void genHeader()
          Generate a header that is common to all TXT files
protected  void genLookaheadSetForAlt(antlr.Alternative alt)
          Generate the lookahead set for an alternate.
 void genLookaheadSetForBlock(antlr.AlternativeBlock blk)
          Generate a textual representation of the lookahead set for a block.
 void genNextToken()
          Generate the nextToken rule.
 void genRule(antlr.RuleSymbol s)
          Generate code for a named rule block
protected  void genSynPred(antlr.SynPredBlock blk)
          Generate the syntactic predicate.
 void genTail()
           
protected  void genTokenTypes(antlr.TokenManager tm)
          Generate the token types TXT file
 String getASTCreateString(antlr.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, genTokenInterchange, getBitsetName, getFIRSTBitSet, getFOLLOWBitSet, markBitsetForGen, print, printAction, println, printTabs, processStringForASTConstructor, removeAssignmentFromDeclaration, reverseLexerRuleName, setAnalyzer, setBehavior, setGrammar, setTool
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

syntacticPredLevel

protected int syntacticPredLevel
non-zero if inside syntactic predicate generation


doingLexRules

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


firstElementInAlt

protected boolean firstElementInAlt

prevAltElem

protected antlr.AlternativeElement prevAltElem
Constructor Detail

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 Detail

gen

public void gen()
Description copied from class: CodeGenerator
Generate the code for all grammars

Specified by:
gen in class CodeGenerator

gen

public void gen(antlr.ActionElement action)
Generate code for the given grammar element.

Specified by:
gen in class CodeGenerator
Parameters:
action - The {...} action to generate

gen

public void gen(antlr.AlternativeBlock blk)
Generate code for the given grammar element.

Specified by:
gen in class CodeGenerator
Parameters:
blk - The "x|y|z|..." block to generate

gen

public void gen(antlr.BlockEndElement end)
Generate code for the given grammar element.

Specified by:
gen in class CodeGenerator
Parameters:
end - 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(antlr.CharLiteralElement atom)
Generate code for the given grammar element.

Specified by:
gen in class CodeGenerator
Parameters:
atom - The character literal reference to generate

gen

public void gen(antlr.CharRangeElement r)
Generate code for the given grammar element.

Specified by:
gen in class CodeGenerator
Parameters:
r - The character-range reference to generate

gen

public void gen(antlr.LexerGrammar g)
         throws IOException
Generate the lexer HTML file

Specified by:
gen in class CodeGenerator
IOException

gen

public void gen(antlr.OneOrMoreBlock blk)
Generate code for the given grammar element.

Specified by:
gen in class CodeGenerator
Parameters:
blk - The (...)+ block to generate

gen

public void gen(antlr.ParserGrammar g)
         throws IOException
Generate the parser HTML file

Specified by:
gen in class CodeGenerator
IOException

gen

public void gen(antlr.RuleRefElement rr)
Generate code for the given grammar element.

Specified by:
gen in class CodeGenerator
Parameters:
rr - The rule-reference to generate

gen

public void gen(antlr.StringLiteralElement atom)
Generate code for the given grammar element.

Specified by:
gen in class CodeGenerator
Parameters:
atom - The string-literal reference to generate

gen

public void gen(antlr.TokenRangeElement r)
Generate code for the given grammar element.

Specified by:
gen in class CodeGenerator
Parameters:
r - The token-range reference to generate

gen

public void gen(antlr.TokenRefElement atom)
Generate code for the given grammar element.

Specified by:
gen in class CodeGenerator
Parameters:
atom - The token-reference to generate

gen

public void gen(antlr.TreeElement t)
Description copied from class: CodeGenerator
Generate code for the given grammar element.

Specified by:
gen in class CodeGenerator

gen

public void gen(antlr.TreeWalkerGrammar g)
         throws IOException
Generate the tree-walker TXT file

Specified by:
gen in class CodeGenerator
IOException

gen

public void gen(antlr.WildcardElement wc)
Generate a wildcard element

Specified by:
gen in class CodeGenerator
Parameters:
wc - The wildcard element to generate

gen

public void gen(antlr.ZeroOrMoreBlock blk)
Generate code for the given grammar element.

Specified by:
gen in class CodeGenerator
Parameters:
blk - The (...)* block to generate

genAlt

protected void genAlt(antlr.Alternative alt)

genCommonBlock

public void genCommonBlock(antlr.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(antlr.AlternativeBlock blk,
                               String blkOp)

genHeader

protected void genHeader()
Generate a header that is common to all TXT files


genLookaheadSetForAlt

protected void genLookaheadSetForAlt(antlr.Alternative alt)
Generate the lookahead set for an alternate.


genLookaheadSetForBlock

public void genLookaheadSetForBlock(antlr.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(antlr.RuleSymbol s)
Generate code for a named rule block

Parameters:
s - The RuleSymbol describing the rule to generate

genSynPred

protected void genSynPred(antlr.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(antlr.TokenManager tm)
                      throws IOException
Generate the token types TXT file

IOException

getASTCreateString

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

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

getASTCreateString

public String getASTCreateString(antlr.GrammarAtom atom,
                                 String str)
Get a string for an expression to generate creating of an AST node

Specified by:
getASTCreateString in class CodeGenerator
Parameters:
str - The arguments to the AST constructor

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

Specified by:
mapTreeId in class CodeGenerator
Parameters:
id - 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

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 class CodeGenerator

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


Copyright © 1999-2003 Oliver Zeigermann. All Rights Reserved.