From fa62570737591bcafe5b823099cc713bd5e0fcb1 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 30 Jul 2012 13:55:29 -0500 Subject: [PATCH 1/4] Add IntegerList and IntegerStack, behaves like ArrayList and ArrayDeque (mostly) except doesn't require boxing --- .../antlr/v4/runtime/misc/IntegerList.java | 198 ++++++++++++++++++ .../antlr/v4/runtime/misc/IntegerStack.java | 61 ++++++ 2 files changed, 259 insertions(+) create mode 100644 runtime/Java/src/org/antlr/v4/runtime/misc/IntegerList.java create mode 100644 runtime/Java/src/org/antlr/v4/runtime/misc/IntegerStack.java diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/IntegerList.java b/runtime/Java/src/org/antlr/v4/runtime/misc/IntegerList.java new file mode 100644 index 000000000..15a9af713 --- /dev/null +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/IntegerList.java @@ -0,0 +1,198 @@ +/* + [The "BSD license"] + Copyright (c) 2012 Terence Parr + Copyright (c) 2012 Sam Harwell + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.antlr.v4.runtime.misc; + +import java.util.Arrays; +import java.util.Collection; + +/** + * + * @author Sam Harwell + */ +public class IntegerList { + + private static int[] EMPTY_DATA = new int[0]; + + private static final int INITIAL_SIZE = 4; + private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; + + @NotNull + private int[] _data; + + private int _size; + + public IntegerList() { + _data = EMPTY_DATA; + } + + public IntegerList(int capacity) { + if (capacity < 0) { + throw new IllegalArgumentException(); + } + + if (capacity == 0) { + _data = EMPTY_DATA; + } else { + _data = new int[capacity]; + } + } + + public IntegerList(@NotNull IntegerList list) { + _data = list._data.clone(); + _size = list._size; + } + + public IntegerList(@NotNull Collection list) { + this(list.size()); + for (Integer value : list) { + add(value); + } + } + + public final void add(int value) { + if (_data.length == _size) { + ensureCapacity(_size + 1); + } + + _data[_size] = value; + _size++; + } + + public final void addAll(IntegerList list) { + ensureCapacity(_size + list._size); + System.arraycopy(list._data, 0, _data, _size, list._size); + _size += list._size; + } + + public final void addAll(int[] array) { + ensureCapacity(_size + array.length); + System.arraycopy(array, 0, _data, _size, array.length); + _size += array.length; + } + + public final int get(int index) { + if (index < 0 || index >= _size) { + throw new IndexOutOfBoundsException(); + } + + return _data[index]; + } + + public final int set(int index, int value) { + if (index < 0 || index >= _size) { + throw new IndexOutOfBoundsException(); + } + + int previous = _data[index]; + _data[index] = value; + return previous; + } + + public final int removeAt(int index) { + int value = get(index); + System.arraycopy(_data, index + 1, _data, index, _size - index - 1); + _data[_size - 1] = 0; + _size--; + return value; + } + + public final void removeRange(int fromIndex, int toIndex) { + if (fromIndex < 0 || toIndex < 0 || fromIndex > _size || toIndex > _size) { + throw new IndexOutOfBoundsException(); + } + if (fromIndex > toIndex) { + throw new IllegalArgumentException(); + } + + System.arraycopy(_data, toIndex, _data, fromIndex, _size - toIndex); + Arrays.fill(_data, _size - (toIndex - fromIndex), _size, 0); + _size -= (toIndex - fromIndex); + } + + public final boolean isEmpty() { + return _size == 0; + } + + public final int size() { + return _size; + } + + public final void trimToSize() { + if (_data.length == _size) { + return; + } + + _data = Arrays.copyOf(_data, _size); + } + + public final void clear() { + Arrays.fill(_data, 0, _size, 0); + _size = 0; + } + + public final int[] toArray() { + if (_size == 0) { + return EMPTY_DATA; + } + + return Arrays.copyOf(_data, _size); + } + + public final int binarySearch(int key) { + return Arrays.binarySearch(_data, key); + } + + public final int binarySearch(int fromIndex, int toIndex, int key) { + return Arrays.binarySearch(_data, fromIndex, toIndex, key); + } + + private void ensureCapacity(int capacity) { + if (capacity < 0 || capacity > MAX_ARRAY_SIZE) { + throw new OutOfMemoryError(); + } + + int newLength; + if (_data.length == 0) { + newLength = INITIAL_SIZE; + } else { + newLength = _data.length; + } + + while (newLength < capacity) { + newLength = newLength * 2; + if (newLength < 0 || newLength > MAX_ARRAY_SIZE) { + newLength = MAX_ARRAY_SIZE; + } + } + + _data = Arrays.copyOf(_data, newLength); + } + +} diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/IntegerStack.java b/runtime/Java/src/org/antlr/v4/runtime/misc/IntegerStack.java new file mode 100644 index 000000000..eec0e751a --- /dev/null +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/IntegerStack.java @@ -0,0 +1,61 @@ +/* + [The "BSD license"] + Copyright (c) 2012 Terence Parr + Copyright (c) 2012 Sam Harwell + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.antlr.v4.runtime.misc; + +/** + * + * @author Sam Harwell + */ +public class IntegerStack extends IntegerList { + + public IntegerStack() { + } + + public IntegerStack(int capacity) { + super(capacity); + } + + public IntegerStack(@NotNull IntegerStack list) { + super(list); + } + + public final void push(int value) { + add(value); + } + + public final int pop() { + return removeAt(size() - 1); + } + + public final int peek() { + return get(size() - 1); + } + +} From 3bf99d6d88b2d6c32aed5a2dc9fe6262e6e2d791 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 30 Jul 2012 13:56:19 -0500 Subject: [PATCH 2/4] Add IntervalSet.toIntegerList(), use IntegerStack to hold mode stack in Lexer --- .../Java/src/org/antlr/v4/runtime/Lexer.java | 4 +-- .../antlr/v4/runtime/misc/IntervalSet.java | 28 ++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/Lexer.java b/runtime/Java/src/org/antlr/v4/runtime/Lexer.java index 34b2fe426..55322153c 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/Lexer.java +++ b/runtime/Java/src/org/antlr/v4/runtime/Lexer.java @@ -29,9 +29,9 @@ package org.antlr.v4.runtime; import org.antlr.v4.runtime.atn.LexerATNSimulator; +import org.antlr.v4.runtime.misc.IntegerStack; import org.antlr.v4.runtime.misc.Interval; -import java.util.ArrayDeque; import java.util.ArrayList; import java.util.EmptyStackException; import java.util.List; @@ -91,7 +91,7 @@ public abstract class Lexer extends Recognizer /** The token type for the current token */ public int _type; - public ArrayDeque _modeStack = new ArrayDeque(); + public final IntegerStack _modeStack = new IntegerStack(); public int _mode = Lexer.DEFAULT_MODE; /** You can set the text for the current token to override what is in diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java b/runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java index dc1f25062..21dd7a271 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/IntervalSet.java @@ -530,6 +530,20 @@ public class IntervalSet implements IntSet { return n; } + public IntegerList toIntegerList() { + IntegerList values = new IntegerList(size()); + int n = intervals.size(); + for (int i = 0; i < n; i++) { + Interval I = intervals.get(i); + int a = I.a; + int b = I.b; + for (int v=a; v<=b; v++) { + values.add(v); + } + } + return values; + } + @Override public List toList() { List values = new ArrayList(); @@ -579,19 +593,7 @@ public class IntervalSet implements IntSet { } public int[] toArray() { - int[] values = new int[size()]; - int n = intervals.size(); - int j = 0; - for (int i = 0; i < n; i++) { - Interval I = intervals.get(i); - int a = I.a; - int b = I.b; - for (int v=a; v<=b; v++) { - values[j] = v; - j++; - } - } - return values; + return toIntegerList().toArray(); } @Override From dcdcad8febddeee5dfac608dcbb94228a278838c Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 30 Jul 2012 14:39:27 -0500 Subject: [PATCH 3/4] Add IntegerList.addAll overload for Collection, add contains, sort, hashCode, equals, toString. --- .../antlr/v4/runtime/misc/IntegerList.java | 101 +++++++++++++++++- 1 file changed, 97 insertions(+), 4 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/misc/IntegerList.java b/runtime/Java/src/org/antlr/v4/runtime/misc/IntegerList.java index 15a9af713..84388291b 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/misc/IntegerList.java +++ b/runtime/Java/src/org/antlr/v4/runtime/misc/IntegerList.java @@ -85,16 +85,26 @@ public class IntegerList { _size++; } + public final void addAll(int[] array) { + ensureCapacity(_size + array.length); + System.arraycopy(array, 0, _data, _size, array.length); + _size += array.length; + } + public final void addAll(IntegerList list) { ensureCapacity(_size + list._size); System.arraycopy(list._data, 0, _data, _size, list._size); _size += list._size; } - public final void addAll(int[] array) { - ensureCapacity(_size + array.length); - System.arraycopy(array, 0, _data, _size, array.length); - _size += array.length; + public final void addAll(Collection list) { + ensureCapacity(_size + list.size()); + int current = 0; + for (int x : list) { + _data[_size + current] = x; + } + + _size += list.size(); } public final int get(int index) { @@ -105,6 +115,16 @@ public class IntegerList { return _data[index]; } + public final boolean contains(int value) { + for (int i = 0; i < _size; i++) { + if (_data[i] == value) { + return true; + } + } + + return false; + } + public final int set(int index, int value) { if (index < 0 || index >= _size) { throw new IndexOutOfBoundsException(); @@ -165,6 +185,79 @@ public class IntegerList { return Arrays.copyOf(_data, _size); } + public final void sort() { + Arrays.sort(_data, 0, _size); + } + + /** + * Compares the specified object with this list for equality. Returns + * {@code true} if and only if the specified object is also an {@code IntegerList}, + * both lists have the same size, and all corresponding pairs of elements in + * the two lists are equal. In other words, two lists are defined to be + * equal if they contain the same elements in the same order. + *

+ * This implementation first checks if the specified object is this + * list. If so, it returns {@code true}; if not, it checks if the + * specified object is an {@code IntegerList}. If not, it returns {@code false}; + * if so, it checks the size of both lists. If the lists are not the same size, + * it returns {@code false}; otherwise it iterates over both lists, comparing + * corresponding pairs of elements. If any comparison returns {@code false}, + * this method returns {@code false}. + * + * @param o the object to be compared for equality with this list + * @return {@code true} if the specified object is equal to this list + */ + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + + if (!(o instanceof IntegerList)) { + return false; + } + + IntegerList other = (IntegerList)o; + if (_size != other._size) { + return false; + } + + for (int i = 0; i < _size; i++) { + if (_data[i] != other._data[i]) { + return false; + } + } + + return true; + } + + /** + * Returns the hash code value for this list. + * + *

This implementation uses exactly the code that is used to define the + * list hash function in the documentation for the {@link List#hashCode} + * method. + * + * @return the hash code value for this list + */ + @Override + public int hashCode() { + int hashCode = 1; + for (int i = 0; i < _size; i++) { + hashCode = 31*hashCode + _data[i]; + } + + return hashCode; + } + + /** + * Returns a string representation of this list. + */ + @Override + public String toString() { + return Arrays.toString(toArray()); + } + public final int binarySearch(int key) { return Arrays.binarySearch(_data, key); } From 7d4f71d829b24a2aaf6a52d2add6123212d3cb37 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 30 Jul 2012 14:58:28 -0500 Subject: [PATCH 4/4] Use IntegerList in the tool --- tool/src/org/antlr/v4/automata/ATNSerializer.java | 9 +++++---- .../org/antlr/v4/codegen/model/SerializedATN.java | 5 +++-- tool/src/org/antlr/v4/misc/Utils.java | 12 +++--------- tool/src/org/antlr/v4/tool/DOTGenerator.java | 5 +++-- tool/src/org/antlr/v4/tool/Grammar.java | 6 +++--- tool/test/org/antlr/v4/test/BaseTest.java | 13 +++++++------ tool/test/org/antlr/v4/test/TestATNInterpreter.java | 6 ++---- .../org/antlr/v4/test/TestATNParserPrediction.java | 9 ++++----- 8 files changed, 30 insertions(+), 35 deletions(-) diff --git a/tool/src/org/antlr/v4/automata/ATNSerializer.java b/tool/src/org/antlr/v4/automata/ATNSerializer.java index 5d727854b..bb3fa6653 100644 --- a/tool/src/org/antlr/v4/automata/ATNSerializer.java +++ b/tool/src/org/antlr/v4/automata/ATNSerializer.java @@ -32,6 +32,7 @@ package org.antlr.v4.automata; import org.antlr.v4.misc.Utils; import org.antlr.v4.parse.ANTLRParser; import org.antlr.v4.runtime.atn.*; +import org.antlr.v4.runtime.misc.IntegerList; import org.antlr.v4.runtime.misc.Interval; import org.antlr.v4.runtime.misc.IntervalSet; import org.antlr.v4.tool.Grammar; @@ -71,8 +72,8 @@ public class ATNSerializer { * * Convenient to pack into unsigned shorts to make as Java string. */ - public List serialize() { - List data = new ArrayList(); + public IntegerList serialize() { + IntegerList data = new IntegerList(); // 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); @@ -277,7 +278,7 @@ public class ATNSerializer { return new String(Utils.toCharArray(getSerialized(g, atn))); } - public static List getSerialized(Grammar g, ATN atn) { + public static IntegerList getSerialized(Grammar g, ATN atn) { return new ATNSerializer(g, atn).serialize(); } @@ -286,7 +287,7 @@ public class ATNSerializer { } public static String getDecoded(Grammar g, ATN atn) { - List serialized = getSerialized(g, atn); + IntegerList serialized = getSerialized(g, atn); char[] data = Utils.toCharArray(serialized); return new ATNSerializer(g, atn).decode(data); } diff --git a/tool/src/org/antlr/v4/codegen/model/SerializedATN.java b/tool/src/org/antlr/v4/codegen/model/SerializedATN.java index c8706a76d..e58c3c511 100644 --- a/tool/src/org/antlr/v4/codegen/model/SerializedATN.java +++ b/tool/src/org/antlr/v4/codegen/model/SerializedATN.java @@ -32,6 +32,7 @@ package org.antlr.v4.codegen.model; import org.antlr.v4.automata.ATNSerializer; import org.antlr.v4.codegen.OutputModelFactory; import org.antlr.v4.runtime.atn.ATN; +import org.antlr.v4.runtime.misc.IntegerList; import java.util.*; @@ -40,9 +41,9 @@ public class SerializedATN extends OutputModelObject { public List serialized; public SerializedATN(OutputModelFactory factory, ATN atn) { super(factory); - List data = ATNSerializer.getSerialized(factory.getGrammar(), atn); + IntegerList data = ATNSerializer.getSerialized(factory.getGrammar(), atn); serialized = new ArrayList(data.size()); - for (int c : data) { + for (int c : data.toArray()) { String encoded = factory.getGenerator().target.encodeIntAsCharEscape(c == -1 ? Character.MAX_VALUE : c); serialized.add(encoded); } diff --git a/tool/src/org/antlr/v4/misc/Utils.java b/tool/src/org/antlr/v4/misc/Utils.java index 7dd29e7dc..3006d7da0 100644 --- a/tool/src/org/antlr/v4/misc/Utils.java +++ b/tool/src/org/antlr/v4/misc/Utils.java @@ -29,6 +29,7 @@ package org.antlr.v4.misc; +import org.antlr.v4.runtime.misc.IntegerList; import org.antlr.v4.tool.ast.GrammarAST; import java.util.*; @@ -137,13 +138,6 @@ public class Utils { // return x; // } - public static int[] toIntArray(List list) { - if ( list==null ) return null; - int[] a = new int[list.size()]; - for (int i=0; i data) { + public static char[] toCharArray(IntegerList data) { if ( data==null ) return null; char[] cdata = new char[data.size()]; for (int i=0; i altList = new ArrayList(); + IntegerList altList = new IntegerList(); altList.addAll(alts); - Collections.sort(altList); + altList.sort(); Set configurations = s.configset; for (int altIndex = 0; altIndex < altList.size(); altIndex++) { int alt = altList.get(altIndex); diff --git a/tool/src/org/antlr/v4/tool/Grammar.java b/tool/src/org/antlr/v4/tool/Grammar.java index 7a644f7c5..27540169e 100644 --- a/tool/src/org/antlr/v4/tool/Grammar.java +++ b/tool/src/org/antlr/v4/tool/Grammar.java @@ -46,6 +46,7 @@ import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.atn.ATN; import org.antlr.v4.runtime.dfa.DFA; import org.antlr.v4.runtime.misc.IntSet; +import org.antlr.v4.runtime.misc.IntegerList; import org.antlr.v4.runtime.misc.IntervalSet; import org.antlr.v4.runtime.misc.NotNull; import org.antlr.v4.runtime.misc.Nullable; @@ -58,7 +59,6 @@ import org.antlr.v4.tool.ast.TerminalAST; import java.io.IOException; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -466,9 +466,9 @@ public class Grammar implements AttributeResolver { return tokenName; } - public List getTokenDisplayNames(Collection types) { + public List getTokenDisplayNames(IntegerList types) { List names = new ArrayList(); - for (int t : types) names.add(getTokenDisplayName(t)); + for (int t : types.toArray()) names.add(getTokenDisplayName(t)); return names; } diff --git a/tool/test/org/antlr/v4/test/BaseTest.java b/tool/test/org/antlr/v4/test/BaseTest.java index 8009a1254..ad6c7e13f 100644 --- a/tool/test/org/antlr/v4/test/BaseTest.java +++ b/tool/test/org/antlr/v4/test/BaseTest.java @@ -50,6 +50,7 @@ import org.antlr.v4.runtime.atn.ATNState; import org.antlr.v4.runtime.atn.DecisionState; import org.antlr.v4.runtime.atn.LexerATNSimulator; import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.misc.IntegerList; import org.antlr.v4.runtime.misc.Interval; import org.antlr.v4.runtime.misc.Nullable; import org.antlr.v4.semantics.SemanticPipeline; @@ -184,8 +185,8 @@ public abstract class BaseTest { // dfa.minimized = dmin.minimize(); // } - List getTypesFromString(Grammar g, String expecting) { - List expectingTokenTypes = new ArrayList(); + IntegerList getTypesFromString(Grammar g, String expecting) { + IntegerList expectingTokenTypes = new IntegerList(); if ( expecting!=null && !expecting.trim().isEmpty() ) { for (String tname : expecting.replace(" ", "").split(",")) { int ttype = g.getTokenType(tname); @@ -195,9 +196,9 @@ public abstract class BaseTest { return expectingTokenTypes; } - public List getTokenTypesViaATN(String input, LexerATNSimulator lexerATN) { + public IntegerList getTokenTypesViaATN(String input, LexerATNSimulator lexerATN) { ANTLRInputStream in = new ANTLRInputStream(input); - List tokenTypes = new ArrayList(); + IntegerList tokenTypes = new IntegerList(); int ttype; do { ttype = lexerATN.matchATN(in); @@ -1065,9 +1066,9 @@ public abstract class BaseTest { public void assertNull(Object object) { try {Assert.assertNull(object);} catch (Error e) {lastTestFailed=true; throw e;} } public static class IntTokenStream implements TokenStream { - List types; + IntegerList types; int p=0; - public IntTokenStream(List types) { this.types = types; } + public IntTokenStream(IntegerList types) { this.types = types; } @Override public void consume() { p++; } diff --git a/tool/test/org/antlr/v4/test/TestATNInterpreter.java b/tool/test/org/antlr/v4/test/TestATNInterpreter.java index f7c120430..32fab5105 100644 --- a/tool/test/org/antlr/v4/test/TestATNInterpreter.java +++ b/tool/test/org/antlr/v4/test/TestATNInterpreter.java @@ -7,6 +7,7 @@ import org.antlr.v4.runtime.atn.ATN; import org.antlr.v4.runtime.atn.ATNState; import org.antlr.v4.runtime.atn.BlockStartState; import org.antlr.v4.runtime.atn.LexerATNSimulator; +import org.antlr.v4.runtime.misc.IntegerList; import org.antlr.v4.tool.DOTGenerator; import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.LexerGrammar; @@ -14,9 +15,6 @@ import org.antlr.v4.tool.Rule; import org.antlr.v4.tool.interp.ParserInterpreter; import org.junit.Test; -import java.util.List; - - // NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH // NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH // NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH @@ -275,7 +273,7 @@ public class TestATNInterpreter extends BaseTest { { ATN lexatn = createATN(lg); LexerATNSimulator lexInterp = new LexerATNSimulator(lexatn); - List types = getTokenTypesViaATN(inputString, lexInterp); + IntegerList types = getTokenTypesViaATN(inputString, lexInterp); System.out.println(types); semanticProcess(lg); diff --git a/tool/test/org/antlr/v4/test/TestATNParserPrediction.java b/tool/test/org/antlr/v4/test/TestATNParserPrediction.java index 4393a5a1b..9ef7c684b 100644 --- a/tool/test/org/antlr/v4/test/TestATNParserPrediction.java +++ b/tool/test/org/antlr/v4/test/TestATNParserPrediction.java @@ -37,6 +37,7 @@ import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.TokenStream; import org.antlr.v4.runtime.atn.*; import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.misc.IntegerList; import org.antlr.v4.tool.DOTGenerator; import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.LexerGrammar; @@ -44,8 +45,6 @@ import org.antlr.v4.tool.Rule; import org.antlr.v4.tool.interp.ParserInterpreter; import org.junit.Test; -import java.util.List; - // NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH // NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH // NOTICE: TOKENS IN LEXER, PARSER MUST BE SAME OR TOKEN TYPE MISMATCH @@ -477,7 +476,7 @@ public class TestATNParserPrediction extends BaseTest { Tool.internalOption_ShowATNConfigsInDFA = true; ATN lexatn = createATN(lg); LexerATNSimulator lexInterp = new LexerATNSimulator(lexatn); - List types = getTokenTypesViaATN(inputString, lexInterp); + IntegerList types = getTokenTypesViaATN(inputString, lexInterp); System.out.println(types); semanticProcess(lg); @@ -542,7 +541,7 @@ public class TestATNParserPrediction extends BaseTest { // System.out.println(dot.getDOT(atn.ruleToStartState.get(g.getRule("e")))); ParserATNSimulator interp = new ParserATNSimulator(atn); - List types = getTokenTypesViaATN(inputString, lexInterp); + IntegerList types = getTokenTypesViaATN(inputString, lexInterp); System.out.println(types); TokenStream input = new IntTokenStream(types); try { @@ -572,7 +571,7 @@ public class TestATNParserPrediction extends BaseTest { ParserInterpreter interp = new ParserInterpreter(g, null); for (int i=0; i types = getTokenTypesViaATN(inputString[i], lexInterp); + IntegerList types = getTokenTypesViaATN(inputString[i], lexInterp); System.out.println(types); TokenStream input = new IntTokenStream(types); try {