antlr

Class Grammar

public abstract class Grammar extends Object

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
protected booleananalyzerDebug
protected ToolantlrTool
protected booleanbuildAST
protected TokenclassMemberAction
protected StringclassName
protected Stringcomment
protected booleandebuggingOutput
protected booleandefaultErrorHandler
protected StringexportVocab
The name of the export vocabulary...used to generate the output token types interchange file.
protected StringfileName
protected CodeGeneratorgenerator
protected booleanhasSyntacticPredicate
protected booleanhasUserErrorHandling
protected StringimportVocab
The name of the import vocabulary.
protected booleaninteractive
protected intmaxk
protected Hashtableoptions
protected TokenpreambleAction
protected Vectorrules
protected StringsuperClass
protected Hashtablesymbols
protected LLkGrammarAnalyzertheLLkAnalyzer
protected TokenManagertokenManager
The token manager associated with the grammar, if any.
protected booleantraceRules
Constructor Summary
Grammar(String className_, Tool tool_, String superClass)
Method Summary
voiddefine(RuleSymbol rs)
Define a rule
abstract voidgenerate()
Top-level call to generate the code for this grammar
protected StringgetClassName()
booleangetDefaultErrorHandler()
StringgetFilename()
intgetIntegerOption(String key)
Get an integer option.
TokengetOption(String key)
Get an option.
protected abstract StringgetSuperClass()
GrammarSymbolgetSymbol(String s)
EnumerationgetSymbols()
booleanhasOption(String key)
Check the existence of an option in the table
booleanisDefined(String s)
Is a rule symbol defined?
abstract voidprocessArguments(String[] args)
Process command line arguments.
voidsetCodeGenerator(CodeGenerator gen)
voidsetFilename(String s)
voidsetGrammarAnalyzer(LLkGrammarAnalyzer a)
booleansetOption(String key, Token value)
Set a generic option.
voidsetTokenManager(TokenManager tokenManager_)
StringtoString()
Print out the grammar without actions

Field Detail

analyzerDebug

protected boolean analyzerDebug

antlrTool

protected Tool antlrTool

buildAST

protected boolean buildAST

classMemberAction

protected Token classMemberAction

className

protected String className

comment

protected String comment

debuggingOutput

protected boolean debuggingOutput

defaultErrorHandler

protected boolean defaultErrorHandler

exportVocab

protected String exportVocab
The name of the export vocabulary...used to generate the output token types interchange file.

fileName

protected String fileName

generator

protected CodeGenerator generator

hasSyntacticPredicate

protected boolean hasSyntacticPredicate

hasUserErrorHandling

protected boolean hasUserErrorHandling

importVocab

protected String importVocab
The name of the import vocabulary. "Initial conditions"

interactive

protected boolean interactive

maxk

protected int maxk

options

protected Hashtable options

preambleAction

protected Token preambleAction

rules

protected Vector rules

superClass

protected String superClass

symbols

protected Hashtable symbols

theLLkAnalyzer

protected LLkGrammarAnalyzer theLLkAnalyzer

tokenManager

protected TokenManager 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.

traceRules

protected boolean traceRules

Constructor Detail

Grammar

public Grammar(String className_, Tool tool_, String superClass)

Method Detail

define

public void define(RuleSymbol rs)
Define a rule

generate

public abstract void generate()
Top-level call to generate the code for this grammar

getClassName

protected String getClassName()

getDefaultErrorHandler

public boolean getDefaultErrorHandler()

getFilename

public String getFilename()

getIntegerOption

public int getIntegerOption(String key)
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.

getOption

public Token getOption(String key)
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

protected abstract String getSuperClass()

getSymbol

public GrammarSymbol getSymbol(String s)

getSymbols

public Enumeration getSymbols()

hasOption

public boolean hasOption(String key)
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

public boolean isDefined(String s)
Is a rule symbol defined? (not used for tokens)

processArguments

public abstract void processArguments(String[] args)
Process command line arguments. Implemented in subclasses

setCodeGenerator

public void setCodeGenerator(CodeGenerator gen)

setFilename

public void setFilename(String s)

setGrammarAnalyzer

public void setGrammarAnalyzer(LLkGrammarAnalyzer a)

setOption

public boolean setOption(String key, Token value)
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

public void setTokenManager(TokenManager tokenManager_)

toString

public String toString()
Print out the grammar without actions