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/codegen/CodeGenerator.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.codegen; import org.antlr.v4.Tool; import org.antlr.v4.codegen.model.OutputModelObject; import org.antlr.v4.runtime.Token; import org.antlr.v4.tool.ErrorType; import org.antlr.v4.tool.Grammar; import org.stringtemplate.v4.AutoIndentWriter; import org.stringtemplate.v4.ST; import org.stringtemplate.v4.STGroup; import org.stringtemplate.v4.STWriter; import java.io.IOException; import java.io.Writer; import java.lang.reflect.Constructor; import java.util.LinkedHashMap; import java.util.Map; /** General controller for code gen. Can instantiate sub generator(s). */ public class CodeGenerator { public static final String TEMPLATE_ROOT = "org/antlr/v4/tool/templates/codegen"; public static final String VOCAB_FILE_EXTENSION = ".tokens"; public static final String vocabFilePattern = "<tokens.keys:{t | <t>=<tokens.(t)>\n}>" + "<literals.keys:{t | <t>=<literals.(t)>\n}>"; public final Grammar g; public final Tool tool; public final String language; private Target target; public int lineWidth = 72; public static CodeGenerator create(Grammar g) { return create(g.tool, g, g.getLanguage()); } public static CodeGenerator create(Tool tool, Grammar g, String language) { String targetName = "org.antlr.v4.codegen.target."+language+"Target"; try { Class<? extends Target> c = Class.forName(targetName).asSubclass(Target.class); Constructor<? extends Target> ctor = c.getConstructor(CodeGenerator.class); CodeGenerator codeGenerator = new CodeGenerator(tool, g, language); codeGenerator.target = ctor.newInstance(codeGenerator); return codeGenerator; } catch (Exception e) { g.tool.errMgr.toolError(ErrorType.CANNOT_CREATE_TARGET_GENERATOR, e, language); return null; } } private CodeGenerator(Tool tool, Grammar g, String language) { this.g = g; this.tool = tool; this.language = language; } public Target getTarget() { return target; } public STGroup getTemplates() { return target.getTemplates(); } // CREATE TEMPLATES BY WALKING MODEL private OutputModelController createController() { OutputModelFactory factory = new ParserFactory(this); OutputModelController controller = new OutputModelController(factory); factory.setController(controller); return controller; } private ST walk(OutputModelObject outputModel, boolean header) { OutputModelWalker walker = new OutputModelWalker(tool, getTemplates()); return walker.walk(outputModel, header); } public ST generateLexer() { return generateLexer(false); } public ST generateLexer(boolean header) { return walk(createController().buildLexerOutputModel(header), header); } public ST generateParser() { return generateParser(false); } public ST generateParser(boolean header) { return walk(createController().buildParserOutputModel(header), header); } public ST generateListener() { return generateListener(false); } public ST generateListener(boolean header) { return walk(createController().buildListenerOutputModel(header), header); } public ST generateBaseListener() { return generateBaseListener(false); } public ST generateBaseListener(boolean header) { return walk(createController().buildBaseListenerOutputModel(header), header); } public ST generateVisitor() { return generateVisitor(false); } public ST generateVisitor(boolean header) { return walk(createController().buildVisitorOutputModel(header), header); } public ST generateBaseVisitor() { return generateBaseVisitor(false); } public ST generateBaseVisitor(boolean header) { return walk(createController().buildBaseVisitorOutputModel(header), header); } /** Generate a token vocab file with all the token names/types. For example: * ID=7 * FOR=8 * 'for'=8 * * This is independent of the target language; used by antlr internally */ ST getTokenVocabOutput() { ST vocabFileST = new ST(vocabFilePattern); Map<String,Integer> tokens = new LinkedHashMap<String,Integer>(); // make constants for the token names for (String t : g.tokenNameToTypeMap.keySet()) { int tokenType = g.tokenNameToTypeMap.get(t); if ( tokenType>=Token.MIN_USER_TOKEN_TYPE) { tokens.put(t, tokenType); } } vocabFileST.add("tokens", tokens); // now dump the strings Map<String,Integer> literals = new LinkedHashMap<String,Integer>(); for (String literal : g.stringLiteralToTypeMap.keySet()) { int tokenType = g.stringLiteralToTypeMap.get(literal); if ( tokenType>=Token.MIN_USER_TOKEN_TYPE) { literals.put(literal, tokenType); } } vocabFileST.add("literals", literals); return vocabFileST; } public void writeRecognizer(ST outputFileST, boolean header) { target.genFile(g, outputFileST, getRecognizerFileName(header)); } public void writeListener(ST outputFileST, boolean header) { target.genFile(g, outputFileST, getListenerFileName(header)); } public void writeBaseListener(ST outputFileST, boolean header) { target.genFile(g, outputFileST, getBaseListenerFileName(header)); } public void writeVisitor(ST outputFileST, boolean header) { target.genFile(g, outputFileST, getVisitorFileName(header)); } public void writeBaseVisitor(ST outputFileST, boolean header) { target.genFile(g, outputFileST, getBaseVisitorFileName(header)); } public void writeVocabFile() { // write out the vocab interchange file; used by antlr, // does not change per target ST tokenVocabSerialization = getTokenVocabOutput(); String fileName = getVocabFileName(); if ( fileName!=null ) { target.genFile(g, tokenVocabSerialization, fileName); } } public void write(ST code, String fileName) { try { // long start = System.currentTimeMillis(); Writer w = tool.getOutputFileWriter(g, fileName); STWriter wr = new AutoIndentWriter(w); wr.setLineWidth(lineWidth); code.write(wr); w.close(); // long stop = System.currentTimeMillis(); } catch (IOException ioe) { tool.errMgr.toolError(ErrorType.CANNOT_WRITE_FILE, ioe, fileName); } } public String getRecognizerFileName() { return getRecognizerFileName(false); } public String getListenerFileName() { return getListenerFileName(false); } public String getVisitorFileName() { return getVisitorFileName(false); } public String getBaseListenerFileName() { return getBaseListenerFileName(false); } public String getBaseVisitorFileName() { return getBaseVisitorFileName(false); } public String getRecognizerFileName(boolean header) { return target.getRecognizerFileName(header); } public String getListenerFileName(boolean header) { return target.getListenerFileName(header); } public String getVisitorFileName(boolean header) { return target.getVisitorFileName(header); } public String getBaseListenerFileName(boolean header) { return target.getBaseListenerFileName(header); } public String getBaseVisitorFileName(boolean header) { return target.getBaseVisitorFileName(header); } /** What is the name of the vocab file generated for this grammar? * Returns null if no .tokens file should be generated. */ public String getVocabFileName() { return g.name+VOCAB_FILE_EXTENSION; } public String getHeaderFileName() { ST extST = getTemplates().getInstanceOf("headerFileExtension"); if ( extST==null ) return null; String recognizerName = g.getRecognizerName(); return recognizerName+extST.render(); } }
⏎ org/antlr/v4/codegen/CodeGenerator.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, 32010👍, 0💬
Popular Posts:
Java Cryptography Extension 1.2.2 JAR File Size and Download Location: File name: jce.jar, jce-1.2.2...
commons-net-1.4.1.jar is the JAR file for Apache Commons Net 1.4.1, which implements the client side...
JDK 11 jdk.jlink.jmod is the JMOD file for JDK 11 JLink tool, which can be invoked by the "jlink" co...
Apache Commons Lang 3 is the 3rd version of Apache Commons Lang, which provides a host of helper uti...
How to download and install ojdbc14.jar for Oracle 10g R2? ojdbc14.jar for Oracle 10g R2 is a Java 1...