Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
ANTLR Tool Source Code
ANTLR is a powerful parser generator for multiple programming languages including Java.
ANTLR contains 2 major modules:
ANTLR Tool Source Code files are provided in the distribution packge (antlr4-4.10.1.zip). You can download them at ANTLR Website.
You can also browse the source code below:
✍: FYIcenter
⏎ org/antlr/v4/semantics/SymbolCollector.java
/* * Copyright (c) 2012-2017 The ANTLR Project. All rights reserved. * Use of this file is governed by the BSD 3-clause license that * can be found in the LICENSE.txt file in the project root. */ package org.antlr.v4.semantics; import org.antlr.v4.parse.GrammarTreeVisitor; import org.antlr.v4.tool.ErrorManager; import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.LabelElementPair; import org.antlr.v4.tool.Rule; import org.antlr.v4.tool.ast.ActionAST; import org.antlr.v4.tool.ast.AltAST; import org.antlr.v4.tool.ast.GrammarAST; import org.antlr.v4.tool.ast.GrammarASTWithOptions; import org.antlr.v4.tool.ast.PredAST; import org.antlr.v4.tool.ast.RuleAST; import org.antlr.v4.tool.ast.TerminalAST; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; /** Collects (create) rules, terminals, strings, actions, scopes etc... from AST * side-effects: sets resolver field of asts for actions and * defines predicates via definePredicateInAlt(), collects actions and stores * in alts. * TODO: remove side-effects! */ public class SymbolCollector extends GrammarTreeVisitor { /** which grammar are we checking */ public Grammar g; // stuff to collect public List<GrammarAST> rulerefs = new ArrayList<GrammarAST>(); public List<GrammarAST> qualifiedRulerefs = new ArrayList<GrammarAST>(); public List<GrammarAST> terminals = new ArrayList<GrammarAST>(); public List<GrammarAST> tokenIDRefs = new ArrayList<GrammarAST>(); public Set<String> strings = new HashSet<String>(); public List<GrammarAST> tokensDefs = new ArrayList<GrammarAST>(); public List<GrammarAST> channelDefs = new ArrayList<GrammarAST>(); /** Track action name node in @parser::members {...} or @members {...} */ List<GrammarAST> namedActions = new ArrayList<GrammarAST>(); public ErrorManager errMgr; // context public Rule currentRule; public SymbolCollector(Grammar g) { this.g = g; this.errMgr = g.tool.errMgr; } @Override public ErrorManager getErrorManager() { return errMgr; } public void process(GrammarAST ast) { visitGrammar(ast); } @Override public void globalNamedAction(GrammarAST scope, GrammarAST ID, ActionAST action) { namedActions.add((GrammarAST)ID.getParent()); action.resolver = g; } @Override public void defineToken(GrammarAST ID) { terminals.add(ID); tokenIDRefs.add(ID); tokensDefs.add(ID); } @Override public void defineChannel(GrammarAST ID) { channelDefs.add(ID); } @Override public void discoverRule(RuleAST rule, GrammarAST ID, List<GrammarAST> modifiers, ActionAST arg, ActionAST returns, GrammarAST thrws, GrammarAST options, ActionAST locals, List<GrammarAST> actions, GrammarAST block) { currentRule = g.getRule(ID.getText()); } @Override public void discoverLexerRule(RuleAST rule, GrammarAST ID, List<GrammarAST> modifiers, GrammarAST options, GrammarAST block) { currentRule = g.getRule(ID.getText()); } @Override public void discoverOuterAlt(AltAST alt) { currentRule.alt[currentOuterAltNumber].ast = alt; } @Override public void actionInAlt(ActionAST action) { currentRule.defineActionInAlt(currentOuterAltNumber, action); action.resolver = currentRule.alt[currentOuterAltNumber]; } @Override public void sempredInAlt(PredAST pred) { currentRule.definePredicateInAlt(currentOuterAltNumber, pred); pred.resolver = currentRule.alt[currentOuterAltNumber]; } @Override public void ruleCatch(GrammarAST arg, ActionAST action) { GrammarAST catchme = (GrammarAST)action.getParent(); currentRule.exceptions.add(catchme); action.resolver = currentRule; } @Override public void finallyAction(ActionAST action) { currentRule.finallyAction = action; action.resolver = currentRule; } @Override public void label(GrammarAST op, GrammarAST ID, GrammarAST element) { LabelElementPair lp = new LabelElementPair(g, ID, element, op.getType()); currentRule.alt[currentOuterAltNumber].labelDefs.map(ID.getText(), lp); } @Override public void stringRef(TerminalAST ref) { terminals.add(ref); strings.add(ref.getText()); if ( currentRule!=null ) { currentRule.alt[currentOuterAltNumber].tokenRefs.map(ref.getText(), ref); } } @Override public void tokenRef(TerminalAST ref) { terminals.add(ref); tokenIDRefs.add(ref); if ( currentRule!=null ) { currentRule.alt[currentOuterAltNumber].tokenRefs.map(ref.getText(), ref); } } @Override public void ruleRef(GrammarAST ref, ActionAST arg) { // if ( inContext("DOT ...") ) qualifiedRulerefs.add((GrammarAST)ref.getParent()); rulerefs.add(ref); if ( currentRule!=null ) { currentRule.alt[currentOuterAltNumber].ruleRefs.map(ref.getText(), ref); } } @Override public void grammarOption(GrammarAST ID, GrammarAST valueAST) { setActionResolver(valueAST); } @Override public void ruleOption(GrammarAST ID, GrammarAST valueAST) { setActionResolver(valueAST); } @Override public void blockOption(GrammarAST ID, GrammarAST valueAST) { setActionResolver(valueAST); } @Override public void elementOption(GrammarASTWithOptions t, GrammarAST ID, GrammarAST valueAST) { setActionResolver(valueAST); } /** In case of option id={...}, set resolve in case they use $foo */ private void setActionResolver(GrammarAST valueAST) { if ( valueAST instanceof ActionAST) { ((ActionAST)valueAST).resolver = currentRule.alt[currentOuterAltNumber]; } } }
⏎ org/antlr/v4/semantics/SymbolCollector.java
Or download all of them as a single archive file:
File name: antlr-tool-4.10.1-sources.jar File size: 347718 bytes Release date: 2022-04-15 Download
2022-04-24, 31977👍, 0💬
Popular Posts:
JDK 11 jdk.rmic.jmod is the JMOD file for JDK 11 RMI (Remote Method Invocation) Compiler Tool tool, ...
Apache ZooKeeper is an open-source server which enables highly reliable distributed coordination. Ap...
What Is ojdbc5.jar for Oracle 11g R1? ojdbc5.jar for Oracle 11g R1 is the JAR files of ojdbc.jar, JD...
maven-core-3.5.4.jar is the JAR file for Apache Maven 3.5.4 Core module. Apache Maven is a software ...
Apache ZooKeeper is an open-source server which enables highly reliable distributed coordination. Ap...