Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
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 (322)
Collections:
Other Resources:
ANTLR Runtime Source Code
ANTLR is a powerful parser generator for multiple programming languages
including Java.
ANTLR contains 2 major modules:
ANTLR Runtime 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/runtime/misc/InterpreterDataReader.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.runtime.misc;
import org.antlr.v4.runtime.Vocabulary;
import org.antlr.v4.runtime.VocabularyImpl;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.dfa.DFA;
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.FileReader;
// A class to read plain text interpreter data produced by ANTLR.
public class InterpreterDataReader {
public static class InterpreterData {
ATN atn;
Vocabulary vocabulary;
List<String> ruleNames;
List<String> channels; // Only valid for lexer grammars.
List<String> modes; // ditto
};
/**
* The structure of the data file is very simple. Everything is line based with empty lines
* separating the different parts. For lexers the layout is:
* token literal names:
* ...
*
* token symbolic names:
* ...
*
* rule names:
* ...
*
* channel names:
* ...
*
* mode names:
* ...
*
* atn:
* <a single line with comma separated int values> enclosed in a pair of squared brackets.
*
* Data for a parser does not contain channel and mode names.
*/
public static InterpreterData parseFile(String fileName) {
InterpreterData result = new InterpreterData();
result.ruleNames = new ArrayList<String>();
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
String line;
List<String> literalNames = new ArrayList<String>();
List<String> symbolicNames = new ArrayList<String>();
line = br.readLine();
if ( !line.equals("token literal names:") )
throw new RuntimeException("Unexpected data entry");
while ((line = br.readLine()) != null) {
if ( line.isEmpty() )
break;
literalNames.add(line.equals("null") ? "" : line);
}
line = br.readLine();
if ( !line.equals("token symbolic names:") )
throw new RuntimeException("Unexpected data entry");
while ((line = br.readLine()) != null) {
if ( line.isEmpty() )
break;
symbolicNames.add(line.equals("null") ? "" : line);
}
result.vocabulary = new VocabularyImpl(literalNames.toArray(new String[0]), symbolicNames.toArray(new String[0]));
line = br.readLine();
if ( !line.equals("rule names:") )
throw new RuntimeException("Unexpected data entry");
while ((line = br.readLine()) != null) {
if ( line.isEmpty() )
break;
result.ruleNames.add(line);
}
line = br.readLine();
if ( line.equals("channel names:") ) { // Additional lexer data.
result.channels = new ArrayList<String>();
while ((line = br.readLine()) != null) {
if ( line.isEmpty() )
break;
result.channels.add(line);
}
line = br.readLine();
if ( !line.equals("mode names:") )
throw new RuntimeException("Unexpected data entry");
result.modes = new ArrayList<String>();
while ((line = br.readLine()) != null) {
if ( line.isEmpty() )
break;
result.modes.add(line);
}
}
line = br.readLine();
if ( !line.equals("atn:") )
throw new RuntimeException("Unexpected data entry");
line = br.readLine();
String[] elements = line.substring(1,line.length()-1).split(",");
int[] serializedATN = new int[elements.length];
for (int i = 0; i < elements.length; ++i) { // ignore [...] on ends
serializedATN[i] = Integer.parseInt(elements[i].trim());
}
ATNDeserializer deserializer = new ATNDeserializer();
result.atn = deserializer.deserialize(serializedATN);
}
catch (java.io.IOException e) {
// We just swallow the error and return empty objects instead.
}
return result;
}
}
⏎ org/antlr/v4/runtime/misc/InterpreterDataReader.java
Or download all of them as a single archive file:
File name: antlr-runtime-4.10.1-sources.jar File size: 308953 bytes Release date: 2022-04-15 Download
⇐ What Is ANTLR Parser Generator
2018-10-21, ≈85🔥, 0💬
Popular Posts:
Apache Avalon began in 1999 as the Java Apache Server Framework and in late 2002 separated from the ...
JRE 8 rt.jar is the JAR file for JRE 8 RT (Runtime) libraries. JRE (Java Runtime) 8 is the runtime e...
What Is jms.jar? I heard it's related to JMS (Java Message Service) 1.1? The if you have an jms.jar ...
The Jakarta-ORO Java classes are a set of text-processing Java classes that provide Perl5 compatible...
Apache Avalon began in 1999 as the Java Apache Server Framework and in late 2002 separated from the ...