no tool depends now in ATN, moved some maps to arrays :)
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 8779]
This commit is contained in:
parent
4d04b21999
commit
9bc02bfd33
|
@ -27,9 +27,8 @@
|
|||
*/
|
||||
package org.antlr.v4.runtime;
|
||||
|
||||
import org.antlr.v4.misc.OrderedHashSet;
|
||||
import org.antlr.v4.runtime.atn.*;
|
||||
import org.antlr.v4.runtime.misc.IntervalSet;
|
||||
import org.antlr.v4.runtime.misc.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.antlr.v4.runtime;
|
||||
|
||||
import org.antlr.v4.misc.OrderedHashSet;
|
||||
import org.antlr.v4.runtime.atn.ATNConfig;
|
||||
import org.antlr.v4.runtime.misc.OrderedHashSet;
|
||||
|
||||
public class LexerNoViableAltException extends LexerRecognitionExeption {
|
||||
/** Prediction began at what input index? */
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
*/
|
||||
package org.antlr.v4.runtime;
|
||||
|
||||
import org.antlr.v4.misc.OrderedHashSet;
|
||||
import org.antlr.v4.runtime.atn.ATNConfig;
|
||||
import org.antlr.v4.runtime.misc.OrderedHashSet;
|
||||
|
||||
public class NoViableAltException extends RecognitionException {
|
||||
/** Prediction began at what input index? */
|
||||
|
|
|
@ -6,39 +6,38 @@ import org.antlr.v4.runtime.misc.IntervalSet;
|
|||
import java.util.*;
|
||||
|
||||
/** */
|
||||
// TODO: split into runtime / analysis time?
|
||||
public class ATN {
|
||||
public static final int INVALID_ALT_NUMBER = -1;
|
||||
public static final int INVALID_DECISION_NUMBER = -1;
|
||||
public static final int INVALID_ALT_NUMBER = 0;
|
||||
// public static final int INVALID_DECISION_NUMBER = -1;
|
||||
|
||||
public static final int PARSER = 1;
|
||||
public static final int LEXER = 2;
|
||||
public static final int TREE_PARSER = 3;
|
||||
|
||||
public List<ATNState> states = new ArrayList<ATNState>();
|
||||
public List<ATNState> rules = new ArrayList<ATNState>(); // rule index to start state
|
||||
|
||||
/** Each subrule/rule is a decision point and we must track them so we
|
||||
* can go back later and build DFA predictors for them. This includes
|
||||
* all the rules, subrules, optional blocks, ()+, ()* etc...
|
||||
*/
|
||||
public List<DecisionState> decisionToATNState = new ArrayList<DecisionState>();
|
||||
public List<DecisionState> decisionToState = new ArrayList<DecisionState>();
|
||||
|
||||
public Map<Integer, RuleStartState> ruleToStartState = new LinkedHashMap<Integer, RuleStartState>();
|
||||
public Map<Integer, RuleStopState> ruleToStopState = new LinkedHashMap<Integer, RuleStopState>();
|
||||
|
||||
// public RuleStartState[] ruleToStartState = new LinkedHashMap<Integer, RuleStartState>();
|
||||
// public RuleStopState[] ruleToStopState = new LinkedHashMap<Integer, RuleStopState>();
|
||||
public RuleStartState[] ruleToStartState;
|
||||
public RuleStopState[] ruleToStopState;
|
||||
|
||||
public Map<String, TokensStartState> modeNameToStartState =
|
||||
new LinkedHashMap<String, TokensStartState>();
|
||||
|
||||
// runtime
|
||||
public int grammarType; // ANTLRParser.LEXER, ...
|
||||
public List<TokensStartState> modeToStartState = new ArrayList<TokensStartState>();
|
||||
|
||||
// runtime for lexer
|
||||
public List<Integer> ruleToTokenType = new ArrayList<Integer>();
|
||||
public List<Integer> ruleToActionIndex = new ArrayList<Integer>();
|
||||
|
||||
// runtime for parsers, lexers
|
||||
public int grammarType; // ATN.LEXER, ...
|
||||
public int maxTokenType;
|
||||
|
||||
// runtime for lexer only
|
||||
public int[] ruleToTokenType;
|
||||
public int[] ruleToActionIndex;
|
||||
public List<TokensStartState> modeToStartState = new ArrayList<TokensStartState>();
|
||||
|
||||
/** used during construction from grammar AST */
|
||||
int stateNumber = 0;
|
||||
|
||||
/** Used for runtime deserialization of ATNs from strings */
|
||||
|
@ -63,12 +62,12 @@ public class ATN {
|
|||
}
|
||||
|
||||
public int defineDecisionState(DecisionState s) {
|
||||
decisionToATNState.add(s);
|
||||
s.decision = decisionToATNState.size()-1;
|
||||
decisionToState.add(s);
|
||||
s.decision = decisionToState.size()-1;
|
||||
return s.decision;
|
||||
}
|
||||
|
||||
public int getNumberOfDecisions() {
|
||||
return decisionToATNState.size();
|
||||
return decisionToState.size();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package org.antlr.v4.runtime.atn;
|
||||
|
||||
import org.antlr.v4.misc.OrderedHashSet;
|
||||
import org.antlr.v4.parse.ANTLRParser;
|
||||
import org.antlr.v4.runtime.dfa.DFAState;
|
||||
import org.antlr.v4.runtime.misc.IntervalSet;
|
||||
import org.antlr.v4.runtime.misc.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -39,15 +37,20 @@ public abstract class ATNInterpreter {
|
|||
atn.addState(s);
|
||||
}
|
||||
int nrules = toInt(data[p++]);
|
||||
for (int i=1; i<=nrules; i++) {
|
||||
if ( atn.grammarType == ATN.LEXER ) {
|
||||
atn.ruleToTokenType = new int[nrules];
|
||||
atn.ruleToActionIndex = new int[nrules];
|
||||
}
|
||||
atn.ruleToStartState = new RuleStartState[nrules];
|
||||
for (int i=0; i<nrules; i++) {
|
||||
int s = toInt(data[p++]);
|
||||
ATNState startState = atn.states.get(s);
|
||||
atn.rules.add(startState);
|
||||
if ( atn.grammarType==ANTLRParser.LEXER ) {
|
||||
RuleStartState startState = (RuleStartState)atn.states.get(s);
|
||||
atn.ruleToStartState[i] = startState;
|
||||
if ( atn.grammarType == ATN.LEXER ) {
|
||||
int tokenType = toInt(data[p++]);
|
||||
atn.ruleToTokenType.add(tokenType);
|
||||
atn.ruleToTokenType[i] = tokenType;
|
||||
int actionIndex = toInt(data[p++]);
|
||||
atn.ruleToActionIndex.add(actionIndex);
|
||||
atn.ruleToActionIndex[i] = actionIndex;
|
||||
}
|
||||
else {
|
||||
p += 2;
|
||||
|
@ -85,7 +88,7 @@ public abstract class ATNInterpreter {
|
|||
for (int i=1; i<=ndecisions; i++) {
|
||||
int s = toInt(data[p++]);
|
||||
DecisionState decState = (DecisionState)atn.states.get(s);
|
||||
atn.decisionToATNState.add((DecisionState) decState);
|
||||
atn.decisionToState.add((DecisionState) decState);
|
||||
decState.decision = i-1;
|
||||
}
|
||||
// System.out.println(atn.getDecoded());
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package org.antlr.v4.runtime.atn;
|
||||
|
||||
import org.antlr.v4.misc.OrderedHashSet;
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.dfa.*;
|
||||
import org.antlr.v4.runtime.misc.OrderedHashSet;
|
||||
|
||||
/** "dup" of ParserInterpreter */
|
||||
public class LexerInterpreter extends ATNInterpreter {
|
||||
|
@ -113,12 +113,13 @@ public class LexerInterpreter extends ATNInterpreter {
|
|||
return -1;
|
||||
}
|
||||
if ( recog!=null ) {
|
||||
int actionIndex = atn.ruleToActionIndex[prevAcceptState.ruleIndex];
|
||||
if ( dfa_debug ) {
|
||||
System.out.println("ACTION "+
|
||||
recog.getRuleNames()[prevAcceptState.ruleIndex]+
|
||||
":"+atn.ruleToActionIndex.get(prevAcceptState.ruleIndex));
|
||||
":"+ actionIndex);
|
||||
}
|
||||
recog.action(prevAcceptState.ruleIndex, atn.ruleToActionIndex.get(prevAcceptState.ruleIndex));
|
||||
if ( actionIndex>=0 ) recog.action(prevAcceptState.ruleIndex, actionIndex);
|
||||
}
|
||||
input.seek(prevAcceptMarker);
|
||||
return prevAcceptState.prediction;
|
||||
|
@ -201,13 +202,13 @@ public class LexerInterpreter extends ATNInterpreter {
|
|||
if ( debug ) System.out.println("ACCEPT " + prevAccept.toString(recog, true) + " index " + prevAcceptIndex);
|
||||
|
||||
int ruleIndex = prevAccept.state.ruleIndex;
|
||||
int ttype = atn.ruleToTokenType.get(ruleIndex);
|
||||
int ttype = atn.ruleToTokenType[ruleIndex];
|
||||
if ( debug ) {
|
||||
if ( recog!=null ) System.out.println("ACTION "+recog.getRuleNames()[ruleIndex]+":"+ruleIndex);
|
||||
else System.out.println("ACTION "+ruleIndex+":"+ruleIndex);
|
||||
}
|
||||
int actionIndex = atn.ruleToActionIndex.get(ruleIndex);
|
||||
if ( actionIndex>0 ) recog.action(ruleIndex, actionIndex);
|
||||
int actionIndex = atn.ruleToActionIndex[ruleIndex];
|
||||
if ( actionIndex>=0 ) recog.action(ruleIndex, actionIndex);
|
||||
return ttype;
|
||||
}
|
||||
|
||||
|
@ -386,7 +387,7 @@ public class LexerInterpreter extends ATNInterpreter {
|
|||
if ( firstConfigWithRuleStopState!=null ) {
|
||||
newState.isAcceptState = true;
|
||||
newState.ruleIndex = firstConfigWithRuleStopState.state.ruleIndex;
|
||||
newState.prediction = atn.ruleToTokenType.get(newState.ruleIndex);
|
||||
newState.prediction = atn.ruleToTokenType[newState.ruleIndex];
|
||||
}
|
||||
|
||||
if ( traversedPredicate ) return null; // cannot cache
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package org.antlr.v4.runtime.atn;
|
||||
|
||||
import org.antlr.v4.misc.*;
|
||||
import org.antlr.v4.misc.Utils;
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.dfa.*;
|
||||
import org.antlr.v4.runtime.misc.OrderedHashSet;
|
||||
import org.stringtemplate.v4.misc.MultiMap;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -43,7 +44,7 @@ public class ParserInterpreter extends ATNInterpreter {
|
|||
predict_calls++;
|
||||
DFA dfa = decisionToDFA[decision];
|
||||
if ( dfa==null || dfa.s0==null ) {
|
||||
ATNState startState = atn.decisionToATNState.get(decision);
|
||||
ATNState startState = atn.decisionToState.get(decision);
|
||||
decisionToDFA[decision] = dfa = new DFA(startState);
|
||||
dfa.decision = decision;
|
||||
return predictATN(dfa, input, decision, ctx, false);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package org.antlr.v4.runtime.dfa;
|
||||
|
||||
import org.antlr.v4.misc.OrderedHashSet;
|
||||
import org.antlr.v4.runtime.RuleContext;
|
||||
import org.antlr.v4.runtime.atn.ATNConfig;
|
||||
import org.antlr.v4.runtime.misc.OrderedHashSet;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.antlr.v4.misc;
|
||||
package org.antlr.v4.runtime.misc;
|
||||
|
||||
import java.util.*;
|
||||
|
|
@ -48,7 +48,7 @@ public class Test {
|
|||
ATN atn = f.createATN();
|
||||
|
||||
DOTGenerator dot = new DOTGenerator(g);
|
||||
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("d").index)));
|
||||
System.out.println(dot.getDOT(atn.ruleToStartState[g.getRule("d").index]));
|
||||
}
|
||||
|
||||
public static class IntTokenStream implements TokenStream {
|
||||
|
|
|
@ -410,7 +410,7 @@ public class Tool {
|
|||
for (Grammar ig : grammars) {
|
||||
for (Rule r : ig.rules.values()) {
|
||||
try {
|
||||
String dot = dotGenerator.getDOT(g.atn.ruleToStartState.get(r.index));
|
||||
String dot = dotGenerator.getDOT(g.atn.ruleToStartState[r.index]);
|
||||
if (dot != null) {
|
||||
writeDOTFile(g, r, dot);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class AnalysisPipeline {
|
|||
void processParserOrTreeParser() {
|
||||
g.decisionLOOK =
|
||||
new Vector<IntervalSet[]>(g.atn.getNumberOfDecisions()+1);
|
||||
for (DecisionState s : g.atn.decisionToATNState) {
|
||||
for (DecisionState s : g.atn.decisionToState) {
|
||||
System.out.println("\nDECISION "+s.decision+" in rule "+s.rule.name);
|
||||
|
||||
LL1Analyzer anal = new LL1Analyzer(g.atn);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.antlr.v4.analysis;
|
||||
|
||||
import org.antlr.v4.misc.OrderedHashSet;
|
||||
import org.antlr.v4.runtime.atn.*;
|
||||
import org.antlr.v4.runtime.misc.OrderedHashSet;
|
||||
import org.antlr.v4.tool.*;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -24,7 +24,7 @@ public class LeftRecursionDetector {
|
|||
}
|
||||
|
||||
public void check() {
|
||||
for (RuleStartState start : atn.ruleToStartState.values()) {
|
||||
for (RuleStartState start : atn.ruleToStartState) {
|
||||
//System.out.print("check "+start.rule.name);
|
||||
rulesVisitedPerRuleCheck.clear();
|
||||
rulesVisitedPerRuleCheck.add(start);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.antlr.v4.automata;
|
||||
|
||||
import org.antlr.v4.misc.*;
|
||||
import org.antlr.v4.parse.ANTLRParser;
|
||||
import org.antlr.v4.runtime.atn.*;
|
||||
import org.antlr.v4.runtime.misc.IntervalSet;
|
||||
import org.antlr.v4.tool.*;
|
||||
|
@ -40,7 +41,10 @@ public class ATNSerializer {
|
|||
*/
|
||||
public List<Integer> serialize() {
|
||||
List<Integer> data = new ArrayList<Integer>();
|
||||
data.add(g.getType());
|
||||
// convert grammar type to ATN const to avoid dependence on ANTLRParser
|
||||
if ( g.getType()== ANTLRParser.LEXER ) data.add(ATN.LEXER);
|
||||
else if ( g.getType()== ANTLRParser.PARSER ) data.add(ATN.PARSER);
|
||||
else data.add(ATN.TREE_PARSER);
|
||||
data.add(g.getMaxTokenType());
|
||||
data.add(atn.states.size());
|
||||
int nedges = 0;
|
||||
|
@ -59,13 +63,13 @@ public class ATNSerializer {
|
|||
}
|
||||
}
|
||||
}
|
||||
int nrules = atn.rules.size();
|
||||
int nrules = atn.ruleToStartState.length;
|
||||
data.add(nrules);
|
||||
for (int r=0; r<nrules; r++) {
|
||||
ATNState ruleStartState = atn.rules.get(r);
|
||||
ATNState ruleStartState = atn.ruleToStartState[r];
|
||||
data.add(ruleStartState.stateNumber);
|
||||
if ( g.isLexer() ) {
|
||||
data.add(atn.ruleToTokenType.get(r));
|
||||
data.add(atn.ruleToTokenType[r]);
|
||||
String ruleName = g.rules.getKey(r);
|
||||
Rule rule = g.getRule(ruleName);
|
||||
data.add(rule.actionIndex);
|
||||
|
@ -148,9 +152,9 @@ public class ATNSerializer {
|
|||
data.add(arg2);
|
||||
}
|
||||
}
|
||||
int ndecisions = atn.decisionToATNState.size();
|
||||
int ndecisions = atn.decisionToState.size();
|
||||
data.add(ndecisions);
|
||||
for (ATNState decStartState : atn.decisionToATNState) {
|
||||
for (ATNState decStartState : atn.decisionToState) {
|
||||
data.add(decStartState.stateNumber);
|
||||
}
|
||||
return data;
|
||||
|
|
|
@ -21,10 +21,11 @@ public class LexerATNFactory extends ParserATNFactory {
|
|||
}
|
||||
|
||||
// INIT ACTION, RULE->TOKEN_TYPE MAP
|
||||
atn.ruleToTokenType = new int[g.rules.size()];
|
||||
atn.ruleToActionIndex = new int[g.rules.size()];
|
||||
for (Rule r : g.rules.values()) {
|
||||
atn.ruleToTokenType.add(g.getTokenType(r.name));
|
||||
if ( r.actionIndex>0 ) atn.ruleToActionIndex.add(r.actionIndex);
|
||||
else atn.ruleToActionIndex.add(0);
|
||||
atn.ruleToTokenType[r.index] = g.getTokenType(r.name);
|
||||
atn.ruleToActionIndex[r.index] = r.actionIndex;
|
||||
}
|
||||
|
||||
// CREATE ATN FOR EACH RULE
|
||||
|
@ -36,7 +37,7 @@ public class LexerATNFactory extends ParserATNFactory {
|
|||
TokensStartState startState = atn.modeNameToStartState.get(modeName);
|
||||
for (Rule r : rules) {
|
||||
if ( !r.isFragment() ) {
|
||||
RuleStartState s = atn.ruleToStartState.get(r.index);
|
||||
RuleStartState s = atn.ruleToStartState[r.index];
|
||||
epsilon(startState, s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,9 +57,9 @@ public class ParserATNFactory implements ATNFactory {
|
|||
/* start->ruleblock->end */
|
||||
public Handle rule(GrammarAST ruleAST, String name, Handle blk) {
|
||||
Rule r = g.getRule(name);
|
||||
RuleStartState start = atn.ruleToStartState.get(r.index);
|
||||
RuleStartState start = atn.ruleToStartState[r.index];
|
||||
epsilon(start, blk.left);
|
||||
RuleStopState stop = atn.ruleToStopState.get(r.index);
|
||||
RuleStopState stop = atn.ruleToStopState[r.index];
|
||||
epsilon(blk.right, stop);
|
||||
Handle h = new Handle(start, stop);
|
||||
// FASerializer ser = new FASerializer(g, h.left);
|
||||
|
@ -141,7 +141,7 @@ public class ParserATNFactory implements ATNFactory {
|
|||
|
||||
public Handle _ruleRef(GrammarAST node) {
|
||||
Rule r = g.getRule(node.getText());
|
||||
RuleStartState start = atn.ruleToStartState.get(r.index);
|
||||
RuleStartState start = atn.ruleToStartState[r.index];
|
||||
ATNState left = newState(node);
|
||||
ATNState right = newState(node);
|
||||
RuleTransition call = new RuleTransition(r, start, right);
|
||||
|
@ -153,7 +153,7 @@ public class ParserATNFactory implements ATNFactory {
|
|||
|
||||
public void addFollowLink(Rule r, ATNState right) {
|
||||
// add follow edge from end of invoked rule
|
||||
RuleStopState stop = atn.ruleToStopState.get(r.index);
|
||||
RuleStopState stop = atn.ruleToStopState[r.index];
|
||||
epsilon(stop, right);
|
||||
}
|
||||
|
||||
|
@ -413,15 +413,16 @@ public class ParserATNFactory implements ATNFactory {
|
|||
* issues.
|
||||
*/
|
||||
void createRuleStartAndStopATNStates() {
|
||||
atn.ruleToStartState = new RuleStartState[g.rules.size()];
|
||||
atn.ruleToStopState = new RuleStopState[g.rules.size()];
|
||||
for (Rule r : g.rules.values()) {
|
||||
RuleStartState start = (RuleStartState)newState(RuleStartState.class, r.ast);
|
||||
RuleStopState stop = (RuleStopState)newState(RuleStopState.class, r.ast);
|
||||
start.stopState = stop;
|
||||
start.setRule(r);
|
||||
stop.setRule(r);
|
||||
atn.ruleToStartState.put(r.index, start);
|
||||
atn.rules.add(start);
|
||||
atn.ruleToStopState.put(r.index, stop);
|
||||
atn.ruleToStartState[r.index] = start;
|
||||
atn.ruleToStopState[r.index] = stop;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -437,7 +438,7 @@ public class ParserATNFactory implements ATNFactory {
|
|||
int n = 0;
|
||||
ATNState eofTarget = newState(null); // one unique EOF target for all rules
|
||||
for (Rule r : g.rules.values()) {
|
||||
ATNState stop = atn.ruleToStopState.get(r.index);
|
||||
ATNState stop = atn.ruleToStopState[r.index];
|
||||
if ( stop.getNumberOfTransitions()>0 ) continue;
|
||||
n++;
|
||||
Transition t = new AtomTransition(Token.EOF, eofTarget);
|
||||
|
|
|
@ -2,8 +2,9 @@ package org.antlr.v4.codegen.model;
|
|||
|
||||
import org.antlr.v4.codegen.OutputModelFactory;
|
||||
import org.antlr.v4.codegen.model.decl.*;
|
||||
import org.antlr.v4.misc.*;
|
||||
import org.antlr.v4.misc.Utils;
|
||||
import org.antlr.v4.runtime.atn.ATNState;
|
||||
import org.antlr.v4.runtime.misc.OrderedHashSet;
|
||||
import org.antlr.v4.tool.*;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -77,7 +78,7 @@ public class RuleFunction extends OutputModelObject {
|
|||
addLocalDecl(new KidsListDecl(factory, 0));
|
||||
}
|
||||
|
||||
startState = factory.getGrammar().atn.ruleToStartState.get(r.index);
|
||||
startState = factory.getGrammar().atn.ruleToStartState[r.index];
|
||||
}
|
||||
|
||||
/** Add local var decl */
|
||||
|
|
|
@ -80,7 +80,7 @@ public class Rule implements AttributeResolver {
|
|||
/** All rules have unique index 0..n-1 */
|
||||
public int index;
|
||||
|
||||
public int actionIndex; // if lexer
|
||||
public int actionIndex = -1; // if lexer; 0..n-1
|
||||
|
||||
public Rule(Grammar g, String name, RuleAST ast, int numberOfAlts) {
|
||||
this.g = g;
|
||||
|
@ -94,7 +94,7 @@ public class Rule implements AttributeResolver {
|
|||
public void defineActionInAlt(int currentAlt, ActionAST actionAST) {
|
||||
alt[currentAlt].actions.add(actionAST);
|
||||
if ( g.isLexer() || actionAST.getType()== ANTLRParser.FORCED_ACTION ) {
|
||||
actionIndex = g.actions.size() + 1;
|
||||
actionIndex = g.actions.size();
|
||||
g.actions.put(actionAST, actionIndex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,7 +174,7 @@ public abstract class BaseTest {
|
|||
ErrorQueue equeue = new ErrorQueue();
|
||||
Grammar g = new Grammar(gtext, equeue);
|
||||
ATN atn = createATN(g);
|
||||
ATNState s = atn.ruleToStartState.get(g.getRule(ruleName).index);
|
||||
ATNState s = atn.ruleToStartState[g.getRule(ruleName).index];
|
||||
if ( s==null ) {
|
||||
System.err.println("no such rule: "+ruleName);
|
||||
return null;
|
||||
|
@ -195,7 +195,7 @@ public abstract class BaseTest {
|
|||
ErrorQueue equeue = new ErrorQueue();
|
||||
Grammar g = new Grammar(gtext, equeue);
|
||||
ATN atn = createATN(g);
|
||||
DecisionState blk = atn.decisionToATNState.get(decision);
|
||||
DecisionState blk = atn.decisionToState.get(decision);
|
||||
checkRuleDFA(g, blk, expecting);
|
||||
return equeue.all;
|
||||
}
|
||||
|
|
|
@ -941,10 +941,10 @@ public class TestATNConstruction extends BaseTest {
|
|||
ATN atn = f.createATN();
|
||||
|
||||
DOTGenerator dot = new DOTGenerator(g);
|
||||
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule(ruleName).index)));
|
||||
System.out.println(dot.getDOT(atn.ruleToStartState[g.getRule(ruleName).index]));
|
||||
|
||||
Rule r = g.getRule(ruleName);
|
||||
ATNState startState = atn.ruleToStartState.get(r.index);
|
||||
ATNState startState = atn.ruleToStartState[r.index];
|
||||
ATNPrinter serializer = new ATNPrinter(g, startState);
|
||||
String result = serializer.toString();
|
||||
|
||||
|
|
|
@ -274,15 +274,15 @@ public class TestATNInterpreter extends BaseTest {
|
|||
|
||||
ParserInterpreter interp = new ParserInterpreter(atn);
|
||||
TokenStream input = new IntTokenStream(types);
|
||||
ATNState startState = atn.ruleToStartState.get(g.getRule("a").index);
|
||||
ATNState startState = atn.ruleToStartState[g.getRule("a").index];
|
||||
if ( startState.transition(0).target instanceof BlockStartState ) {
|
||||
startState = startState.transition(0).target;
|
||||
}
|
||||
|
||||
DOTGenerator dot = new DOTGenerator(g);
|
||||
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("a").index)));
|
||||
System.out.println(dot.getDOT(atn.ruleToStartState[g.getRule("a").index]));
|
||||
Rule r = g.getRule("e");
|
||||
if ( r!=null ) System.out.println(dot.getDOT(atn.ruleToStartState.get(r.index)));
|
||||
if ( r!=null ) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
|
||||
|
||||
int result = interp.matchATN(input, startState);
|
||||
assertEquals(expected, result);
|
||||
|
|
|
@ -269,9 +269,9 @@ public class TestATNParserPrediction extends BaseTest {
|
|||
ParserATNFactory f = new ParserATNFactory(g);
|
||||
ATN atn = f.createATN();
|
||||
|
||||
RuleStartState aStart = atn.ruleToStartState.get(g.getRule("a").index);
|
||||
RuleStartState bStart = atn.ruleToStartState.get(g.getRule("b").index);
|
||||
RuleStartState eStart = atn.ruleToStartState.get(g.getRule("e").index);
|
||||
RuleStartState aStart = atn.ruleToStartState[g.getRule("a").index];
|
||||
RuleStartState bStart = atn.ruleToStartState[g.getRule("b").index];
|
||||
RuleStartState eStart = atn.ruleToStartState[g.getRule("e").index];
|
||||
ATNState a_e_invoke = aStart.transition(0).target; //
|
||||
ATNState b_e_invoke = bStart.transition(0).target; //
|
||||
RuleContext a_ctx = new RuleContext(null, -1, a_e_invoke.stateNumber);
|
||||
|
@ -491,16 +491,16 @@ public class TestATNParserPrediction extends BaseTest {
|
|||
ATN atn = f.createATN();
|
||||
|
||||
DOTGenerator dot = new DOTGenerator(g);
|
||||
System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("a").index)));
|
||||
System.out.println(dot.getDOT(atn.ruleToStartState[g.getRule("a").index]));
|
||||
Rule r = g.getRule("b");
|
||||
if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState.get(r.index)));
|
||||
if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
|
||||
r = g.getRule("e");
|
||||
if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState.get(r.index)));
|
||||
if ( r!=null) System.out.println(dot.getDOT(atn.ruleToStartState[r.index]));
|
||||
|
||||
// Check ATN prediction
|
||||
ParserInterpreter interp = new ParserInterpreter(atn);
|
||||
TokenStream input = new IntTokenStream(types);
|
||||
ATNState startState = atn.decisionToATNState.get(decision);
|
||||
ATNState startState = atn.decisionToState.get(decision);
|
||||
DFA dfa = new DFA(startState);
|
||||
int alt = interp.predictATN(dfa, input, decision, RuleContext.EMPTY, false);
|
||||
|
||||
|
@ -542,7 +542,7 @@ public class TestATNParserPrediction extends BaseTest {
|
|||
System.out.println(types);
|
||||
TokenStream input = new IntTokenStream(types);
|
||||
try {
|
||||
ATNState startState = atn.decisionToATNState.get(0);
|
||||
ATNState startState = atn.decisionToState.get(0);
|
||||
DFA dfa = new DFA(startState);
|
||||
// Rule r = g.getRule(ruleName);
|
||||
//ATNState startState = atn.ruleToStartState.get(r);
|
||||
|
|
|
@ -242,8 +242,8 @@ public class TestATNSerialization extends BaseTest {
|
|||
"6:BASIC 0\n" +
|
||||
"7:BASIC 1\n" +
|
||||
"8:BASIC 1\n" +
|
||||
"rule 1:1 3,0\n" +
|
||||
"rule 2:3 4,0\n" +
|
||||
"rule 1:1 3,-1\n" +
|
||||
"rule 2:3 4,-1\n" +
|
||||
"mode 0:0\n" +
|
||||
"0->1 EPSILON 0,0\n" +
|
||||
"0->3 EPSILON 0,0\n" +
|
||||
|
@ -270,7 +270,7 @@ public class TestATNSerialization extends BaseTest {
|
|||
"2:RULE_STOP 0\n" +
|
||||
"3:BASIC 0\n" +
|
||||
"4:BASIC 0\n" +
|
||||
"rule 1:1 3,0\n" +
|
||||
"rule 1:1 3,-1\n" +
|
||||
"mode 0:0\n" +
|
||||
"0->1 EPSILON 0,0\n" +
|
||||
"1->3 EPSILON 0,0\n" +
|
||||
|
@ -297,7 +297,7 @@ public class TestATNSerialization extends BaseTest {
|
|||
"6:BLOCK_END 0\n" +
|
||||
"7:PLUS_LOOP_BACK 0\n" +
|
||||
"8:BASIC 0\n" +
|
||||
"rule 1:1 3,0\n" +
|
||||
"rule 1:1 3,-1\n" +
|
||||
"mode 0:0\n" +
|
||||
"0->1 EPSILON 0,0\n" +
|
||||
"1->5 EPSILON 0,0\n" +
|
||||
|
@ -340,9 +340,9 @@ public class TestATNSerialization extends BaseTest {
|
|||
"12:BASIC 2\n" +
|
||||
"13:BASIC 2\n" +
|
||||
"14:BASIC 2\n" +
|
||||
"rule 1:1 3,1\n" +
|
||||
"rule 2:3 4,0\n" +
|
||||
"rule 3:5 5,2\n" +
|
||||
"rule 1:1 3,0\n" +
|
||||
"rule 2:3 4,-1\n" +
|
||||
"rule 3:5 5,1\n" +
|
||||
"mode 0:0\n" +
|
||||
"0->1 EPSILON 0,0\n" +
|
||||
"0->3 EPSILON 0,0\n" +
|
||||
|
@ -375,7 +375,7 @@ public class TestATNSerialization extends BaseTest {
|
|||
"2:RULE_STOP 0\n" +
|
||||
"3:BASIC 0\n" +
|
||||
"4:BASIC 0\n" +
|
||||
"rule 1:1 3,0\n" +
|
||||
"rule 1:1 3,-1\n" +
|
||||
"mode 0:0\n" +
|
||||
"0:'a'..'b'\n" +
|
||||
"0->1 EPSILON 0,0\n" +
|
||||
|
@ -399,7 +399,7 @@ public class TestATNSerialization extends BaseTest {
|
|||
"2:RULE_STOP 0\n" +
|
||||
"3:BASIC 0\n" +
|
||||
"4:BASIC 0\n" +
|
||||
"rule 1:1 3,0\n" +
|
||||
"rule 1:1 3,-1\n" +
|
||||
"mode 0:0\n" +
|
||||
"0:'a'..'b', 'e'..'e', 'p'..'t'\n" +
|
||||
"0->1 EPSILON 0,0\n" +
|
||||
|
@ -425,7 +425,7 @@ public class TestATNSerialization extends BaseTest {
|
|||
"4:BASIC 0\n" +
|
||||
"5:BASIC 0\n" +
|
||||
"6:BASIC 0\n" +
|
||||
"rule 1:1 3,0\n" +
|
||||
"rule 1:1 3,-1\n" +
|
||||
"mode 0:0\n" +
|
||||
"0:'a'..'b'\n" +
|
||||
"1:'e'..'e', 'p'..'t'\n" +
|
||||
|
@ -466,9 +466,9 @@ public class TestATNSerialization extends BaseTest {
|
|||
"12:BASIC 1\n" +
|
||||
"13:BASIC 2\n" +
|
||||
"14:BASIC 2\n" +
|
||||
"rule 1:3 3,0\n" +
|
||||
"rule 2:5 4,0\n" +
|
||||
"rule 3:7 5,0\n" +
|
||||
"rule 1:3 3,-1\n" +
|
||||
"rule 2:5 4,-1\n" +
|
||||
"rule 3:7 5,-1\n" +
|
||||
"mode 0:0\n" +
|
||||
"mode 1:1\n" +
|
||||
"mode 2:2\n" +
|
||||
|
|
Loading…
Reference in New Issue