rename atn sim, add error message to TestRig

This commit is contained in:
Terence Parr 2012-02-05 10:14:04 -08:00
parent c47c07299a
commit 894a77168d
8 changed files with 28 additions and 29 deletions

View File

@ -38,7 +38,7 @@ import java.util.ArrayList;
import java.util.List;
/** This is all the parsing support code essentially; most of it is error recovery stuff. */
public abstract class Parser extends Recognizer<Token, v2ParserATNSimulator<Token>> {
public abstract class Parser extends Recognizer<Token, ParserATNSimulator<Token>> {
public class TraceListener implements ParseTreeListener<Token> {
@Override
public void enterEveryRule(ParserRuleContext<Token> ctx) {

View File

@ -43,7 +43,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ParserATNPathFinder extends v2ParserATNSimulator {
public class ParserATNPathFinder extends ParserATNSimulator {
public ParserATNPathFinder(@Nullable Parser parser, @NotNull ATN atn) {
super(parser, atn);
}

View File

@ -225,7 +225,7 @@ import java.util.*;
* when closure operations fall off the end of the rule that
* holds the decision were evaluating
*/
public class v2ParserATNSimulator<Symbol> extends ATNSimulator {
public class ParserATNSimulator<Symbol> extends ATNSimulator {
public static boolean debug = false;
public static boolean dfa_debug = false;
public static boolean retry_debug = false;
@ -242,11 +242,11 @@ public class v2ParserATNSimulator<Symbol> extends ATNSimulator {
public final DFA[] decisionToDFA;
/** Testing only! */
public v2ParserATNSimulator(@NotNull ATN atn) {
public ParserATNSimulator(@NotNull ATN atn) {
this(null, atn);
}
public v2ParserATNSimulator(@Nullable Parser parser, @NotNull ATN atn) {
public ParserATNSimulator(@Nullable Parser parser, @NotNull ATN atn) {
super(atn);
this.parser = parser;
// ctxToDFAs = new HashMap<RuleContext, DFA[]>();

View File

@ -28,10 +28,8 @@
*/
package org.antlr.v4.runtime.dfa;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
@ -83,7 +81,7 @@ public class DFA {
// return states;
// }
public List<Set<ATNState>> getATNStatesAlongPath(v2ParserATNSimulator atn,
public List<Set<ATNState>> getATNStatesAlongPath(ParserATNSimulator atn,
List<DFAState> dfaStates,
TokenStream input, int start, int stop)
{

View File

@ -60,8 +60,8 @@ public class TestRig {
String encoding = null;
if ( args.length < 2 ) {
System.err.println("java org.antlr.v4.runtime.misc.TestRig GrammarName startRuleName" +
" [-print] [-tokens] [-gui] [-encoding encodingname]" +
" [-ps file.ps] [-trace] [input-filename]");
" [-tokens] [-print] [-gui] [-ps file.ps] [-encoding encodingname] [-trace]"+
" [input-filename]");
return;
}
int i=0;
@ -155,17 +155,22 @@ public class TestRig {
parser.setTrace(trace);
Method startRule = parserClass.getMethod(startRuleName, (Class[])null);
ParserRuleContext<Token> tree = (ParserRuleContext<Token>)startRule.invoke(parser, (Object[])null);
try {
Method startRule = parserClass.getMethod(startRuleName, (Class[])null);
ParserRuleContext<Token> tree = (ParserRuleContext<Token>)startRule.invoke(parser, (Object[])null);
if ( printTree ) {
System.out.println(tree.toStringTree(parser));
if ( printTree ) {
System.out.println(tree.toStringTree(parser));
}
if ( gui ) {
tree.inspect(parser);
}
if ( psFile!=null ) {
tree.save(parser, psFile); // Generate postscript
}
}
if ( gui ) {
tree.inspect(parser);
}
if ( psFile!=null ) {
tree.save(parser, psFile); // Generate postscript
catch (NoSuchMethodException nsme) {
System.err.println("No method for rule "+startRuleName+" or it has arguments");
}
}
finally {

View File

@ -33,14 +33,10 @@ import org.antlr.v4.Tool;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
import org.antlr.v4.runtime.misc.Nullable;
import org.antlr.v4.tool.Grammar;
import java.util.HashSet;
import java.util.Set;
public class ParserInterpreter {
class DummyParser extends Parser {
public Grammar g;
@ -61,7 +57,7 @@ public class ParserInterpreter {
}
protected Grammar g;
protected v2ParserATNSimulator<Token> atnSimulator;
protected ParserATNSimulator<Token> atnSimulator;
protected TokenStream input;
public ParserInterpreter(@NotNull Grammar g) {
@ -71,7 +67,7 @@ public class ParserInterpreter {
public ParserInterpreter(@NotNull Grammar g, @NotNull TokenStream input) {
Tool antlr = new Tool();
antlr.process(g,false);
atnSimulator = new v2ParserATNSimulator<Token>(new DummyParser(g, input), g.atn);
atnSimulator = new ParserATNSimulator<Token>(new DummyParser(g, input), g.atn);
}
public int predictATN(@NotNull DFA dfa, @NotNull SymbolStream<Token> input,
@ -104,7 +100,7 @@ public class ParserInterpreter {
}
}
public v2ParserATNSimulator<Token> getATNSimulator() {
public ParserATNSimulator<Token> getATNSimulator() {
return atnSimulator;
}

View File

@ -3,7 +3,7 @@ package org.antlr.v4.test;
import org.antlr.v4.automata.ATNSerializer;
import org.antlr.v4.misc.Utils;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.v2ParserATNSimulator;
import org.antlr.v4.runtime.atn.ParserATNSimulator;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.LexerGrammar;
import org.junit.Test;
@ -147,7 +147,7 @@ public class TestATNDeserialization extends BaseTest {
ATN atn = createATN(g);
char[] data = Utils.toCharArray(ATNSerializer.getSerialized(g, atn));
String atnData = ATNSerializer.getDecoded(g, atn);
ATN atn2 = v2ParserATNSimulator.deserialize(data);
ATN atn2 = ParserATNSimulator.deserialize(data);
String atn2Data = ATNSerializer.getDecoded(g, atn2);
assertEquals(atnData, atn2Data);

View File

@ -541,7 +541,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("e"))));
v2ParserATNSimulator interp = new v2ParserATNSimulator(atn);
ParserATNSimulator interp = new ParserATNSimulator(atn);
List<Integer> types = getTokenTypesViaATN(inputString, lexInterp);
System.out.println(types);
TokenStream input = new IntTokenStream(types);