Package org.antlr.tool
Class CompositeGrammar
java.lang.Object
org.antlr.tool.CompositeGrammar
A tree of component (delegate) grammars.
Rules defined in delegates are "inherited" like multi-inheritance
so you can override them. All token types must be consistent across
rules from all delegate grammars, so they must be stored here in one
central place.
We have to start out assuming a composite grammar situation as we can't
look into the grammar files a priori to see if there is a delegate
statement. Because of this, and to avoid duplicating token type tracking
in each grammar, even single noncomposite grammars use one of these objects
to track token types.
-
Field Summary
FieldsModifier and TypeFieldDescriptionIf combined or lexer grammar, track the rules.protected int
Token names and literal tokens like "void" are uniquely indexed.static final int
The NFA states in the NFA built from rules across grammars in composite.Used during getRuleReferenceClosure to detect computation cyclesprotected int
Rules are uniquely labeled from 1..n among all grammarsMap a rule index to its name; use a Vector on purpose as new collections stuff won't let me setSize and make it grow.int
Used to assign state numbers; all grammars in composite share common NFA space.Map token literals like "while" to its token type.Map token like ID (but not literals like "while") to its token typeReverse index for stringLiteralToTypeMapMap a token type to its token name.boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
_minimizeRuleSet
(Set<String> ruleDefs, CompositeGrammarTree p) void
addGrammar
(Grammar delegator, Grammar delegate) Add delegate grammar as child of delegatorvoid
void
void
void
Get all rule definitions from all direct/indirect delegate grammars of g.Get set of rules for grammar g that need to have manual delegation methods.Get list of all delegates from all grammars in the delegate subtree of g.Get parent of this grammarReturn list of delegate grammars from root down to g.getGrammar
(String grammarName) Get delegates below direct delegates of gint
getState
(int s) protected void
void
void
setDelegationRoot
(Grammar root)
-
Field Details
-
MIN_RULE_INDEX
public static final int MIN_RULE_INDEX- See Also:
-
delegateGrammarTreeRoot
-
refClosureBusy
Used during getRuleReferenceClosure to detect computation cycles -
stateCounter
public int stateCounterUsed to assign state numbers; all grammars in composite share common NFA space. This NFA tracks state numbers number to state mapping. -
numberToStateList
The NFA states in the NFA built from rules across grammars in composite. Maps state number to NFAState object. This is a Vector instead of a List because I need to be able to grow this properly. After talking to Josh Bloch, Collections guy at Sun, I decided this was easiest solution. -
maxTokenType
protected int maxTokenTypeToken names and literal tokens like "void" are uniquely indexed. with -1 implying EOF. Characters are different; they go from -1 (EOF) to . For example, 0 could be a binary byte you want to lexer. Labels of DFA/NFA transitions can be both tokens and characters. I use negative numbers for bookkeeping labels like EPSILON. Char/String literals and token types overlap in the same space, however. -
tokenIDToTypeMap
Map token like ID (but not literals like "while") to its token type -
stringLiteralToTypeMap
Map token literals like "while" to its token type. It may be that WHILE="while"=35, in which case both tokenIDToTypeMap and this field will have entries both mapped to 35. -
typeToStringLiteralList
Reverse index for stringLiteralToTypeMap -
typeToTokenList
Map a token type to its token name. Must subtract MIN_TOKEN_TYPE from index. -
lexerRules
If combined or lexer grammar, track the rules. Track lexer rules so we can warn about undefined tokens. This is combined set of lexer rules from all lexer grammars seen in all imports. -
ruleIndex
protected int ruleIndexRules are uniquely labeled from 1..n among all grammars -
ruleIndexToRuleList
Map a rule index to its name; use a Vector on purpose as new collections stuff won't let me setSize and make it grow. :( I need a specific guaranteed index, which the Collections stuff won't let me have. -
watchNFAConversion
public boolean watchNFAConversion
-
-
Constructor Details
-
CompositeGrammar
public CompositeGrammar() -
CompositeGrammar
-
-
Method Details
-
initTokenSymbolTables
protected void initTokenSymbolTables() -
setDelegationRoot
-
getRule
-
getOption
-
addGrammar
Add delegate grammar as child of delegator -
getDelegator
Get parent of this grammar -
getDelegates
Get list of all delegates from all grammars in the delegate subtree of g. The grammars are in delegation tree preorder. Don't include g itself in list as it is not a delegate of itself. -
getDirectDelegates
-
getIndirectDelegates
Get delegates below direct delegates of g -
getDelegators
Return list of delegate grammars from root down to g. Order is root, ..., g.parent. (g not included). -
getDelegatedRules
Get set of rules for grammar g that need to have manual delegation methods. This is the list of rules collected from all direct/indirect delegates minus rules overridden in grammar g. This returns null except for the delegate root because it is the only one that has to have a complete grammar rule interface. The delegates should not be instantiated directly for use as parsers (you can create them to pass to the root parser's ctor as arguments). -
getAllImportedRules
Get all rule definitions from all direct/indirect delegate grammars of g. -
getRootGrammar
-
getGrammar
-
getNewNFAStateNumber
public int getNewNFAStateNumber() -
addState
-
getState
-
assignTokenTypes
public void assignTokenTypes() throws antlr.RecognitionException- Throws:
antlr.RecognitionException
-
defineGrammarSymbols
public void defineGrammarSymbols() -
createNFAs
public void createNFAs() -
minimizeRuleSet
public void minimizeRuleSet() -
_minimizeRuleSet
-