Package org.antlr.v4.semantics
Class SemanticPipeline
- java.lang.Object
-
- org.antlr.v4.semantics.SemanticPipeline
-
public class SemanticPipeline extends java.lang.Object
Do as much semantic checking as we can and fill in grammar with rules, actions, and token definitions. The only side effects are in the grammar passed to process(). We consume a bunch of memory here while we build up data structures to perform checking, but all of it goes away after this pipeline object gets garbage collected. After this pipeline finishes, we can be sure that the grammar is syntactically correct and that it's semantically correct enough for us to attempt grammar analysis. We have assigned all token types. Note that imported grammars bring in token and rule definitions but only the root grammar and any implicitly created lexer grammar get their token definitions filled up. We are treating the imported grammars like includes. The semantic pipeline works on root grammars (those that do the importing, if any). Upon entry to the semantic pipeline, all imported grammars should have been loaded into delegate grammar objects with their ASTs created. The pipeline does the BasicSemanticChecks on the imported grammar before collecting symbols. We cannot perform the simple checks such as undefined rule until we have collected all tokens and rules from the imported grammars into a single collection.
-
-
Constructor Summary
Constructors Constructor Description SemanticPipeline(Grammar g)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
assignChannelTypes(Grammar g, java.util.List<GrammarAST> channelDefs)
Assign constant values to custom channels defined in a grammar.(package private) void
assignLexerTokenTypes(Grammar g, java.util.List<GrammarAST> tokensDefs)
(package private) void
assignTokenTypes(Grammar g, java.util.List<GrammarAST> tokensDefs, java.util.List<GrammarAST> tokenIDs, java.util.List<GrammarAST> terminals)
(package private) boolean
hasTypeOrMoreCommand(Rule r)
(package private) void
identifyStartRules(SymbolCollector collector)
void
process()
-
-
-
Field Detail
-
g
public Grammar g
-
-
Constructor Detail
-
SemanticPipeline
public SemanticPipeline(Grammar g)
-
-
Method Detail
-
process
public void process()
-
identifyStartRules
void identifyStartRules(SymbolCollector collector)
-
assignLexerTokenTypes
void assignLexerTokenTypes(Grammar g, java.util.List<GrammarAST> tokensDefs)
-
hasTypeOrMoreCommand
boolean hasTypeOrMoreCommand(Rule r)
-
assignTokenTypes
void assignTokenTypes(Grammar g, java.util.List<GrammarAST> tokensDefs, java.util.List<GrammarAST> tokenIDs, java.util.List<GrammarAST> terminals)
-
assignChannelTypes
void assignChannelTypes(Grammar g, java.util.List<GrammarAST> channelDefs)
Assign constant values to custom channels defined in a grammar.- Parameters:
g
- The grammar.channelDefs
- A collection of AST nodes defining individual channels within achannels{}
block in the grammar.
-
-