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/RuleCollector.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.analysis.LeftRecursiveRuleAnalyzer; import org.antlr.v4.misc.OrderedHashMap; import org.antlr.v4.misc.Utils; import org.antlr.v4.parse.GrammarTreeVisitor; import org.antlr.v4.parse.ScopeParser; import org.antlr.v4.tool.*; 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.RuleAST; import org.stringtemplate.v4.misc.MultiMap; import java.util.HashMap; import java.util.List; import java.util.Map; public class RuleCollector extends GrammarTreeVisitor { private boolean grammarCaseInsensitive = false; /** which grammar are we checking */ public Grammar g; public ErrorManager errMgr; // stuff to collect. this is the output public OrderedHashMap<String, Rule> rules = new OrderedHashMap<String, Rule>(); public MultiMap<String,GrammarAST> ruleToAltLabels = new MultiMap<String, GrammarAST>(); public Map<String,String> altLabelToRuleName = new HashMap<String, String>(); public RuleCollector(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 discoverRule(RuleAST rule, GrammarAST ID, List<GrammarAST> modifiers, ActionAST arg, ActionAST returns, GrammarAST thrws, GrammarAST options, ActionAST locals, List<GrammarAST> actions, GrammarAST block) { int numAlts = block.getChildCount(); Rule r; if ( LeftRecursiveRuleAnalyzer.hasImmediateRecursiveRuleRefs(rule, ID.getText()) ) { r = new LeftRecursiveRule(g, ID.getText(), rule); } else { r = new Rule(g, ID.getText(), rule, numAlts); } rules.put(r.name, r); if ( arg!=null ) { r.args = ScopeParser.parseTypedArgList(arg, arg.getText(), g); r.args.type = AttributeDict.DictType.ARG; r.args.ast = arg; arg.resolver = r.alt[currentOuterAltNumber]; } if ( returns!=null ) { r.retvals = ScopeParser.parseTypedArgList(returns, returns.getText(), g); r.retvals.type = AttributeDict.DictType.RET; r.retvals.ast = returns; } if ( locals!=null ) { r.locals = ScopeParser.parseTypedArgList(locals, locals.getText(), g); r.locals.type = AttributeDict.DictType.LOCAL; r.locals.ast = locals; } for (GrammarAST a : actions) { // a = ^(AT ID ACTION) ActionAST action = (ActionAST) a.getChild(1); r.namedActions.put(a.getChild(0).getText(), action); action.resolver = r; } } @Override public void discoverOuterAlt(AltAST alt) { if ( alt.altLabel!=null ) { ruleToAltLabels.map(currentRuleName, alt.altLabel); String altLabel = alt.altLabel.getText(); altLabelToRuleName.put(Utils.capitalize(altLabel), currentRuleName); altLabelToRuleName.put(Utils.decapitalize(altLabel), currentRuleName); } } @Override public void grammarOption(GrammarAST ID, GrammarAST valueAST) { Boolean caseInsensitive = getCaseInsensitiveValue(ID, valueAST); if (caseInsensitive != null) { grammarCaseInsensitive = caseInsensitive; } } @Override public void discoverLexerRule(RuleAST rule, GrammarAST ID, List<GrammarAST> modifiers, GrammarAST options, GrammarAST block) { boolean currentCaseInsensitive = grammarCaseInsensitive; if (options != null) { for (Object child : options.getChildren()) { GrammarAST childAST = (GrammarAST) child; Boolean caseInsensitive = getCaseInsensitiveValue((GrammarAST)childAST.getChild(0), (GrammarAST)childAST.getChild(1)); if (caseInsensitive != null) { currentCaseInsensitive = caseInsensitive; } } } int numAlts = block.getChildCount(); Rule r = new Rule(g, ID.getText(), rule, numAlts, currentModeName, currentCaseInsensitive); if ( !modifiers.isEmpty() ) r.modifiers = modifiers; rules.put(r.name, r); } private Boolean getCaseInsensitiveValue(GrammarAST optionID, GrammarAST valueAST) { String optionName = optionID.getText(); if (optionName.equals(Grammar.caseInsensitiveOptionName)) { String valueText = valueAST.getText(); if (valueText.equals("true") || valueText.equals("false")) { return Boolean.parseBoolean(valueText); } } return null; } }
⏎ org/antlr/v4/semantics/RuleCollector.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, 32017👍, 0💬
Popular Posts:
Swingx is the SwingLabs Swing Component Extensions. JAR File Size and Download Location: File name: ...
Jackson is "the Java JSON library" or "the best JSON parser for Java". Or simply as "JSON for Java"....
commons-io-2.6-sources.j aris the source JAR file for Apache Commons IO 2.6, which is a library of u...
How to read XML document with DTD validation from socket connections with the socket\DelayedInput.ja.. .
How to read XML document from socket connections with the socket\DelayedInput.java provided in the A...