diff --git a/src/main/java/org/sablecc/sablecc/CharSet.java b/src/main/java/org/sablecc/sablecc/CharSet.java index c98b5669df4e2c7dd53a48e74b5677757189aa54..c1bec22dfdab7c561666cd510289421da73ef2d7 100644 --- a/src/main/java/org/sablecc/sablecc/CharSet.java +++ b/src/main/java/org/sablecc/sablecc/CharSet.java @@ -8,27 +8,26 @@ package org.sablecc.sablecc; import java.util.*; -import java.util.Vector; public class CharSet implements Cloneable { - private final Vector<Interval> intervals = new Vector<>(0); + private final List<Interval> intervals = new ArrayList<>(); public CharSet(char c) { - intervals.addElement(new Interval(c, c)); + intervals.add(new Interval(c, c)); } public CharSet(char start, char end) { - intervals.addElement(new Interval(start, end)); + intervals.add(new Interval(start, end)); } private CharSet(Collection<Interval> intervals) { for(Interval i : intervals) { - this.intervals.addElement(i.clone()); + this.intervals.add(i.clone()); } } @@ -49,7 +48,7 @@ public class CharSet implements Cloneable { int middle = (high + low) >>> 1; - interval2 = intervals.elementAt(middle); + interval2 = intervals.get(middle); if(interval1.start <= interval2.end) { @@ -73,7 +72,7 @@ public class CharSet implements Cloneable private void remove (Interval interval) { - intervals.removeElement(interval); + intervals.remove(interval); } private void add @@ -81,16 +80,16 @@ public class CharSet implements Cloneable { for(int i = 0; i < intervals.size(); i++) { - Interval iv = intervals.elementAt(i); + Interval iv = intervals.get(i); if(iv.start > interval.start) { - intervals.insertElementAt(interval, i); + intervals.add(i, interval); return; } } - intervals.addElement(interval); + intervals.add(interval); } public CharSet union(CharSet chars) diff --git a/src/main/java/org/sablecc/sablecc/DFA.java b/src/main/java/org/sablecc/sablecc/DFA.java index 8f8afb8ff37398365b8bb600edc94d5588ec6736..7b53279ada239a18a53b18542a1dba84ae1436fe 100644 --- a/src/main/java/org/sablecc/sablecc/DFA.java +++ b/src/main/java/org/sablecc/sablecc/DFA.java @@ -7,9 +7,10 @@ package org.sablecc.sablecc; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; -import java.util.Vector; -import java.util.Hashtable; public class DFA { @@ -21,17 +22,17 @@ public class DFA } public NFA nfa; - public final Vector<DFA.State> states = new Vector<>(0); - public final Map<IntSet, Integer> finder = new Hashtable<>(1); + public final List<State> states = new ArrayList<>(); + public final Map<IntSet, Integer> finder = new HashMap<>(); private void optimize() { - Vector<Vector<DFA.Transition>> transitions = new Vector<>(0); + List<List<DFA.Transition>> transitions = new ArrayList<>(); for(int i = 0; i < states.size(); i++) { - DFA.State state = states.elementAt(i); - transitions.addElement(new Vector<DFA.Transition>(0)); + DFA.State state = states.get(i); + transitions.add(new ArrayList<DFA.Transition>()); for(int j = 0; j < state.transitions.size(); j++) { @@ -51,12 +52,12 @@ public class DFA if(max < 2) { - transitions.elementAt(i).addElement(state.transitions.elementAt(j)); + transitions.get(i).add(state.transitions.get(j)); } else { - DFA.Transition transition1 = state.transitions.elementAt(j); - DFA.Transition transition2 = state.transitions.elementAt(j + max - 1); + DFA.Transition transition1 = state.transitions.get(j); + DFA.Transition transition2 = state.transitions.get(j + max - 1); DFA.Transition transition = new DFA.Transition( @@ -65,7 +66,7 @@ public class DFA transition2.interval().end), -2 - st); - transitions.elementAt(i).addElement(transition); + transitions.get(i).add(transition); j += max - 1; } } @@ -73,23 +74,23 @@ public class DFA for(int i = 0; i < states.size(); i++) { - DFA.State state = states.elementAt(i); - state.transitions = transitions.elementAt(i); + DFA.State state = states.get(i); + state.transitions = transitions.get(i); } } private int match(int st1, int tr, int st2) { - DFA.State state1 = states.elementAt(st1); - DFA.State state2 = states.elementAt(st2); + DFA.State state1 = states.get(st1); + DFA.State state2 = states.get(st2); - DFA.Transition first = state1.transitions.elementAt(tr); + DFA.Transition first = state1.transitions.get(tr); int j = -1; for(int i = 0; i < state2.transitions.size(); i++) { - DFA.Transition transition = state2.transitions.elementAt(i); + DFA.Transition transition = state2.transitions.get(i); if(transition.match(first)) { @@ -109,9 +110,9 @@ public class DFA while((i < state1.transitions.size()) && (j < state2.transitions.size())) { - DFA.Transition transition1 = state1.transitions.elementAt(i); + DFA.Transition transition1 = state1.transitions.get(i); - DFA.Transition transition2 = state2.transitions.elementAt(j); + DFA.Transition transition2 = state2.transitions.get(j); if(!transition1.match(transition2)) { @@ -134,7 +135,7 @@ public class DFA initial.or(eclosure(0)); State state = new State(initial); - states.addElement(state); + states.add(state); finder.put(state.nfaStates, 0); int i = -1; @@ -142,7 +143,7 @@ public class DFA { System.out.print("."); - state = states.elementAt(i); + state = states.get(i); CharSet.Interval interval = new CharSet.Interval((char) 0, (char) 0xffff); @@ -215,16 +216,16 @@ public class DFA if(dest != null) { - state.transitions.addElement( + state.transitions.add( new Transition(interval.clone(), dest.intValue())); } else { State s = new State(destination); - states.addElement(s); + states.add(s); finder.put(s.nfaStates, states.size() - 1); - state.transitions.addElement( + state.transitions.add( new Transition(interval.clone(), states.size() - 1)); } } @@ -315,8 +316,7 @@ public class DFA for(int i = 0; i < states.size(); i++) { - result.append(i + ": " + states.elementAt(i) + - System.getProperty("line.separator")); + result.append(i + ": " + states.get(i) + System.getProperty("line.separator")); } return result.toString(); @@ -330,7 +330,7 @@ public class DFA } public IntSet nfaStates = new IntSet(); - public Vector<Transition> transitions = new Vector<>(0); + public List<Transition> transitions = new ArrayList<>(); public int accept; @Override diff --git a/src/main/java/org/sablecc/sablecc/GenLexer.java b/src/main/java/org/sablecc/sablecc/GenLexer.java index e3f4963ccb66edfd66e7d3e1b5c324165d169ec1..4f093a7e5a88f30daa4cf29e5266618bfb1bf88f 100644 --- a/src/main/java/org/sablecc/sablecc/GenLexer.java +++ b/src/main/java/org/sablecc/sablecc/GenLexer.java @@ -11,8 +11,6 @@ import java.util.*; import org.sablecc.sablecc.analysis.*; import org.sablecc.sablecc.node.*; import java.io.*; -import java.util.Vector; -import java.util.Enumeration; public class GenLexer extends AnalysisAdapter { @@ -194,11 +192,11 @@ public class GenLexer extends AnalysisAdapter DFA dfa = acceptStatesArray[accSt].dfa; file.write(" { // " + acceptStatesArray[accSt].stateName + System.getProperty("line.separator")); - Vector<Vector<int[]>> outerArray = new Vector<>(); + List<List<int[]>> outerArray = new ArrayList<>(); for(DFA.State state : dfa.states) { - Vector<int[]> innerArray = new Vector<>(); + List<int[]> innerArray = new ArrayList<>(); file.write(" {"); @@ -208,7 +206,7 @@ public class GenLexer extends AnalysisAdapter ((int) transition.interval().end) + ", " + transition.destination + "}, "); - innerArray.addElement(new int[] { + innerArray.add(new int[] { ((int) transition.interval().start), ((int) transition.interval().end), transition.destination}); @@ -216,12 +214,12 @@ public class GenLexer extends AnalysisAdapter file.write("}," + System.getProperty("line.separator")); - outerArray.addElement(innerArray); + outerArray.add(innerArray); } file.write(" }" + System.getProperty("line.separator")); out.writeInt(outerArray.size()); - for(Vector<int[]> innerArray : outerArray) + for(List<int[]> innerArray : outerArray) { out.writeInt(innerArray.size()); for(int[] array : innerArray) @@ -238,12 +236,12 @@ public class GenLexer extends AnalysisAdapter final int stateNumber = acceptStatesArray.length; - Vector<Vector<Integer>> outerArray = new Vector<>(); + List<List<Integer>> outerArray = new ArrayList<>(); for(int i = 0; i < stateNumber; i++) { DFA dfa = acceptStatesArray[i].dfa; - Vector<Integer> innerArray = new Vector<>(); + List<Integer> innerArray = new ArrayList<>(); file.write(" // " + acceptStatesArray[i].stateName + System.getProperty("line.separator")); file.write(" {"); @@ -251,16 +249,16 @@ public class GenLexer extends AnalysisAdapter for(DFA.State state : dfa.states) { file.write(state.accept + ", "); - innerArray.addElement(state.accept); + innerArray.add(state.accept); } file.write("}," + System.getProperty("line.separator")); - outerArray.addElement(innerArray); + outerArray.add(innerArray); } out.writeInt(outerArray.size()); - for(Vector<Integer> innerArray : outerArray) + for(List<Integer> innerArray : outerArray) { out.writeInt(innerArray.size()); for(int i : innerArray) diff --git a/src/main/java/org/sablecc/sablecc/GenParser.java b/src/main/java/org/sablecc/sablecc/GenParser.java index 7be893db50b5ac2a93bab94467130ae42678b146..44fbe339b5b6dc80d5e567d5e21d359644082d33 100644 --- a/src/main/java/org/sablecc/sablecc/GenParser.java +++ b/src/main/java/org/sablecc/sablecc/GenParser.java @@ -11,9 +11,6 @@ import java.util.*; import org.sablecc.sablecc.analysis.*; import org.sablecc.sablecc.node.*; import java.io.*; -import org.sablecc.sablecc.Grammar; -import java.util.Vector; -import java.util.Enumeration; /* * GenParser @@ -455,11 +452,11 @@ public class GenParser extends DepthFirstAdapter new FileOutputStream( new File(pkgDir, "parser.dat")))); - Vector<Vector<int[]>> outerArray = new Vector<>(); + List<List<int[]>> outerArray = new ArrayList<>(); //Generating of paring tables for(int i = 0; i < Grammar.action_.length; i++) { - Vector<int[]> innerArray = new Vector<>(); + List<int[]> innerArray = new ArrayList<>(); String mostFrequentAction = "ERROR"; int mostFrequentDestination = i; @@ -490,7 +487,7 @@ public class GenParser extends DepthFirstAdapter table.append("{" + -1 + ", " + mostFrequentAction + ", " + mostFrequentDestination + "}, "); - innerArray.addElement( + innerArray.add( new int[] {-1, mostFrequentAction.equals("ERROR") ? 3 : 1, mostFrequentDestination}); @@ -503,31 +500,31 @@ public class GenParser extends DepthFirstAdapter { case 0: table.append("{" + j + ", SHIFT, " + Grammar.action_[i][j][1] + "}, "); - innerArray.addElement(new int[] {j, 0, Grammar.action_[i][j][1]}); + innerArray.add(new int[] {j, 0, Grammar.action_[i][j][1]}); break; case 1: if(Grammar.action_[i][j][1] != mostFrequentDestination) { table.append("{" + j + ", REDUCE, " + Grammar.action_[i][j][1] + "}, "); - innerArray.addElement(new int[] {j, 1, Grammar.action_[i][j][1]}); + innerArray.add(new int[] {j, 1, Grammar.action_[i][j][1]}); } break; case 2: table.append("{" + j + ", ACCEPT, -1}, "); - innerArray.addElement(new int[] {j, 2, -1}); + innerArray.add(new int[] {j, 2, -1}); break; } } } table.append("}," + System.getProperty("line.separator")); - outerArray.addElement(innerArray); + outerArray.add(innerArray); } file.write("" + table); out.writeInt(outerArray.size()); - for(Vector<int[]> innerArray : outerArray) + for(List<int[]> innerArray : outerArray) { out.writeInt(innerArray.size()); for(int[] array : innerArray) @@ -544,11 +541,11 @@ public class GenParser extends DepthFirstAdapter macros.apply(file, "ParserGotoHeader"); table = new StringBuffer(); - outerArray = new Vector<>(); + outerArray = new ArrayList<>(); for(int j = 0; j < nonterminals.length - 1; j++) { - Vector<int[]> innerArray = new Vector<>(); + List<int[]> innerArray = new ArrayList<>(); int mostFrequent = -1; int frequence = 0; @@ -573,7 +570,7 @@ public class GenParser extends DepthFirstAdapter table.append(" {"); table.append("{" + (-1) + ", " + mostFrequent + "}, "); - innerArray.addElement(new int[] {-1, mostFrequent}); + innerArray.add(new int[] {-1, mostFrequent}); for(int i = 0; i < Grammar.goto_.length; i++) { @@ -581,19 +578,19 @@ public class GenParser extends DepthFirstAdapter (Grammar.goto_[i][j] != mostFrequent)) { table.append("{" + i + ", " + Grammar.goto_[i][j] + "}, "); - innerArray.addElement(new int[] {i, Grammar.goto_[i][j]}); + innerArray.add(new int[] {i, Grammar.goto_[i][j]}); } } table.append("}," + System.getProperty("line.separator")); - outerArray.addElement(innerArray); + outerArray.add(innerArray); } file.write("" + table); out.writeInt(outerArray.size()); - for(Vector<int[]> innerArray : outerArray) + for(List<int[]> innerArray : outerArray) { out.writeInt(innerArray.size()); for(int[] array : innerArray) @@ -615,8 +612,8 @@ public class GenParser extends DepthFirstAdapter Map<String, Integer> errorIndex = new TreeMap<>(); - Vector<String> outerArray2 = new Vector<>(); - Vector<Integer> indexArray = new Vector<>(); + List<String> outerArray2 = new ArrayList<>(); + List<Integer> indexArray = new ArrayList<>(); index.append(" "); for(int i = 0; i < Grammar.action_.length; i++) @@ -645,14 +642,14 @@ public class GenParser extends DepthFirstAdapter if(errorIndex.containsKey(s.toString())) { index.append(errorIndex.get(s.toString()) + ", "); - indexArray.addElement(errorIndex.get(s.toString())); + indexArray.add(errorIndex.get(s.toString())); } else { table.append(" \"" + s + "\"," + System.getProperty("line.separator")); - outerArray2.addElement(s.toString()); + outerArray2.add(s.toString()); errorIndex.put(s.toString(), nextIndex); - indexArray.addElement(nextIndex); + indexArray.add(nextIndex); index.append(nextIndex++ + ", "); } } diff --git a/src/main/java/org/sablecc/sablecc/GenerateAlternativeCodeForParser.java b/src/main/java/org/sablecc/sablecc/GenerateAlternativeCodeForParser.java index 0774d36128609484769986755fd33805d00cd293..210d951b2408d067ebb122bc35b2a3e3dcca2de5 100644 --- a/src/main/java/org/sablecc/sablecc/GenerateAlternativeCodeForParser.java +++ b/src/main/java/org/sablecc/sablecc/GenerateAlternativeCodeForParser.java @@ -11,9 +11,6 @@ import java.util.*; import org.sablecc.sablecc.analysis.*; import org.sablecc.sablecc.node.*; import java.io.*; -import org.sablecc.sablecc.Grammar; -import java.util.Vector; -import java.util.Enumeration; public class GenerateAlternativeCodeForParser extends DepthFirstAdapter { diff --git a/src/main/java/org/sablecc/sablecc/Grammar.java b/src/main/java/org/sablecc/sablecc/Grammar.java index ad8b4069981ef6de56f20819e9226bf08f7fa048..ea93cde68d9430b2cf4afdf2882c7b5d9c4778a2 100644 --- a/src/main/java/org/sablecc/sablecc/Grammar.java +++ b/src/main/java/org/sablecc/sablecc/Grammar.java @@ -7,7 +7,6 @@ package org.sablecc.sablecc; -import java.util.Vector; import java.util.*; public final class Grammar @@ -162,7 +161,7 @@ public final class Grammar case 0: conflictMessage.append( "\n\nshift/reduce conflict in state [stack:" + - collection.collection.names.elementAt(i) + "*] on " + + collection.collection.names.get(i) + "*] on " + terminals[j] + " in " + state.toString(terminals[j])); /* nothing else to do */ @@ -171,7 +170,7 @@ public final class Grammar case 1: conflictMessage.append( "\n\nreduce/reduce conflict in state [stack:" + - collection.collection.names.elementAt(i) + "*] on " + + collection.collection.names.get(i) + "*] on " + terminals[j] + " in " + state.toString(terminals[j])); listOfConflictualProds.add(Symbol.symbol(Production.production(action[1]).leftside, false).toString()); @@ -180,7 +179,7 @@ public final class Grammar case 2: conflictMessage.append( "\n\nreduce/accept conflict in state [stack:" + - collection.collection.names.elementAt(i) + "*] on " + + collection.collection.names.get(i) + "*] on " + terminals[j] + " in " + state.toString(terminals[j])); listOfConflictualProds.add(Symbol.symbol(Production.production(action[1]).leftside, false).toString()); @@ -211,7 +210,7 @@ public final class Grammar case 0: conflictMessage.append( "shift/accept conflict in state [stack:" + - collection.collection.names.elementAt(i) + "*] on " + + collection.collection.names.get(i) + "*] on " + terminals[j] + " in " + state); /* nothing else to do */ @@ -220,7 +219,7 @@ public final class Grammar case 1: conflictMessage.append( "reduce/accept conflict in state [stack:" + - collection.collection.names.elementAt(i) + "*] on " + + collection.collection.names.get(i) + "*] on " + terminals[j] + " in " + state); listOfConflictualProds.add(Symbol.symbol(Production.production(action[1]).leftside, false).toString()); @@ -569,17 +568,16 @@ public final class Grammar if(!symbol.terminal) { - Vector<Symbol> tailVector = new Vector<>(0); + List<Symbol> tailVector = new ArrayList<>(0); for(int k = items[i].lr0Item.position + 1; k < rightside.length; k++) { - tailVector.addElement(rightside[k]); + tailVector.add(rightside[k]); } - tailVector.addElement(Symbol.symbol(items[i].terminal, true)); + tailVector.add(Symbol.symbol(items[i].terminal, true)); - Symbol[] tail = new Symbol[tailVector.size()]; - tailVector.copyInto(tail); + Symbol[] tail = tailVector.toArray(new Symbol[0]); Symbol[] symbols = FIRST(tail).getSymbols(); diff --git a/src/main/java/org/sablecc/sablecc/LR0Collection.java b/src/main/java/org/sablecc/sablecc/LR0Collection.java index 69ce858cd4352a7cebc83fac524a8c0d80545085..c2412239e16711b059e1b3263d348cde1de04e0d 100644 --- a/src/main/java/org/sablecc/sablecc/LR0Collection.java +++ b/src/main/java/org/sablecc/sablecc/LR0Collection.java @@ -8,14 +8,13 @@ package org.sablecc.sablecc; import java.util.*; -import java.util.Vector; final class LR0Collection { - private final Vector<LR0ItemSet> sets = new Vector<>(0); - private final TreeMap<LR0ItemSet, Integer> setIndices = new TreeMap<>(); - private final Vector<TreeMap<Symbol, Integer>> GOTO = new Vector<>(0); - final Vector<String> names = new Vector<>(0); + private final List<LR0ItemSet> sets = new ArrayList<>(0); + private final Map<LR0ItemSet, Integer> setIndices = new TreeMap<>(); + private final List<Map<Symbol, Integer>> GOTO = new ArrayList<>(0); + final List<String> names = new ArrayList<>(0); LR0Collection(LR0ItemSet set ) @@ -52,16 +51,15 @@ final class LR0Collection setIndices.put(set , result); - sets.addElement(set - ); - GOTO.addElement(new TreeMap<Symbol, Integer>()); + sets.add(set); + GOTO.add(new TreeMap<Symbol, Integer>()); if(from == -1) { - names.addElement(" "); + names.add(" "); } else { - names.addElement(names.elementAt(from) + "" + symbol + " "); + names.add(names.get(from) + "" + symbol + " "); } } @@ -79,7 +77,7 @@ final class LR0Collection { if(!to.equals(empty)) { - GOTO.elementAt(from).put(symbol, add(to, from, symbol)); + GOTO.get(from).put(symbol, add(to, from, symbol)); } } @@ -93,21 +91,18 @@ final class LR0Collection private LR0ItemSet set (int index) { - return sets.elementAt(index); + return sets.get(index); } LR0ItemSet[] sets() { - LR0ItemSet[] result = new LR0ItemSet[sets.size()]; - sets.copyInto(result); - - return result; + return sets.toArray(new LR0ItemSet[0]); } Integer GOTO(int set , Symbol symbol) { - return GOTO.elementAt(set).get(symbol); + return GOTO.get(set).get(symbol); } @Override diff --git a/src/main/java/org/sablecc/sablecc/LR0ItemSet.java b/src/main/java/org/sablecc/sablecc/LR0ItemSet.java index a58b1a91fed189fd6fdf4d9787d758fcf3c23421..beb9bdc6e7b5ea10c276173c796479d6b7e66149 100644 --- a/src/main/java/org/sablecc/sablecc/LR0ItemSet.java +++ b/src/main/java/org/sablecc/sablecc/LR0ItemSet.java @@ -11,7 +11,7 @@ import java.util.*; final class LR0ItemSet implements Cloneable, Comparable<LR0ItemSet> { - private final TreeMap<LR0Item, LR0Item> items; + private final Map<LR0Item, LR0Item> items; private int hashCode; LR0ItemSet() diff --git a/src/main/java/org/sablecc/sablecc/LR1Collection.java b/src/main/java/org/sablecc/sablecc/LR1Collection.java index 1264fa2db653cafa0f11dce60879880f3200826b..a40eb3f4eb970cb62c0dc92e60e6797c0967a9c5 100644 --- a/src/main/java/org/sablecc/sablecc/LR1Collection.java +++ b/src/main/java/org/sablecc/sablecc/LR1Collection.java @@ -7,14 +7,13 @@ package org.sablecc.sablecc; -import java.util.Vector; import java.util.*; final class LR1Collection { final LR0Collection collection; - final TreeMap<LR0Item, SymbolSet>[] lookaheads; - private final TreeMap<LR0Item, Vector<LR0ItemAndSetPair>>[] propagation; + final Map<LR0Item, SymbolSet>[] lookaheads; + private final Map<LR0Item, List<LR0ItemAndSetPair>>[] propagation; LR1Collection(LR0ItemSet set ) @@ -25,10 +24,10 @@ final class LR1Collection // Initialize lookaheads to nothing, propagation to nothing LR0ItemSet[] sets = collection.sets(); @SuppressWarnings("unchecked") - final TreeMap<LR0Item, SymbolSet>[] lookaheadsTemp = (TreeMap<LR0Item, SymbolSet>[])new TreeMap<?, ?>[sets.length]; + final Map<LR0Item, SymbolSet>[] lookaheadsTemp = (Map<LR0Item, SymbolSet>[])new Map<?, ?>[sets.length]; lookaheads = lookaheadsTemp; @SuppressWarnings("unchecked") - final TreeMap<LR0Item, Vector<LR0ItemAndSetPair>>[] propagationTemp = (TreeMap<LR0Item, Vector<LR0ItemAndSetPair>>[])new TreeMap<?, ?>[sets.length]; + final Map<LR0Item, List<LR0ItemAndSetPair>>[] propagationTemp = (Map<LR0Item, List<LR0ItemAndSetPair>>[])new Map<?, ?>[sets.length]; propagation = propagationTemp; for(int i = 0; i < sets.length; i++) @@ -41,7 +40,7 @@ final class LR1Collection for(int j = 0; j < items.length; j++) { lookaheads[i].put(items[j], new SymbolSet()); - propagation[i].put(items[j], new Vector<LR0ItemAndSetPair>(0)); + propagation[i].put(items[j], new ArrayList<LR0ItemAndSetPair>()); } } System.out.println(); @@ -103,14 +102,12 @@ final class LR1Collection if(destination != null) { - propagation[i].get(items[j]). - addElement(new LR0ItemAndSetPair( + propagation[i].get(items[j]).add(new LR0ItemAndSetPair( new LR0Item(closure[k].lr0Item.production, closure[k].lr0Item.position + 1), destination.intValue())); - /*propagation[i].get(items[j]). - addElement(new LR0ItemAndSetPair( + /*propagation[i].get(items[j]).add(new LR0ItemAndSetPair( new LR0Item(closure[k].lr0Item.production, closure[k].lr0Item.position + 1), collection.GOTO(i, diff --git a/src/main/java/org/sablecc/sablecc/LR1ItemSet.java b/src/main/java/org/sablecc/sablecc/LR1ItemSet.java index ca9596349283c99314ba1fc3fb253ab0f11f781d..c45a7516fa77975973abc8b1da63bb45aeeb24ee 100644 --- a/src/main/java/org/sablecc/sablecc/LR1ItemSet.java +++ b/src/main/java/org/sablecc/sablecc/LR1ItemSet.java @@ -11,7 +11,7 @@ import java.util.*; final class LR1ItemSet implements Cloneable, Comparable<LR1ItemSet> { - private final TreeMap<LR1Item, LR1Item> items; + private final Map<LR1Item, LR1Item> items; private int hashCode = 0; LR1ItemSet() diff --git a/src/main/java/org/sablecc/sablecc/Production.java b/src/main/java/org/sablecc/sablecc/Production.java index 808c8f4b6f186ced802d984b5eeddddbafd1188b..50d90179e81edc00848e4342fc885900b08c9731 100644 --- a/src/main/java/org/sablecc/sablecc/Production.java +++ b/src/main/java/org/sablecc/sablecc/Production.java @@ -8,7 +8,6 @@ package org.sablecc.sablecc; import java.util.*; -import java.util.Vector; final class Production { @@ -16,15 +15,15 @@ final class Production final int index; final String name; - private final Vector<Symbol> rightside = new Vector<>(); - private static final Vector<Production> productions = new Vector<>(0); - private static TreeMap<Integer, Production[]> alternatives_ = new TreeMap<>(); + private final List<Symbol> rightside = new ArrayList<>(); + private static final List<Production> productions = new ArrayList<>(); + private static Map<Integer, Production[]> alternatives_ = new TreeMap<>(); private static boolean modified_ = true; private static Production[] productions_; public static void reinit() { - productions.removeAllElements(); + productions.clear(); alternatives_ = new TreeMap<>(); productions_ = null; modified_ = true; @@ -33,8 +32,7 @@ final class Production private static void computeArray_() { - productions_ = new Production[productions.size()]; - productions.copyInto(productions_); + productions_ = productions.toArray(new Production[0]); modified_ = false; } @@ -43,14 +41,13 @@ final class Production private void computeArray() { - rightside_ = new Symbol[rightside.size()]; - rightside.copyInto(rightside_); + rightside_ = rightside.toArray(new Symbol[0]); modified = false; } Production(int leftside, String name) { - productions.addElement(this); + productions.add(this); this.name = name; this.leftside = leftside; @@ -70,19 +67,19 @@ final class Production void addSymbol(Symbol s) { - rightside.addElement(s); + rightside.add(s); modified = true; modified_ = true; } Symbol rightside(int index) { - return rightside.elementAt(index); + return rightside.get(index); } static Production production(int index) { - return productions.elementAt(index); + return productions.get(index); } static Production[] alternatives(int nonterminal) @@ -96,18 +93,17 @@ final class Production if(result == null) { - Vector<Production> alternatives = new Vector<>(0); + List<Production> alternatives = new ArrayList<>(0); for(Production production : productions) { if(production.leftside == nonterminal) { - alternatives.addElement(production); + alternatives.add(production); } } - result = new Production[alternatives.size()]; - alternatives.copyInto(result); + result = alternatives.toArray(new Production[0]); alternatives_.put(nonterminal, result); } diff --git a/src/main/java/org/sablecc/sablecc/SableCC.java b/src/main/java/org/sablecc/sablecc/SableCC.java index 3df008e7080c2cd4d5ce0359d857db95c584dac9..2936c014b000dd9efd8e708d228c54a9a9cdc851 100644 --- a/src/main/java/org/sablecc/sablecc/SableCC.java +++ b/src/main/java/org/sablecc/sablecc/SableCC.java @@ -14,7 +14,8 @@ import org.sablecc.sablecc.node.*; import org.sablecc.sablecc.analysis.*; import org.sablecc.sablecc.lexer.*; import org.sablecc.sablecc.parser.*; -import java.util.Vector; + +import java.util.List; public class SableCC { private static boolean processInlining = true; @@ -55,7 +56,7 @@ public class SableCC { public static void main(String[] arguments) { String d_option = null; - Vector<String> filename = new Vector<>(); + List<String> filename = new ArrayList<>(); if (arguments.length == 0) { displayCopyright(); @@ -102,7 +103,7 @@ public class SableCC { else if (arguments[arg].equals(OPT_PRETTY_PRINT)) { prettyPrinting = true; } else { - filename.addElement(arguments[arg]); + filename.add(arguments[arg]); } arg++; } @@ -115,7 +116,7 @@ public class SableCC { try { for (int i = 0; i < filename.size(); i++) { - processGrammar(filename.elementAt(i), d_option); + processGrammar(filename.get(i), d_option); } } catch (IOException | LexerException | ParserException | RuntimeException e) { e.printStackTrace(); diff --git a/src/main/java/org/sablecc/sablecc/Symbol.java b/src/main/java/org/sablecc/sablecc/Symbol.java index 916c8ccc223c45fec96f7a9c508fc94bf6d8a241..7a7947ca197a070d437e1879aa22d419fe31682b 100644 --- a/src/main/java/org/sablecc/sablecc/Symbol.java +++ b/src/main/java/org/sablecc/sablecc/Symbol.java @@ -8,13 +8,12 @@ package org.sablecc.sablecc; import java.util.*; -import java.util.Vector; final class Symbol implements Comparable<Symbol> { - private static Vector<Symbol> terminals; - private static Vector<Symbol> nonterminals; - private static TreeMap<String, Symbol> names; + private static List<Symbol> terminals; + private static List<Symbol> nonterminals; + private static Map<String, Symbol> names; private static boolean modified_ = true; private static Symbol[] symbols_; @@ -39,12 +38,12 @@ final class Symbol implements Comparable<Symbol> if(terminal) { - terminals.addElement(this); + terminals.add(this); this.index = terminals.indexOf(this); } else { - nonterminals.addElement(this); + nonterminals.add(this); this.index = nonterminals.indexOf(this); } @@ -57,8 +56,8 @@ final class Symbol implements Comparable<Symbol> public static void reinit() { - terminals = new Vector<>(); - nonterminals = new Vector<>(); + terminals = new ArrayList<>(); + nonterminals = new ArrayList<>(); names = new TreeMap<>(); modified_ = true; symbols_ = null; @@ -75,22 +74,20 @@ final class Symbol implements Comparable<Symbol> { if(terminal) { - return terminals.elementAt(index); + return terminals.get(index); } else { - return nonterminals.elementAt(index); + return nonterminals.get(index); } } private static void computeArrays() { symbols_ = new Symbol[terminals.size() + nonterminals.size()]; - terminals_ = new Symbol[terminals.size()]; - nonterminals_ = new Symbol[nonterminals.size()]; + terminals_ = terminals.toArray(new Symbol[0]); + nonterminals_ = nonterminals.toArray(new Symbol[0]); - terminals.copyInto(terminals_); - nonterminals.copyInto(nonterminals_); System.arraycopy(terminals_, 0, symbols_, 0, terminals_.length); System.arraycopy(nonterminals_, 0, symbols_, terminals_.length, nonterminals_.length); diff --git a/src/main/java/org/sablecc/sablecc/SymbolSet.java b/src/main/java/org/sablecc/sablecc/SymbolSet.java index 0f324940678500a913305c0c2624a6210738776f..e1371ebdb6cb9e5b9fffcea9c72d54c99ad2fc54 100644 --- a/src/main/java/org/sablecc/sablecc/SymbolSet.java +++ b/src/main/java/org/sablecc/sablecc/SymbolSet.java @@ -8,7 +8,6 @@ package org.sablecc.sablecc; import java.util.*; -import java.util.Vector; final class SymbolSet implements Cloneable { @@ -21,22 +20,21 @@ final class SymbolSet implements Cloneable private void computeArray() { - Vector<Symbol> symbols = new Vector<>(0); + List<Symbol> symbols = new ArrayList<>(); int[] elements = terminals.elements(); for(int i = 0; i < elements.length; i++) { - symbols.addElement(Symbol.symbol(elements[i], true)); + symbols.add(Symbol.symbol(elements[i], true)); } elements = nonterminals.elements(); for(int i = 0; i < elements.length; i++) { - symbols.addElement(Symbol.symbol(elements[i], false)); + symbols.add(Symbol.symbol(elements[i], false)); } - this.symbols = new Symbol[symbols.size()]; - symbols.copyInto(this.symbols); + this.symbols = symbols.toArray(new Symbol[0]); modified = false; }