diff --git a/src/main/java/org/sablecc/sablecc/Grammar.java b/src/main/java/org/sablecc/sablecc/Grammar.java index ae3fbf4272f5eace042df6659f05aa20a30b66f2..720185603091c27d111acc1ba334048f1d6a829f 100644 --- a/src/main/java/org/sablecc/sablecc/Grammar.java +++ b/src/main/java/org/sablecc/sablecc/Grammar.java @@ -112,9 +112,7 @@ public final class Grammar LR0Item[] items = sets[i].items(); for(int j = 0; j < items.length; j++) { - Symbol[] lookaheads = ((SymbolSet) collection.lookaheads[i]. - get - (items[j])).getSymbols(); + Symbol[] lookaheads = collection.lookaheads[i].get(items[j]).getSymbols(); for(int k = 0; k < lookaheads.length; k++) { diff --git a/src/main/java/org/sablecc/sablecc/LR1Collection.java b/src/main/java/org/sablecc/sablecc/LR1Collection.java index 31334ee5e0bb6e6ec98a3dc46f92f3619a9c6ade..48af3515a77ead2796398fcc25c4393db3a92b33 100644 --- a/src/main/java/org/sablecc/sablecc/LR1Collection.java +++ b/src/main/java/org/sablecc/sablecc/LR1Collection.java @@ -8,14 +8,13 @@ package org.sablecc.sablecc; import java.util.Vector; -import java.util.Enumeration; import java.util.*; final class LR1Collection { final LR0Collection collection; - final TreeMap[] lookaheads; - private final TreeMap[] propagation; + final TreeMap<LR0Item, SymbolSet>[] lookaheads; + private final TreeMap<LR0Item, Vector<LR0ItemAndSetPair>>[] propagation; LR1Collection(LR0ItemSet set ) @@ -25,25 +24,25 @@ final class LR1Collection // Initialize lookaheads to nothing, propagation to nothing LR0ItemSet[] sets = collection.sets(); - lookaheads = new TreeMap[sets.length]; - propagation = new TreeMap[sets.length]; + lookaheads = (TreeMap<LR0Item, SymbolSet>[])new TreeMap<?, ?>[sets.length]; + propagation = (TreeMap<LR0Item, Vector<LR0ItemAndSetPair>>[])new TreeMap<?, ?>[sets.length]; for(int i = 0; i < sets.length; i++) { System.out.print("."); - lookaheads[i] = new TreeMap(); - propagation[i] = new TreeMap(); + lookaheads[i] = new TreeMap<>(); + propagation[i] = new TreeMap<>(); LR0Item[] items = sets[i].items(); for(int j = 0; j < items.length; j++) { lookaheads[i].put(items[j], new SymbolSet()); - propagation[i].put(items[j], new Vector(0)); + propagation[i].put(items[j], new Vector<LR0ItemAndSetPair>(0)); } } System.out.println(); - ((SymbolSet) lookaheads[0].get(set.items()[0])).setTerminal(Grammar.eof); + lookaheads[0].get(set.items()[0]).setTerminal(Grammar.eof); for(int i = 0; i < sets.length; i++) { @@ -73,17 +72,16 @@ final class LR1Collection if(destination != null) { - ((SymbolSet) lookaheads[destination.intValue()]. - get - (new LR0Item(closure[k].lr0Item.production, - closure[k].lr0Item.position + 1))). + lookaheads[destination.intValue()].get + (new LR0Item(closure[k].lr0Item.production, + closure[k].lr0Item.position + 1)). setTerminal(closure[k].terminal); - /*((SymbolSet) lookaheads[collection.GOTO(i, + /*lookaheads[collection.GOTO(i, Production.production(closure[k].lr0Item.production). rightside(closure[k].lr0Item.position)).intValue()]. get(new LR0Item(closure[k].lr0Item.production, - closure[k].lr0Item.position + 1))). + closure[k].lr0Item.position + 1)). setTerminal(closure[k].terminal);*/ } } @@ -101,13 +99,13 @@ final class LR1Collection if(destination != null) { - ((Vector) propagation[i].get(items[j])). + propagation[i].get(items[j]). addElement(new LR0ItemAndSetPair( new LR0Item(closure[k].lr0Item.production, closure[k].lr0Item.position + 1), destination.intValue())); - /*((Vector) propagation[i].get(items[j])). + /*propagation[i].get(items[j]). addElement(new LR0ItemAndSetPair( new LR0Item(closure[k].lr0Item.production, closure[k].lr0Item.position + 1), @@ -133,15 +131,11 @@ final class LR1Collection for(int j = 0; j < items.length; j++) { - for(Enumeration e = ((Vector) propagation[i].get(items[j])). - elements(); e.hasMoreElements();) + for(LR0ItemAndSetPair pair : propagation[i].get(items[j])) { - LR0ItemAndSetPair pair = (LR0ItemAndSetPair) e.nextElement(); + SymbolSet before = lookaheads[pair.set].get(pair.item).clone(); - SymbolSet before = ((SymbolSet) lookaheads[pair.set].get(pair.item)).clone(); - - ((SymbolSet) lookaheads[pair.set].get(pair.item)). - or((SymbolSet) lookaheads[i].get(items[j])); + lookaheads[pair.set].get(pair.item).or(lookaheads[i].get(items[j])); if(!before.equals(lookaheads[pair.set].get(pair.item))) {