Top Description Fields Constructors Methods
org.antlr.v4.semantics

public Class SemanticPipeline

extends Object
Class Inheritance
Imports
org.antlr.v4.analysis.LeftRecursiveRuleTransformer, org.antlr.v4.automata.LexerATNFactory, org.antlr.v4.parse.ANTLRParser, org.antlr.v4.runtime.Token, org.antlr.v4.runtime.misc.Pair, org.antlr.v4.tool.ErrorType, .Grammar, .LexerGrammar, .Rule, org.antlr.v4.tool.ast.GrammarAST, java.util.HashSet, .List, .Set

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

Modifier and TypeField and Description
public Grammar
g

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv void
assignChannelTypes(Grammar
The grammar.
g
,
List<GrammarAST>
A collection of AST nodes defining individual channels within a channels{} block in the grammar.
channelDefs
)

Assign constant values to custom channels defined in a grammar.

pack-priv void
pack-priv void
assignTokenTypes(Grammar g, List<GrammarAST> tokensDefs, List<GrammarAST> tokenIDs, List<GrammarAST> terminals)

pack-priv boolean
pack-priv void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

gback to summary
public Grammar g

Constructor Detail

SemanticPipelineback to summary
public SemanticPipeline(Grammar g)

Method Detail

assignChannelTypesback to summary
pack-priv void assignChannelTypes(Grammar g, List<GrammarAST> channelDefs)

Assign constant values to custom channels defined in a grammar.

Parameters
g:Grammar

The grammar.

channelDefs:List<GrammarAST>

A collection of AST nodes defining individual channels within a channels{} block in the grammar.

assignLexerTokenTypesback to summary
pack-priv void assignLexerTokenTypes(Grammar g, List<GrammarAST> tokensDefs)
assignTokenTypesback to summary
pack-priv void assignTokenTypes(Grammar g, List<GrammarAST> tokensDefs, List<GrammarAST> tokenIDs, List<GrammarAST> terminals)
hasTypeOrMoreCommandback to summary
pack-priv boolean hasTypeOrMoreCommand(Rule r)
identifyStartRulesback to summary
pack-priv void identifyStartRules(SymbolCollector collector)
processback to summary
public void process()