Package org.antlr.grammar.v2
Class CodeGenTreeWalker
java.lang.Object
antlr.TreeParser
org.antlr.grammar.v2.CodeGenTreeWalker
- All Implemented Interfaces:
CodeGenTreeWalkerTokenTypes
Walk a grammar and generate code by gradually building up
a bigger and bigger StringTemplate.
Terence Parr
University of San Francisco
June 15, 2004
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String[]
protected int
protected boolean
protected org.antlr.stringtemplate.StringTemplate
protected String
protected CodeGenerator
protected Grammar
protected org.antlr.stringtemplate.StringTemplate
protected static final int
protected int
protected org.antlr.stringtemplate.StringTemplate
protected String
protected org.antlr.stringtemplate.StringTemplate
The overall lexer/parser template; simulate dynamically scoped attributes by making this an instance var of the walker.protected int
protected Set
protected int
protected static final int
protected org.antlr.stringtemplate.StringTemplateGroup
Fields inherited from class antlr.TreeParser
_retTree, astFactory, ASTNULL, inputState, returnAST, tokenNames, traceDepth
Fields inherited from interface org.antlr.grammar.v2.CodeGenTreeWalkerTokenTypes
ACTION, ACTION_CHAR_LITERAL, ACTION_ESC, ACTION_STRING_LITERAL, ALT, AMPERSAND, ARG, ARG_ACTION, ARGLIST, ASSIGN, BACKTRACK_SEMPRED, BANG, BLOCK, CHAR_LITERAL, CHAR_RANGE, CLOSE_ELEMENT_OPTION, CLOSURE, COLON, COMBINED_GRAMMAR, COMMA, COMMENT, DIGIT, DOC_COMMENT, DOLLAR, DOT, DOUBLE_ANGLE_STRING_LITERAL, DOUBLE_QUOTE_STRING_LITERAL, EOA, EOB, EOF, EOR, EPSILON, ESC, ETC, FORCED_ACTION, FRAGMENT, GATED_SEMPRED, ID, IMPLIES, IMPORT, INITACTION, INT, INTERNAL_RULE_REF, LABEL, LEXER, LEXER_GRAMMAR, LITERAL_catch, LITERAL_finally, LITERAL_grammar, LITERAL_lexer, LITERAL_private, LITERAL_protected, LITERAL_public, LITERAL_returns, LITERAL_throws, LITERAL_tree, LPAREN, ML_COMMENT, NESTED_ACTION, NESTED_ARG_ACTION, NOT, NULL_TREE_LOOKAHEAD, OPEN_ELEMENT_OPTION, OPTIONAL, OPTIONS, OR, PARSER, PARSER_GRAMMAR, PLUS, PLUS_ASSIGN, POSITIVE_CLOSURE, QUESTION, RANGE, RCURLY, RET, REWRITE, ROOT, RPAREN, RULE, RULE_REF, SCOPE, SEMI, SEMPRED, SL_COMMENT, SRC, STAR, STRAY_BRACKET, STRING_LITERAL, SYN_SEMPRED, SYNPRED, TEMPLATE, TOKEN_REF, TOKENS, TREE_BEGIN, TREE_GRAMMAR, WILDCARD, WS, WS_LOOP, WS_OPT, XDIGIT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal org.antlr.stringtemplate.StringTemplate
alternative
(antlr.collections.AST _t) final void
ast_suffix
(antlr.collections.AST _t) final org.antlr.stringtemplate.StringTemplate
atom
(antlr.collections.AST _t, GrammarAST scope, GrammarAST label, GrammarAST astSuffix) final void
attrScope
(antlr.collections.AST _t) final org.antlr.stringtemplate.StringTemplate
final org.antlr.stringtemplate.StringTemplate
ebnf
(antlr.collections.AST _t) final org.antlr.stringtemplate.StringTemplate
element
(antlr.collections.AST _t, GrammarAST label, GrammarAST astSuffix) final org.antlr.stringtemplate.StringTemplate
element_action
(antlr.collections.AST _t) final void
exceptionGroup
(antlr.collections.AST _t, org.antlr.stringtemplate.StringTemplate ruleST) final void
exceptionHandler
(antlr.collections.AST _t, org.antlr.stringtemplate.StringTemplate ruleST) final void
finallyClause
(antlr.collections.AST _t, org.antlr.stringtemplate.StringTemplate ruleST) int
protected org.antlr.stringtemplate.StringTemplate
getRuleElementST
(String name, String ruleTargetName, GrammarAST elementAST, GrammarAST ast_suffix, String label) protected String
getSTSuffix
(GrammarAST elementAST, GrammarAST ast_suffix, String label) Return a non-empty template name suffix if the token is to be tracked, added to a tree, or both.protected org.antlr.stringtemplate.StringTemplate
getTokenElementST
(String name, String elementName, GrammarAST elementAST, GrammarAST ast_suffix, String label) Convert rewrite AST lists to target labels listprotected org.antlr.stringtemplate.StringTemplate
getWildcardST
(GrammarAST elementAST, GrammarAST ast_suffix, String label) final void
grammar
(antlr.collections.AST _t, Grammar g, org.antlr.stringtemplate.StringTemplate recognizerST, org.antlr.stringtemplate.StringTemplate outputFileST, org.antlr.stringtemplate.StringTemplate headerFileST) final void
grammarSpec
(antlr.collections.AST _t) void
boolean
isListLabel
(String label) final void
modifier
(antlr.collections.AST _t) final org.antlr.stringtemplate.StringTemplate
notElement
(antlr.collections.AST _t, GrammarAST n, GrammarAST label, GrammarAST astSuffix) void
reportError
(antlr.RecognitionException ex) void
final org.antlr.stringtemplate.StringTemplate
rewrite
(antlr.collections.AST _t) final org.antlr.stringtemplate.StringTemplate
rewrite_alternative
(antlr.collections.AST _t) final org.antlr.stringtemplate.StringTemplate
rewrite_atom
(antlr.collections.AST _t, boolean isRoot) final org.antlr.stringtemplate.StringTemplate
rewrite_block
(antlr.collections.AST _t, String blockTemplateName) final org.antlr.stringtemplate.StringTemplate
rewrite_ebnf
(antlr.collections.AST _t) final org.antlr.stringtemplate.StringTemplate
rewrite_element
(antlr.collections.AST _t) final org.antlr.stringtemplate.StringTemplate
rewrite_template
(antlr.collections.AST _t) final org.antlr.stringtemplate.StringTemplate
rewrite_tree
(antlr.collections.AST _t) final org.antlr.stringtemplate.StringTemplate
rule
(antlr.collections.AST _t) final void
rules
(antlr.collections.AST _t, org.antlr.stringtemplate.StringTemplate recognizerST) final void
ruleScopeSpec
(antlr.collections.AST _t) final org.antlr.stringtemplate.StringTemplate
set
(antlr.collections.AST _t, GrammarAST label, GrammarAST astSuffix) final org.antlr.stringtemplate.StringTemplate
setBlock
(antlr.collections.AST _t) void
setCurrentRuleName
(String currentRuleName) final void
setElement
(antlr.collections.AST _t) void
setOuterAltNum
(int outerAltNum) final org.antlr.stringtemplate.StringTemplate
tree
(antlr.collections.AST _t) Methods inherited from class antlr.TreeParser
getAST, getASTFactory, getTokenName, getTokenNames, match, match, matchNot, panic, reportWarning, setASTFactory, setASTNodeClass, setASTNodeType, traceIn, traceIndent, traceOut
-
Field Details
-
RULE_BLOCK_NESTING_LEVEL
protected static final int RULE_BLOCK_NESTING_LEVEL- See Also:
-
OUTER_REWRITE_NESTING_LEVEL
protected static final int OUTER_REWRITE_NESTING_LEVEL- See Also:
-
currentRuleName
-
blockNestingLevel
protected int blockNestingLevel -
rewriteBlockNestingLevel
protected int rewriteBlockNestingLevel -
outerAltNum
protected int outerAltNum -
currentBlockST
protected org.antlr.stringtemplate.StringTemplate currentBlockST -
currentAltHasASTRewrite
protected boolean currentAltHasASTRewrite -
rewriteTreeNestingLevel
protected int rewriteTreeNestingLevel -
rewriteRuleRefs
-
generator
-
grammar
-
templates
protected org.antlr.stringtemplate.StringTemplateGroup templates -
recognizerST
protected org.antlr.stringtemplate.StringTemplate recognizerSTThe overall lexer/parser template; simulate dynamically scoped attributes by making this an instance var of the walker. -
outputFileST
protected org.antlr.stringtemplate.StringTemplate outputFileST -
headerFileST
protected org.antlr.stringtemplate.StringTemplate headerFileST -
outputOption
-
_tokenNames
-
-
Constructor Details
-
CodeGenTreeWalker
public CodeGenTreeWalker()
-
-
Method Details
-
getCurrentRuleName
-
setCurrentRuleName
-
getOuterAltNum
public int getOuterAltNum() -
setOuterAltNum
public void setOuterAltNum(int outerAltNum) -
reportError
public void reportError(antlr.RecognitionException ex) - Overrides:
reportError
in classantlr.TreeParser
-
reportError
- Overrides:
reportError
in classantlr.TreeParser
-
getWildcardST
protected org.antlr.stringtemplate.StringTemplate getWildcardST(GrammarAST elementAST, GrammarAST ast_suffix, String label) -
getRuleElementST
protected org.antlr.stringtemplate.StringTemplate getRuleElementST(String name, String ruleTargetName, GrammarAST elementAST, GrammarAST ast_suffix, String label) -
getTokenElementST
protected org.antlr.stringtemplate.StringTemplate getTokenElementST(String name, String elementName, GrammarAST elementAST, GrammarAST ast_suffix, String label) -
isListLabel
-
getSTSuffix
Return a non-empty template name suffix if the token is to be tracked, added to a tree, or both. -
getTokenTypesAsTargetLabels
Convert rewrite AST lists to target labels list -
init
-
grammar
public final void grammar(antlr.collections.AST _t, Grammar g, org.antlr.stringtemplate.StringTemplate recognizerST, org.antlr.stringtemplate.StringTemplate outputFileST, org.antlr.stringtemplate.StringTemplate headerFileST) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
grammarSpec
public final void grammarSpec(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
attrScope
public final void attrScope(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
rules
public final void rules(antlr.collections.AST _t, org.antlr.stringtemplate.StringTemplate recognizerST) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
rule
public final org.antlr.stringtemplate.StringTemplate rule(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
modifier
public final void modifier(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
ruleScopeSpec
public final void ruleScopeSpec(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
block
public final org.antlr.stringtemplate.StringTemplate block(antlr.collections.AST _t, String blockTemplateName, DFA dfa) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
exceptionGroup
public final void exceptionGroup(antlr.collections.AST _t, org.antlr.stringtemplate.StringTemplate ruleST) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
setBlock
public final org.antlr.stringtemplate.StringTemplate setBlock(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
alternative
public final org.antlr.stringtemplate.StringTemplate alternative(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
rewrite
public final org.antlr.stringtemplate.StringTemplate rewrite(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
exceptionHandler
public final void exceptionHandler(antlr.collections.AST _t, org.antlr.stringtemplate.StringTemplate ruleST) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
finallyClause
public final void finallyClause(antlr.collections.AST _t, org.antlr.stringtemplate.StringTemplate ruleST) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
element
public final org.antlr.stringtemplate.StringTemplate element(antlr.collections.AST _t, GrammarAST label, GrammarAST astSuffix) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
notElement
public final org.antlr.stringtemplate.StringTemplate notElement(antlr.collections.AST _t, GrammarAST n, GrammarAST label, GrammarAST astSuffix) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
ebnf
public final org.antlr.stringtemplate.StringTemplate ebnf(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
atom
public final org.antlr.stringtemplate.StringTemplate atom(antlr.collections.AST _t, GrammarAST scope, GrammarAST label, GrammarAST astSuffix) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
tree
public final org.antlr.stringtemplate.StringTemplate tree(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
element_action
public final org.antlr.stringtemplate.StringTemplate element_action(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
set
public final org.antlr.stringtemplate.StringTemplate set(antlr.collections.AST _t, GrammarAST label, GrammarAST astSuffix) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
ast_suffix
public final void ast_suffix(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
setElement
public final void setElement(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
rewrite_alternative
public final org.antlr.stringtemplate.StringTemplate rewrite_alternative(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
rewrite_block
public final org.antlr.stringtemplate.StringTemplate rewrite_block(antlr.collections.AST _t, String blockTemplateName) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
rewrite_element
public final org.antlr.stringtemplate.StringTemplate rewrite_element(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
rewrite_template
public final org.antlr.stringtemplate.StringTemplate rewrite_template(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
rewrite_atom
public final org.antlr.stringtemplate.StringTemplate rewrite_atom(antlr.collections.AST _t, boolean isRoot) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
rewrite_ebnf
public final org.antlr.stringtemplate.StringTemplate rewrite_ebnf(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-
rewrite_tree
public final org.antlr.stringtemplate.StringTemplate rewrite_tree(antlr.collections.AST _t) throws antlr.RecognitionException - Throws:
antlr.RecognitionException
-