Package antlr
Class Grammar
java.lang.Object
antlr.Grammar
- Direct Known Subclasses:
LexerGrammar
,ParserGrammar
,TreeWalkerGrammar
A Grammar holds a set of rules (which are stored
in a symbol table). Most of the time a grammar
needs a code generator and an LLkAnalyzer too.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected Tool
protected boolean
protected Token
protected String
protected String
protected boolean
protected boolean
protected String
The name of the export vocabulary...used to generate the output token types interchange file.protected String
protected CodeGenerator
protected boolean
protected boolean
protected String
The name of the import vocabulary.protected boolean
protected int
protected Hashtable
protected Token
protected Vector
protected String
protected Hashtable
protected LLkGrammarAnalyzer
protected TokenManager
The token manager associated with the grammar, if any.protected boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
define
(RuleSymbol rs) Define a ruleabstract void
generate()
Top-level call to generate the code for this grammarprotected String
boolean
int
getIntegerOption
(String key) Get an integer option.Get an option.protected abstract String
boolean
Check the existence of an option in the tableboolean
Is a rule symbol defined? (not used for tokens)abstract void
processArguments
(String[] args) Process command line arguments.void
void
void
boolean
Set a generic option.void
setTokenManager
(TokenManager tokenManager_) toString()
Print out the grammar without actions
-
Field Details
-
antlrTool
-
generator
-
theLLkAnalyzer
-
symbols
-
buildAST
protected boolean buildAST -
analyzerDebug
protected boolean analyzerDebug -
interactive
protected boolean interactive -
superClass
-
tokenManager
The token manager associated with the grammar, if any. // The token manager is responsible for maintaining the set of valid tokens, and // is conceptually shared between the lexer and parser. This may be either a // LexerGrammar or a ImportVocabTokenManager. -
exportVocab
The name of the export vocabulary...used to generate the output token types interchange file. -
importVocab
The name of the import vocabulary. "Initial conditions" -
options
-
rules
-
preambleAction
-
className
-
fileName
-
classMemberAction
-
hasSyntacticPredicate
protected boolean hasSyntacticPredicate -
hasUserErrorHandling
protected boolean hasUserErrorHandling -
maxk
protected int maxk -
traceRules
protected boolean traceRules -
debuggingOutput
protected boolean debuggingOutput -
defaultErrorHandler
protected boolean defaultErrorHandler -
comment
-
-
Constructor Details
-
Grammar
-
-
Method Details
-
define
Define a rule -
generate
Top-level call to generate the code for this grammar- Throws:
IOException
-
getClassName
-
getDefaultErrorHandler
public boolean getDefaultErrorHandler() -
getFilename
-
getIntegerOption
Get an integer option. Given the name of the option find its associated integer value. If the associated value is not an integer or is not in the table, then throw an exception of type NumberFormatException.- Parameters:
key
- The name of the option- Returns:
- The value associated with the key.
- Throws:
NumberFormatException
-
getOption
Get an option. Given the name of the option find its associated value.- Parameters:
key
- The name of the option- Returns:
- The value associated with the key, or null if the key has not been set.
-
getSuperClass
-
getSymbol
-
getSymbols
-
hasOption
Check the existence of an option in the table- Parameters:
key
- The name of the option- Returns:
- true if the option is in the table
-
isDefined
Is a rule symbol defined? (not used for tokens) -
processArguments
Process command line arguments. Implemented in subclasses -
setCodeGenerator
-
setFilename
-
setGrammarAnalyzer
-
setOption
Set a generic option. This associates a generic option key with a Token value. No validation is performed by this method, although users of the value (code generation and/or analysis) may require certain formats. The value is stored as a token so that the location of an error can be reported.- Parameters:
key
- The name of the option.value
- The value to associate with the key.- Returns:
- true if the option was a valid generic grammar option, false o/w
-
setTokenManager
-
toString
Print out the grammar without actions
-