no more resolved bit in config. use ATNConfigSet all over. final clean up of ATN sim.
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9741]
This commit is contained in:
parent
79d1c40427
commit
6daa66f83f
|
@ -67,7 +67,7 @@ public class ATNConfig {
|
||||||
//public boolean traversedPredicate; // TODO: don't need
|
//public boolean traversedPredicate; // TODO: don't need
|
||||||
|
|
||||||
/** Ignore this config when examining config sets */
|
/** Ignore this config when examining config sets */
|
||||||
public boolean resolved;
|
// public boolean resolved;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We cannot execute predicates dependent upon local context unless
|
* We cannot execute predicates dependent upon local context unless
|
||||||
|
|
|
@ -32,7 +32,6 @@ package org.antlr.v4.runtime.atn;
|
||||||
import org.antlr.v4.runtime.dfa.DFAState;
|
import org.antlr.v4.runtime.dfa.DFAState;
|
||||||
import org.antlr.v4.runtime.misc.IntervalSet;
|
import org.antlr.v4.runtime.misc.IntervalSet;
|
||||||
import org.antlr.v4.runtime.misc.NotNull;
|
import org.antlr.v4.runtime.misc.NotNull;
|
||||||
import org.antlr.v4.runtime.misc.OrderedHashSet;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -45,7 +44,7 @@ public abstract class ATNSimulator {
|
||||||
public final ATN atn;
|
public final ATN atn;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ERROR = new DFAState(new OrderedHashSet<ATNConfig>());
|
ERROR = new DFAState(new ATNConfigSet());
|
||||||
ERROR.stateNumber = Integer.MAX_VALUE;
|
ERROR.stateNumber = Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.antlr.v4.runtime.dfa.DFA;
|
||||||
import org.antlr.v4.runtime.dfa.DFAState;
|
import org.antlr.v4.runtime.dfa.DFAState;
|
||||||
import org.antlr.v4.runtime.misc.NotNull;
|
import org.antlr.v4.runtime.misc.NotNull;
|
||||||
import org.antlr.v4.runtime.misc.Nullable;
|
import org.antlr.v4.runtime.misc.Nullable;
|
||||||
import org.antlr.v4.runtime.misc.OrderedHashSet;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
@ -184,7 +183,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
System.out.format("mode %d start: %s\n", mode, startState);
|
System.out.format("mode %d start: %s\n", mode, startState);
|
||||||
}
|
}
|
||||||
|
|
||||||
OrderedHashSet<ATNConfig> s0_closure = computeStartState(input, startState);
|
ATNConfigSet s0_closure = computeStartState(input, startState);
|
||||||
int old_mode = mode;
|
int old_mode = mode;
|
||||||
dfa[mode].s0 = addDFAState(s0_closure);
|
dfa[mode].s0 = addDFAState(s0_closure);
|
||||||
int predict = exec(input, s0_closure);
|
int predict = exec(input, s0_closure);
|
||||||
|
@ -257,7 +256,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
return Token.EOF;
|
return Token.EOF;
|
||||||
}
|
}
|
||||||
if ( atnException!=null ) throw atnException;
|
if ( atnException!=null ) throw atnException;
|
||||||
throw new LexerNoViableAltException(recog, input, startIndex, s.configs);
|
throw new LexerNoViableAltException(recog, input, startIndex, s.configset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ruleIndex = dfaPrevAccept.state.ruleIndex;
|
int ruleIndex = dfaPrevAccept.state.ruleIndex;
|
||||||
|
@ -266,17 +265,17 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
return dfaPrevAccept.state.prediction;
|
return dfaPrevAccept.state.prediction;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int exec(@NotNull CharStream input, @NotNull OrderedHashSet<ATNConfig> s0) {
|
protected int exec(@NotNull CharStream input, @NotNull ATNConfigSet s0) {
|
||||||
//System.out.println("enter exec index "+input.index()+" from "+s0);
|
//System.out.println("enter exec index "+input.index()+" from "+s0);
|
||||||
@NotNull
|
@NotNull
|
||||||
OrderedHashSet<ATNConfig> closure = new OrderedHashSet<ATNConfig>();
|
ATNConfigSet closure = new ATNConfigSet();
|
||||||
closure.addAll(s0);
|
closure.addAll(s0);
|
||||||
if ( debug ) {
|
if ( debug ) {
|
||||||
System.out.format("start state closure=%s\n", closure);
|
System.out.format("start state closure=%s\n", closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
OrderedHashSet<ATNConfig> reach = new OrderedHashSet<ATNConfig>();
|
ATNConfigSet reach = new ATNConfigSet();
|
||||||
atnPrevAccept.reset();
|
atnPrevAccept.reset();
|
||||||
|
|
||||||
traceLookahead1();
|
traceLookahead1();
|
||||||
|
@ -327,7 +326,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
// swap to avoid reallocating space
|
// swap to avoid reallocating space
|
||||||
// TODO: faster to reallocate?
|
// TODO: faster to reallocate?
|
||||||
@NotNull
|
@NotNull
|
||||||
OrderedHashSet<ATNConfig> tmp = reach;
|
ATNConfigSet tmp = reach;
|
||||||
reach = closure;
|
reach = closure;
|
||||||
closure = tmp;
|
closure = tmp;
|
||||||
reach.clear();
|
reach.clear();
|
||||||
|
@ -347,7 +346,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
return atn.ruleToTokenType[ruleIndex];
|
return atn.ruleToTokenType[ruleIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processAcceptStates(@NotNull CharStream input, @NotNull OrderedHashSet<ATNConfig> reach) {
|
protected void processAcceptStates(@NotNull CharStream input, @NotNull ATNConfigSet reach) {
|
||||||
for (int ci=0; ci<reach.size(); ci++) {
|
for (int ci=0; ci<reach.size(); ci++) {
|
||||||
ATNConfig c = reach.get(ci);
|
ATNConfig c = reach.get(ci);
|
||||||
if ( c.state instanceof RuleStopState) {
|
if ( c.state instanceof RuleStopState) {
|
||||||
|
@ -435,7 +434,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteWildcardConfigsForAlt(@NotNull OrderedHashSet<ATNConfig> closure, int ci, int alt) {
|
public void deleteWildcardConfigsForAlt(@NotNull ATNConfigSet closure, int ci, int alt) {
|
||||||
int j=ci+1;
|
int j=ci+1;
|
||||||
while ( j<closure.size() ) {
|
while ( j<closure.size() ) {
|
||||||
ATNConfig c = closure.get(j);
|
ATNConfig c = closure.get(j);
|
||||||
|
@ -453,11 +452,11 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected OrderedHashSet<ATNConfig> computeStartState(@NotNull IntStream input,
|
protected ATNConfigSet computeStartState(@NotNull IntStream input,
|
||||||
@NotNull ATNState p)
|
@NotNull ATNState p)
|
||||||
{
|
{
|
||||||
RuleContext initialContext = EMPTY_LEXER_RULE_CONTEXT;
|
RuleContext initialContext = EMPTY_LEXER_RULE_CONTEXT;
|
||||||
OrderedHashSet<ATNConfig> configs = new OrderedHashSet<ATNConfig>();
|
ATNConfigSet configs = new ATNConfigSet();
|
||||||
for (int i=0; i<p.getNumberOfTransitions(); i++) {
|
for (int i=0; i<p.getNumberOfTransitions(); i++) {
|
||||||
ATNState target = p.transition(i).target;
|
ATNState target = p.transition(i).target;
|
||||||
ATNConfig c = new ATNConfig(target, i+1, initialContext);
|
ATNConfig c = new ATNConfig(target, i+1, initialContext);
|
||||||
|
@ -466,7 +465,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
return configs;
|
return configs;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void closure(@NotNull ATNConfig config, @NotNull OrderedHashSet<ATNConfig> configs) {
|
protected void closure(@NotNull ATNConfig config, @NotNull ATNConfigSet configs) {
|
||||||
if ( debug ) {
|
if ( debug ) {
|
||||||
System.out.println("closure("+config.toString(recog, true)+")");
|
System.out.println("closure("+config.toString(recog, true)+")");
|
||||||
}
|
}
|
||||||
|
@ -545,10 +544,10 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
if ( dfa_debug ) {
|
if ( dfa_debug ) {
|
||||||
System.out.format("no edge for %s\n", getTokenName(input.LA(1)));
|
System.out.format("no edge for %s\n", getTokenName(input.LA(1)));
|
||||||
System.out.format("ATN exec upon %s at DFA state %d = %s\n",
|
System.out.format("ATN exec upon %s at DFA state %d = %s\n",
|
||||||
input.substring(startIndex, input.index()), s.stateNumber, s.configs);
|
input.substring(startIndex, input.index()), s.stateNumber, s.configset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ttype = exec(input, s.configs);
|
int ttype = exec(input, s.configset);
|
||||||
|
|
||||||
if ( dfa_debug ) {
|
if ( dfa_debug ) {
|
||||||
System.out.format("back from DFA update, ttype=%d, dfa[mode %d]=\n%s\n",
|
System.out.format("back from DFA update, ttype=%d, dfa[mode %d]=\n%s\n",
|
||||||
|
@ -567,9 +566,9 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
state.charPos = charPositionInLine;
|
state.charPos = charPositionInLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addDFAEdge(@NotNull OrderedHashSet<ATNConfig> p,
|
protected void addDFAEdge(@NotNull ATNConfigSet p,
|
||||||
int t,
|
int t,
|
||||||
@NotNull OrderedHashSet<ATNConfig> q)
|
@NotNull ATNConfigSet q)
|
||||||
{
|
{
|
||||||
// even if we can add the states, we can't add an edge for labels out of range
|
// even if we can add the states, we can't add an edge for labels out of range
|
||||||
if (t < 0 || t > NUM_EDGES) {
|
if (t < 0 || t > NUM_EDGES) {
|
||||||
|
@ -626,7 +625,7 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
test them, we cannot cash the DFA state target of ID.
|
test them, we cannot cash the DFA state target of ID.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
protected DFAState addDFAState(@NotNull OrderedHashSet<ATNConfig> configs) {
|
protected DFAState addDFAState(@NotNull ATNConfigSet configs) {
|
||||||
DFAState proposed = new DFAState(configs);
|
DFAState proposed = new DFAState(configs);
|
||||||
DFAState existing = dfa[mode].states.get(proposed);
|
DFAState existing = dfa[mode].states.get(proposed);
|
||||||
if ( existing!=null ) return existing;
|
if ( existing!=null ) return existing;
|
||||||
|
@ -653,8 +652,8 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
if ( traversedPredicate ) return null; // cannot cache
|
if ( traversedPredicate ) return null; // cannot cache
|
||||||
|
|
||||||
newState.stateNumber = dfa[mode].states.size();
|
newState.stateNumber = dfa[mode].states.size();
|
||||||
newState.configs = new OrderedHashSet<ATNConfig>();
|
newState.configset = new ATNConfigSet();
|
||||||
newState.configs.addAll(configs);
|
newState.configset.addAll(configs);
|
||||||
dfa[mode].states.put(newState, newState);
|
dfa[mode].states.put(newState, newState);
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -568,7 +568,7 @@ public class v2ParserATNSimulator<Symbol> extends ATNSimulator {
|
||||||
int nalts = decState.getNumberOfTransitions();
|
int nalts = decState.getNumberOfTransitions();
|
||||||
List<DFAState.PredPrediction> predPredictions =
|
List<DFAState.PredPrediction> predPredictions =
|
||||||
predicateDFAState(D, D.configset, outerContext, nalts);
|
predicateDFAState(D, D.configset, outerContext, nalts);
|
||||||
if ( tooFewPredicates(D, outerContext, nalts) ) {
|
if ( D.predicates.size() < nalts ) {
|
||||||
IntervalSet conflictingAlts = getConflictingAltsFromConfigSet(D.configset);
|
IntervalSet conflictingAlts = getConflictingAltsFromConfigSet(D.configset);
|
||||||
reportInsufficientPredicates(dfa, startIndex, input.index(),
|
reportInsufficientPredicates(dfa, startIndex, input.index(),
|
||||||
conflictingAlts,
|
conflictingAlts,
|
||||||
|
@ -1135,26 +1135,6 @@ public class v2ParserATNSimulator<Symbol> extends ATNSimulator {
|
||||||
return ambigAlts;
|
return ambigAlts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean tooFewPredicates(DFAState D, RuleContext outerContext, int nalts) {
|
|
||||||
List<DFAState.PredPrediction> pairs;
|
|
||||||
if ( D.isCtxSensitive ) {
|
|
||||||
pairs = D.ctxToPredicates.get(outerContext); // TODO: rm
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pairs = D.predicates;
|
|
||||||
}
|
|
||||||
return pairs==null || pairs.size() < nalts;
|
|
||||||
|
|
||||||
// IntervalSet conflictingAlts = getConflictingAltsFromConfigSet(configs);
|
|
||||||
// SemanticContext[] altToPred = getPredsForAmbigAlts(conflictingAlts, configs, nalts);
|
|
||||||
// // We need at least n-1 predicates for n ambiguous alts
|
|
||||||
// int unpredicated = 0;
|
|
||||||
// for (int i = 1; i < altToPred.length; i++) {
|
|
||||||
// if ( altToPred[i]==SemanticContext.NONE ) unpredicated++;
|
|
||||||
// }
|
|
||||||
// return unpredicated > 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IntervalSet getConflictingAltsFromConfigSet(ATNConfigSet configs) {
|
protected IntervalSet getConflictingAltsFromConfigSet(ATNConfigSet configs) {
|
||||||
IntervalSet conflictingAlts;
|
IntervalSet conflictingAlts;
|
||||||
if ( configs.uniqueAlt!= ATN.INVALID_ALT_NUMBER ) {
|
if ( configs.uniqueAlt!= ATN.INVALID_ALT_NUMBER ) {
|
||||||
|
@ -1168,7 +1148,7 @@ public class v2ParserATNSimulator<Symbol> extends ATNSimulator {
|
||||||
|
|
||||||
protected int resolveToMinAlt(@NotNull DFAState D, IntervalSet conflictingAlts) {
|
protected int resolveToMinAlt(@NotNull DFAState D, IntervalSet conflictingAlts) {
|
||||||
// kill dead alts so we don't chase them ever
|
// kill dead alts so we don't chase them ever
|
||||||
killAlts(conflictingAlts, D.configset);
|
// killAlts(conflictingAlts, D.configset);
|
||||||
D.prediction = conflictingAlts.getMinElement();
|
D.prediction = conflictingAlts.getMinElement();
|
||||||
if ( debug ) System.out.println("RESOLVED TO "+D.prediction+" for "+D);
|
if ( debug ) System.out.println("RESOLVED TO "+D.prediction+" for "+D);
|
||||||
return D.prediction;
|
return D.prediction;
|
||||||
|
@ -1182,17 +1162,11 @@ public class v2ParserATNSimulator<Symbol> extends ATNSimulator {
|
||||||
int exitAlt = 2;
|
int exitAlt = 2;
|
||||||
conflictingAlts.remove(exitAlt);
|
conflictingAlts.remove(exitAlt);
|
||||||
// kill dead alts so we don't chase them ever
|
// kill dead alts so we don't chase them ever
|
||||||
killAlts(conflictingAlts, reach);
|
// killAlts(conflictingAlts, reach);
|
||||||
if ( debug ) System.out.println("RESOLVED TO "+reach);
|
if ( debug ) System.out.println("RESOLVED TO "+reach);
|
||||||
return exitAlt;
|
return exitAlt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void killAlts(@NotNull IntervalSet alts, @NotNull ATNConfigSet configs) {
|
|
||||||
for (ATNConfig c : configs) {
|
|
||||||
if ( alts.contains(c.alt) ) c.resolved = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getTokenName(int t) {
|
public String getTokenName(int t) {
|
||||||
if ( t==-1 ) return "EOF";
|
if ( t==-1 ) return "EOF";
|
||||||
|
|
|
@ -29,16 +29,13 @@
|
||||||
|
|
||||||
package org.antlr.v4.runtime.dfa;
|
package org.antlr.v4.runtime.dfa;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.RuleContext;
|
|
||||||
import org.antlr.v4.runtime.atn.ATNConfig;
|
import org.antlr.v4.runtime.atn.ATNConfig;
|
||||||
import org.antlr.v4.runtime.atn.ATNConfigSet;
|
import org.antlr.v4.runtime.atn.ATNConfigSet;
|
||||||
import org.antlr.v4.runtime.atn.SemanticContext;
|
import org.antlr.v4.runtime.atn.SemanticContext;
|
||||||
import org.antlr.v4.runtime.misc.Nullable;
|
import org.antlr.v4.runtime.misc.Nullable;
|
||||||
import org.antlr.v4.runtime.misc.OrderedHashSet;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/** A DFA state represents a set of possible ATN configurations.
|
/** A DFA state represents a set of possible ATN configurations.
|
||||||
|
@ -69,8 +66,8 @@ public class DFAState {
|
||||||
public int stateNumber = -1;
|
public int stateNumber = -1;
|
||||||
|
|
||||||
/** The set of ATN configurations (state,alt,context) for this DFA state */
|
/** The set of ATN configurations (state,alt,context) for this DFA state */
|
||||||
@Nullable
|
// @Nullable
|
||||||
public OrderedHashSet<ATNConfig> configs = new OrderedHashSet<ATNConfig>();
|
// public OrderedHashSet<ATNConfig> configs = new OrderedHashSet<ATNConfig>();
|
||||||
|
|
||||||
// TODO: rename to configs after flipping to new ATN sim
|
// TODO: rename to configs after flipping to new ATN sim
|
||||||
public ATNConfigSet configset = new ATNConfigSet();
|
public ATNConfigSet configset = new ATNConfigSet();
|
||||||
|
@ -89,12 +86,6 @@ public class DFAState {
|
||||||
public boolean complete; // all alts predict "prediction"
|
public boolean complete; // all alts predict "prediction"
|
||||||
public boolean isCtxSensitive;
|
public boolean isCtxSensitive;
|
||||||
|
|
||||||
// TODO: refactor to subclass?
|
|
||||||
@Nullable
|
|
||||||
public Map<RuleContext, Integer> ctxToPrediction; // used for ctx sensitive parsing
|
|
||||||
|
|
||||||
public Map<RuleContext, List<PredPrediction>> ctxToPredicates; // used for ctx sensitive parsing
|
|
||||||
|
|
||||||
/** DFA accept states use predicates in two situations:
|
/** DFA accept states use predicates in two situations:
|
||||||
* disambiguating and validating predicates. If an accept state
|
* disambiguating and validating predicates. If an accept state
|
||||||
* predicts more than one alternative, It's ambiguous and we
|
* predicts more than one alternative, It's ambiguous and we
|
||||||
|
@ -147,7 +138,7 @@ public class DFAState {
|
||||||
|
|
||||||
public DFAState(int stateNumber) { this.stateNumber = stateNumber; }
|
public DFAState(int stateNumber) { this.stateNumber = stateNumber; }
|
||||||
|
|
||||||
public DFAState(OrderedHashSet<ATNConfig> configs) { this.configs = configs; }
|
public DFAState(ATNConfigSet configs) { this.configset = configs; }
|
||||||
|
|
||||||
/** Get the set of all alts mentioned by all ATN configurations in this
|
/** Get the set of all alts mentioned by all ATN configurations in this
|
||||||
* DFA state.
|
* DFA state.
|
||||||
|
@ -155,7 +146,7 @@ public class DFAState {
|
||||||
public Set<Integer> getAltSet() {
|
public Set<Integer> getAltSet() {
|
||||||
// TODO (sam): what to do when configs==null?
|
// TODO (sam): what to do when configs==null?
|
||||||
Set<Integer> alts = new HashSet<Integer>();
|
Set<Integer> alts = new HashSet<Integer>();
|
||||||
for (ATNConfig c : configs) {
|
for (ATNConfig c : configset) {
|
||||||
alts.add(c.alt);
|
alts.add(c.alt);
|
||||||
}
|
}
|
||||||
if ( alts.size()==0 ) return null;
|
if ( alts.size()==0 ) return null;
|
||||||
|
@ -177,7 +168,7 @@ public class DFAState {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
// TODO (sam): what to do when configs==null?
|
// TODO (sam): what to do when configs==null?
|
||||||
int h = 0;
|
int h = 0;
|
||||||
for (ATNConfig c : configs) {
|
for (ATNConfig c : configset) {
|
||||||
h += c.alt;
|
h += c.alt;
|
||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
|
@ -200,7 +191,7 @@ public class DFAState {
|
||||||
if ( this==o ) return true;
|
if ( this==o ) return true;
|
||||||
DFAState other = (DFAState)o;
|
DFAState other = (DFAState)o;
|
||||||
// TODO (sam): what to do when configs==null?
|
// TODO (sam): what to do when configs==null?
|
||||||
boolean sameSet = this.configs.equals(other.configs);
|
boolean sameSet = this.configset.equals(other.configset);
|
||||||
// System.out.println("DFAState.equals: "+configs+(sameSet?"==":"!=")+other.configs);
|
// System.out.println("DFAState.equals: "+configs+(sameSet?"==":"!=")+other.configs);
|
||||||
return sameSet;
|
return sameSet;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import org.antlr.runtime.debug.BlankDebugEventListener;
|
import org.antlr.runtime.debug.BlankDebugEventListener;
|
||||||
import org.antlr.v4.runtime.*;
|
import org.antlr.v4.runtime.ANTLRFileStream;
|
||||||
import org.antlr.v4.runtime.atn.*;
|
import org.antlr.v4.runtime.CommonTokenStream;
|
||||||
|
import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
||||||
|
import org.antlr.v4.runtime.atn.v2ParserATNSimulator;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
@ -32,8 +34,8 @@ class TestYang {
|
||||||
System.out.println("finished parsing OK");
|
System.out.println("finished parsing OK");
|
||||||
System.out.println(LexerATNSimulator.ATN_failover+" lexer failovers");
|
System.out.println(LexerATNSimulator.ATN_failover+" lexer failovers");
|
||||||
System.out.println(LexerATNSimulator.match_calls+" lexer match calls");
|
System.out.println(LexerATNSimulator.match_calls+" lexer match calls");
|
||||||
System.out.println(ParserATNSimulator.ATN_failover+" parser failovers");
|
System.out.println(v2ParserATNSimulator.ATN_failover+" parser failovers");
|
||||||
System.out.println(ParserATNSimulator.predict_calls +" parser predict calls");
|
System.out.println(v2ParserATNSimulator.predict_calls +" parser predict calls");
|
||||||
if ( profile ) {
|
if ( profile ) {
|
||||||
System.out.println("num decisions "+profiler.numDecisions);
|
System.out.println("num decisions "+profiler.numDecisions);
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ public class DOTGenerator {
|
||||||
List<Integer> altList = new ArrayList<Integer>();
|
List<Integer> altList = new ArrayList<Integer>();
|
||||||
altList.addAll(alts);
|
altList.addAll(alts);
|
||||||
Collections.sort(altList);
|
Collections.sort(altList);
|
||||||
Set<ATNConfig> configurations = s.configs;
|
Set<ATNConfig> configurations = s.configset;
|
||||||
for (int altIndex = 0; altIndex < altList.size(); altIndex++) {
|
for (int altIndex = 0; altIndex < altList.size(); altIndex++) {
|
||||||
int alt = altList.get(altIndex);
|
int alt = altList.get(altIndex);
|
||||||
if ( altIndex>0 ) {
|
if ( altIndex>0 ) {
|
||||||
|
|
|
@ -32,7 +32,6 @@ package org.antlr.v4.tool.interp;
|
||||||
import org.antlr.v4.Tool;
|
import org.antlr.v4.Tool;
|
||||||
import org.antlr.v4.runtime.*;
|
import org.antlr.v4.runtime.*;
|
||||||
import org.antlr.v4.runtime.atn.ATNState;
|
import org.antlr.v4.runtime.atn.ATNState;
|
||||||
import org.antlr.v4.runtime.atn.ParserATNSimulator;
|
|
||||||
import org.antlr.v4.runtime.atn.v2ParserATNSimulator;
|
import org.antlr.v4.runtime.atn.v2ParserATNSimulator;
|
||||||
import org.antlr.v4.runtime.dfa.DFA;
|
import org.antlr.v4.runtime.dfa.DFA;
|
||||||
import org.antlr.v4.runtime.misc.NotNull;
|
import org.antlr.v4.runtime.misc.NotNull;
|
||||||
|
@ -88,7 +87,8 @@ public class ParserInterpreter {
|
||||||
public int matchATN(@NotNull TokenStream input,
|
public int matchATN(@NotNull TokenStream input,
|
||||||
@NotNull ATNState startState)
|
@NotNull ATNState startState)
|
||||||
{
|
{
|
||||||
return new ParserATNSimulator<Token>(new DummyParser(g, input), g.atn).matchATN(input, startState);
|
// return new v2ParserATNSimulator<Token>(new DummyParser(g, input), g.atn).matchATN(input, startState);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public v2ParserATNSimulator<Token> getATNSimulator() {
|
public v2ParserATNSimulator<Token> getATNSimulator() {
|
||||||
|
|
|
@ -2,8 +2,10 @@ package org.antlr.v4.test;
|
||||||
|
|
||||||
import org.antlr.v4.automata.ATNSerializer;
|
import org.antlr.v4.automata.ATNSerializer;
|
||||||
import org.antlr.v4.misc.Utils;
|
import org.antlr.v4.misc.Utils;
|
||||||
import org.antlr.v4.runtime.atn.*;
|
import org.antlr.v4.runtime.atn.ATN;
|
||||||
import org.antlr.v4.tool.*;
|
import org.antlr.v4.runtime.atn.v2ParserATNSimulator;
|
||||||
|
import org.antlr.v4.tool.Grammar;
|
||||||
|
import org.antlr.v4.tool.LexerGrammar;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TestATNDeserialization extends BaseTest {
|
public class TestATNDeserialization extends BaseTest {
|
||||||
|
@ -145,7 +147,7 @@ public class TestATNDeserialization extends BaseTest {
|
||||||
ATN atn = createATN(g);
|
ATN atn = createATN(g);
|
||||||
char[] data = Utils.toCharArray(ATNSerializer.getSerialized(g, atn));
|
char[] data = Utils.toCharArray(ATNSerializer.getSerialized(g, atn));
|
||||||
String atnData = ATNSerializer.getDecoded(g, atn);
|
String atnData = ATNSerializer.getDecoded(g, atn);
|
||||||
ATN atn2 = ParserATNSimulator.deserialize(data);
|
ATN atn2 = v2ParserATNSimulator.deserialize(data);
|
||||||
String atn2Data = ATNSerializer.getDecoded(g, atn2);
|
String atn2Data = ATNSerializer.getDecoded(g, atn2);
|
||||||
|
|
||||||
assertEquals(atnData, atn2Data);
|
assertEquals(atnData, atn2Data);
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.antlr.v4.runtime.TokenStream;
|
||||||
import org.antlr.v4.runtime.atn.ATN;
|
import org.antlr.v4.runtime.atn.ATN;
|
||||||
import org.antlr.v4.runtime.atn.ATNState;
|
import org.antlr.v4.runtime.atn.ATNState;
|
||||||
import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
import org.antlr.v4.runtime.atn.LexerATNSimulator;
|
||||||
import org.antlr.v4.runtime.atn.ParserATNSimulator;
|
import org.antlr.v4.runtime.atn.v2ParserATNSimulator;
|
||||||
import org.antlr.v4.runtime.dfa.DFA;
|
import org.antlr.v4.runtime.dfa.DFA;
|
||||||
import org.antlr.v4.tool.DOTGenerator;
|
import org.antlr.v4.tool.DOTGenerator;
|
||||||
import org.antlr.v4.tool.Grammar;
|
import org.antlr.v4.tool.Grammar;
|
||||||
|
@ -544,7 +544,7 @@ public class TestATNParserPrediction extends BaseTest {
|
||||||
// System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("b"))));
|
// System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("b"))));
|
||||||
// System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("e"))));
|
// System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("e"))));
|
||||||
|
|
||||||
ParserATNSimulator interp = new ParserATNSimulator(atn);
|
v2ParserATNSimulator interp = new v2ParserATNSimulator(atn);
|
||||||
List<Integer> types = getTokenTypesViaATN(inputString, lexInterp);
|
List<Integer> types = getTokenTypesViaATN(inputString, lexInterp);
|
||||||
System.out.println(types);
|
System.out.println(types);
|
||||||
TokenStream input = new IntTokenStream(types);
|
TokenStream input = new IntTokenStream(types);
|
||||||
|
@ -553,7 +553,7 @@ public class TestATNParserPrediction extends BaseTest {
|
||||||
DFA dfa = new DFA(startState);
|
DFA dfa = new DFA(startState);
|
||||||
// Rule r = g.getRule(ruleName);
|
// Rule r = g.getRule(ruleName);
|
||||||
//ATNState startState = atn.ruleToStartState.get(r);
|
//ATNState startState = atn.ruleToStartState.get(r);
|
||||||
interp.predictATN(dfa, input, ctx, false);
|
interp.predictATN(dfa, input, ctx);
|
||||||
}
|
}
|
||||||
catch (NoViableAltException nvae) {
|
catch (NoViableAltException nvae) {
|
||||||
nvae.printStackTrace(System.err);
|
nvae.printStackTrace(System.err);
|
||||||
|
|
|
@ -7,7 +7,6 @@ import org.antlr.v4.runtime.tree.ParseTreeListener;
|
||||||
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
import org.antlr.v4.runtime.tree.ParseTreeWalker;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.antlr.v4.runtime.atn.ParserATNSimulator;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
|
Loading…
Reference in New Issue