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/automata/ATNPrinter.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.automata; import org.antlr.v4.runtime.atn.ATNState; import org.antlr.v4.runtime.atn.ActionTransition; import org.antlr.v4.runtime.atn.AtomTransition; import org.antlr.v4.runtime.atn.BlockEndState; import org.antlr.v4.runtime.atn.BlockStartState; import org.antlr.v4.runtime.atn.EpsilonTransition; import org.antlr.v4.runtime.atn.NotSetTransition; import org.antlr.v4.runtime.atn.PlusBlockStartState; import org.antlr.v4.runtime.atn.PlusLoopbackState; import org.antlr.v4.runtime.atn.RuleStartState; import org.antlr.v4.runtime.atn.RuleStopState; import org.antlr.v4.runtime.atn.RuleTransition; import org.antlr.v4.runtime.atn.SetTransition; import org.antlr.v4.runtime.atn.StarBlockStartState; import org.antlr.v4.runtime.atn.StarLoopEntryState; import org.antlr.v4.runtime.atn.StarLoopbackState; import org.antlr.v4.runtime.atn.Transition; import org.antlr.v4.tool.Grammar; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; /** An ATN walker that knows how to dump them to serialized strings. */ public class ATNPrinter { List<ATNState> work; Set<ATNState> marked; Grammar g; ATNState start; public ATNPrinter(Grammar g, ATNState start) { this.g = g; this.start = start; } public String asString() { if ( start==null ) return null; marked = new HashSet<ATNState>(); work = new ArrayList<ATNState>(); work.add(start); StringBuilder buf = new StringBuilder(); ATNState s; while ( !work.isEmpty() ) { s = work.remove(0); if ( marked.contains(s) ) continue; int n = s.getNumberOfTransitions(); // System.out.println("visit "+s+"; edges="+n); marked.add(s); for (int i=0; i<n; i++) { Transition t = s.transition(i); if ( !(s instanceof RuleStopState) ) { // don't add follow states to work if ( t instanceof RuleTransition ) work.add(((RuleTransition)t).followState); else work.add( t.target ); } buf.append(getStateString(s)); if ( t instanceof EpsilonTransition ) { buf.append("->").append(getStateString(t.target)).append('\n'); } else if ( t instanceof RuleTransition ) { buf.append("-").append(g.getRule(((RuleTransition)t).ruleIndex).name).append("->").append(getStateString(t.target)).append('\n'); } else if ( t instanceof ActionTransition ) { ActionTransition a = (ActionTransition)t; buf.append("-").append(a.toString()).append("->").append(getStateString(t.target)).append('\n'); } else if ( t instanceof SetTransition ) { SetTransition st = (SetTransition)t; boolean not = st instanceof NotSetTransition; if ( g.isLexer() ) { buf.append("-").append(not?"~":"").append(st.toString()).append("->").append(getStateString(t.target)).append('\n'); } else { buf.append("-").append(not?"~":"").append(st.label().toString(g.getVocabulary())).append("->").append(getStateString(t.target)).append('\n'); } } else if ( t instanceof AtomTransition ) { AtomTransition a = (AtomTransition)t; String label = g.getTokenDisplayName(a.label); buf.append("-").append(label).append("->").append(getStateString(t.target)).append('\n'); } else { buf.append("-").append(t.toString()).append("->").append(getStateString(t.target)).append('\n'); } } } return buf.toString(); } String getStateString(ATNState s) { int n = s.stateNumber; String stateStr = "s"+n; if ( s instanceof StarBlockStartState ) stateStr = "StarBlockStart_"+n; else if ( s instanceof PlusBlockStartState ) stateStr = "PlusBlockStart_"+n; else if ( s instanceof BlockStartState) stateStr = "BlockStart_"+n; else if ( s instanceof BlockEndState ) stateStr = "BlockEnd_"+n; else if ( s instanceof RuleStartState) stateStr = "RuleStart_"+g.getRule(s.ruleIndex).name+"_"+n; else if ( s instanceof RuleStopState ) stateStr = "RuleStop_"+g.getRule(s.ruleIndex).name+"_"+n; else if ( s instanceof PlusLoopbackState) stateStr = "PlusLoopBack_"+n; else if ( s instanceof StarLoopbackState) stateStr = "StarLoopBack_"+n; else if ( s instanceof StarLoopEntryState) stateStr = "StarLoopEntry_"+n; return stateStr; } }
⏎ org/antlr/v4/automata/ATNPrinter.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, 31785👍, 0💬
Popular Posts:
What Is commons-logging-1.2.jar? commons-logging-1.2.jar is the JAR file for Apache Commons Logging ...
JDK 7 tools.jar is the JAR file for JDK 7 tools. It contains Java classes to support different JDK t...
commons-fileupload-1.3.3 -sources.jaris the source JAR file for Apache Commons FileUpload 1.3., whic...
What Is javaws.jar in JRE (Java Runtime Environment) 8? javaws.jar in JRE (Java Runtime Environment)...
How to download and install JDK (Java Development Kit) 5? If you want to write Java applications, yo...