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 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/dfa/DFA.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.dfa; import org.antlr.v4.runtime.Parser; import org.antlr.v4.runtime.Vocabulary; import org.antlr.v4.runtime.VocabularyImpl; import org.antlr.v4.runtime.atn.ATNConfigSet; import org.antlr.v4.runtime.atn.DecisionState; import org.antlr.v4.runtime.atn.StarLoopEntryState; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; public class DFA { /** A set of all DFA states. Use {@link Map} so we can get old state back * ({@link Set} only allows you to see if it's there). */ public final Map<DFAState, DFAState> states = new HashMap<DFAState, DFAState>(); public volatile DFAState s0; public final int decision; /** From which ATN state did we create this DFA? */ public final DecisionState atnStartState; /** * {@code true} if this DFA is for a precedence decision; otherwise, * {@code false}. This is the backing field for {@link #isPrecedenceDfa}. */ private final boolean precedenceDfa; public DFA(DecisionState atnStartState) { this(atnStartState, 0); } public DFA(DecisionState atnStartState, int decision) { this.atnStartState = atnStartState; this.decision = decision; boolean precedenceDfa = false; if (atnStartState instanceof StarLoopEntryState) { if (((StarLoopEntryState)atnStartState).isPrecedenceDecision) { precedenceDfa = true; DFAState precedenceState = new DFAState(new ATNConfigSet()); precedenceState.edges = new DFAState[0]; precedenceState.isAcceptState = false; precedenceState.requiresFullContext = false; this.s0 = precedenceState; } } this.precedenceDfa = precedenceDfa; } /** * Gets whether this DFA is a precedence DFA. Precedence DFAs use a special * start state {@link #s0} which is not stored in {@link #states}. The * {@link DFAState#edges} array for this start state contains outgoing edges * supplying individual start states corresponding to specific precedence * values. * * @return {@code true} if this is a precedence DFA; otherwise, * {@code false}. * @see Parser#getPrecedence() */ public final boolean isPrecedenceDfa() { return precedenceDfa; } /** * Get the start state for a specific precedence value. * * @param precedence The current precedence. * @return The start state corresponding to the specified precedence, or * {@code null} if no start state exists for the specified precedence. * * @throws IllegalStateException if this is not a precedence DFA. * @see #isPrecedenceDfa() */ @SuppressWarnings("null") public final DFAState getPrecedenceStartState(int precedence) { if (!isPrecedenceDfa()) { throw new IllegalStateException("Only precedence DFAs may contain a precedence start state."); } // s0.edges is never null for a precedence DFA if (precedence < 0 || precedence >= s0.edges.length) { return null; } return s0.edges[precedence]; } /** * Set the start state for a specific precedence value. * * @param precedence The current precedence. * @param startState The start state corresponding to the specified * precedence. * * @throws IllegalStateException if this is not a precedence DFA. * @see #isPrecedenceDfa() */ @SuppressWarnings({"SynchronizeOnNonFinalField", "null"}) public final void setPrecedenceStartState(int precedence, DFAState startState) { if (!isPrecedenceDfa()) { throw new IllegalStateException("Only precedence DFAs may contain a precedence start state."); } if (precedence < 0) { return; } // synchronization on s0 here is ok. when the DFA is turned into a // precedence DFA, s0 will be initialized once and not updated again synchronized (s0) { // s0.edges is never null for a precedence DFA if (precedence >= s0.edges.length) { s0.edges = Arrays.copyOf(s0.edges, precedence + 1); } s0.edges[precedence] = startState; } } /** * Sets whether this is a precedence DFA. * * @param precedenceDfa {@code true} if this is a precedence DFA; otherwise, * {@code false} * * @throws UnsupportedOperationException if {@code precedenceDfa} does not * match the value of {@link #isPrecedenceDfa} for the current DFA. * * @deprecated This method no longer performs any action. */ @Deprecated public final void setPrecedenceDfa(boolean precedenceDfa) { if (precedenceDfa != isPrecedenceDfa()) { throw new UnsupportedOperationException("The precedenceDfa field cannot change after a DFA is constructed."); } } /** * Return a list of all states in this DFA, ordered by state number. */ public List<DFAState> getStates() { List<DFAState> result = new ArrayList<DFAState>(states.keySet()); Collections.sort(result, new Comparator<DFAState>() { @Override public int compare(DFAState o1, DFAState o2) { return o1.stateNumber - o2.stateNumber; } }); return result; } @Override public String toString() { return toString(VocabularyImpl.EMPTY_VOCABULARY); } /** * @deprecated Use {@link #toString(Vocabulary)} instead. */ @Deprecated public String toString(String[] tokenNames) { if ( s0==null ) return ""; DFASerializer serializer = new DFASerializer(this,tokenNames); return serializer.toString(); } public String toString(Vocabulary vocabulary) { if (s0 == null) { return ""; } DFASerializer serializer = new DFASerializer(this, vocabulary); return serializer.toString(); } public String toLexerString() { if ( s0==null ) return ""; DFASerializer serializer = new LexerDFASerializer(this); return serializer.toString(); } }
⏎ org/antlr/v4/runtime/dfa/DFA.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, 30991👍, 0💬
Popular Posts:
JDK 8 jconsole.jar is the JAR file for JDK 8 JConsole, which is a graphical monitoring tool to monit...
Apache Axis2 is the core engine for Web services. It is a complete re-design and re-write of the wid...
iText is an ideal library for developers looking to enhance web- and other applications with dynamic...
What Is activation.jar? I heard it's related to JAF (JavaBeans Activation Framework) 1.1? The if you...
How to show the XML parsing flow with sax\DocumentTracer.java provided in the Apache Xerces package?...