java.lang.Object antlr.CodeGenerator antlr.CSharpCodeGenerator
Generates MyParser.cs, MyLexer.cs and MyParserTokenTypes.cs
Field Summary | |
static int |
caseSizeThreshold
|
Fields inherited from class antlr.CodeGenerator |
TokenTypesFileExt, TokenTypesFileSuffix |
Constructor Summary | |
CSharpCodeGenerator()
Create a CSharp code-generator using the given Grammar. |
Method Summary | |
void |
exitIfError()
|
void |
gen()
Generate the parser, lexer, treeparser, and token types in CSharp |
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 CSharp file |
void |
gen(antlr.OneOrMoreBlock blk)
Generate code for the given grammar element. |
void |
gen(antlr.ParserGrammar g)
Generate the parser CSharp 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-parser CSharp file |
void |
gen(antlr.WildcardElement wc)
Generate code for the given grammar element. |
void |
gen(antlr.ZeroOrMoreBlock blk)
Generate code for the given grammar element. |
void |
genBody(antlr.LexerGrammar g)
|
void |
genBody(antlr.ParserGrammar g)
|
void |
genBody(antlr.TreeWalkerGrammar g)
|
antlr.CSharpBlockFinishingInfo |
genCommonBlock(antlr.AlternativeBlock blk,
boolean noTestForSingle)
Generate common code for a block of alternatives; return a postscript that needs to be generated at the end of the block. |
void |
genInitFactory(Grammar g)
|
void |
genNextToken()
Generate the nextToken() rule. |
void |
genRule(antlr.RuleSymbol s,
boolean startSymbol,
int ruleNum,
antlr.TokenManager tm)
Gen a named rule block. |
void |
genTokenStrings()
Generate a static array containing the names of the tokens, indexed by the token type values. |
java.lang.String |
getASTCreateString(antlr.GrammarAtom atom,
java.lang.String astCtorArgs)
Get a string for an expression to generate creating of an AST node |
java.lang.String |
getASTCreateString(java.lang.String astCtorArgs)
Returns a string expression that creates an AST node using the specified AST constructor argument string. |
java.lang.String |
getASTCreateString(Vector v)
Get a string for an expression to generate creation of an AST subtree. |
java.lang.String |
getRangeExpression(int k,
int[] elems)
Return an expression for testing a contiguous renage of elements |
java.lang.String |
getTokenTypesClassName()
Helper method that returns the name of the interface/class/enum type for token type constants. |
java.lang.String |
mapTreeId(java.lang.String idParam,
ActionTransInfo transInfo)
Map an identifier to it's corresponding tree-node variable. |
java.lang.String |
processStringForASTConstructor(java.lang.String str)
Process a string for an simple expression for use in xx/action.g it is used to cast simple tokens/references to the right type for the generated language. |
void |
setupOutput(java.lang.String className)
This method exists so a subclass, namely VAJCodeGenerator, can open the file in its own evil way. |
Methods inherited from class antlr.CodeGenerator |
decodeLexerRuleName, elementsAreRange, encodeLexerRuleName, getFIRSTBitSet, getFOLLOWBitSet, reverseLexerRuleName, setAnalyzer, setBehavior, setTool |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int caseSizeThreshold
Constructor Detail |
public CSharpCodeGenerator()
Method Detail |
public void exitIfError()
public void gen()
gen
in class CodeGenerator
public void gen(antlr.ActionElement action)
gen
in class CodeGenerator
action
- The {...} action to generatepublic void gen(antlr.AlternativeBlock blk)
gen
in class CodeGenerator
blk
- The "x|y|z|..." block to generatepublic void gen(antlr.BlockEndElement end)
gen
in class CodeGenerator
end
- The block-end element to generate. Block-end
elements are synthesized by the grammar parser to represent
the end of a block.public void gen(antlr.CharLiteralElement atom)
gen
in class CodeGenerator
atom
- The character literal reference to generatepublic void gen(antlr.CharRangeElement r)
gen
in class CodeGenerator
r
- The character-range reference to generatepublic void gen(antlr.LexerGrammar g) throws java.io.IOException
gen
in class CodeGenerator
java.io.IOException
public void gen(antlr.OneOrMoreBlock blk)
gen
in class CodeGenerator
blk
- The (...)+ block to generatepublic void gen(antlr.ParserGrammar g) throws java.io.IOException
gen
in class CodeGenerator
java.io.IOException
public void gen(antlr.RuleRefElement rr)
gen
in class CodeGenerator
rr
- The rule-reference to generatepublic void gen(antlr.StringLiteralElement atom)
gen
in class CodeGenerator
atom
- The string-literal reference to generatepublic void gen(antlr.TokenRangeElement r)
gen
in class CodeGenerator
r
- The token-range reference to generatepublic void gen(antlr.TokenRefElement atom)
gen
in class CodeGenerator
atom
- The token-reference to generatepublic void gen(antlr.TreeElement t)
CodeGenerator
gen
in class CodeGenerator
public void gen(antlr.TreeWalkerGrammar g) throws java.io.IOException
gen
in class CodeGenerator
java.io.IOException
public void gen(antlr.WildcardElement wc)
gen
in class CodeGenerator
wc
- The wildcard element to generatepublic void gen(antlr.ZeroOrMoreBlock blk)
gen
in class CodeGenerator
blk
- The (...)* block to generatepublic void genBody(antlr.LexerGrammar g) throws java.io.IOException
java.io.IOException
public void genInitFactory(Grammar g)
public void genBody(antlr.ParserGrammar g) throws java.io.IOException
java.io.IOException
public void genBody(antlr.TreeWalkerGrammar g) throws java.io.IOException
java.io.IOException
public antlr.CSharpBlockFinishingInfo genCommonBlock(antlr.AlternativeBlock blk, boolean noTestForSingle)
public void genNextToken()
public void genRule(antlr.RuleSymbol s, boolean startSymbol, int ruleNum, antlr.TokenManager tm)
startSymbol
- true if the rule is a start symbol (i.e., not referenced elsewhere)public void genTokenStrings()
public java.lang.String processStringForASTConstructor(java.lang.String str)
processStringForASTConstructor
in class CodeGenerator
str
- A String.public java.lang.String getASTCreateString(Vector v)
getASTCreateString
in class CodeGenerator
v
- A Vector of String, where each element is an expression
in the target language yielding an AST node.public java.lang.String getASTCreateString(antlr.GrammarAtom atom, java.lang.String astCtorArgs)
getASTCreateString
in class CodeGenerator
atom
- The grammar node for which you are creating the nodeastCtorArgs
- The text of the arguments to the AST constructionpublic java.lang.String getASTCreateString(java.lang.String astCtorArgs)
astCtorArgs
- The arguments to the AST constructorpublic java.lang.String getRangeExpression(int k, int[] elems)
k
- The lookahead levelelems
- The elements representing the set, usually from BitSet.toArray().
public java.lang.String mapTreeId(java.lang.String idParam, ActionTransInfo transInfo)
mapTreeId
in class CodeGenerator
idParam
- The identifier name to map
public void setupOutput(java.lang.String className) throws java.io.IOException
java.io.IOException
public java.lang.String getTokenTypesClassName()