Package org.antlr.v4.semantics
Class SemanticPipeline
java.lang.Object
org.antlr.v4.semantics.SemanticPipeline
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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) void
assignChannelTypes
(Grammar g, List<GrammarAST> channelDefs) Assign constant values to custom channels defined in a grammar.(package private) void
assignLexerTokenTypes
(Grammar g, List<GrammarAST> tokensDefs) (package private) void
assignTokenTypes
(Grammar g, List<GrammarAST> tokensDefs, List<GrammarAST> tokenIDs, List<GrammarAST> terminals) (package private) boolean
(package private) void
identifyStartRules
(SymbolCollector collector) void
process()
-
Field Details
-
g
-
-
Constructor Details
-
SemanticPipeline
-
-
Method Details
-
process
public void process() -
identifyStartRules
-
assignLexerTokenTypes
-
hasTypeOrMoreCommand
-
assignTokenTypes
void assignTokenTypes(Grammar g, List<GrammarAST> tokensDefs, List<GrammarAST> tokenIDs, List<GrammarAST> terminals) -
assignChannelTypes
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.
-