Skip to content
Snippets Groups Projects
Commit 75b83131 authored by dgelessus's avatar dgelessus
Browse files

Use generics in LR1Collection

parent c394250a
No related branches found
No related tags found
No related merge requests found
...@@ -112,9 +112,7 @@ public final class Grammar ...@@ -112,9 +112,7 @@ public final class Grammar
LR0Item[] items = sets[i].items(); LR0Item[] items = sets[i].items();
for(int j = 0; j < items.length; j++) for(int j = 0; j < items.length; j++)
{ {
Symbol[] lookaheads = ((SymbolSet) collection.lookaheads[i]. Symbol[] lookaheads = collection.lookaheads[i].get(items[j]).getSymbols();
get
(items[j])).getSymbols();
for(int k = 0; k < lookaheads.length; k++) for(int k = 0; k < lookaheads.length; k++)
{ {
......
...@@ -8,14 +8,13 @@ ...@@ -8,14 +8,13 @@
package org.sablecc.sablecc; package org.sablecc.sablecc;
import java.util.Vector; import java.util.Vector;
import java.util.Enumeration;
import java.util.*; import java.util.*;
final class LR1Collection final class LR1Collection
{ {
final LR0Collection collection; final LR0Collection collection;
final TreeMap[] lookaheads; final TreeMap<LR0Item, SymbolSet>[] lookaheads;
private final TreeMap[] propagation; private final TreeMap<LR0Item, Vector<LR0ItemAndSetPair>>[] propagation;
LR1Collection(LR0ItemSet set LR1Collection(LR0ItemSet set
) )
...@@ -25,25 +24,25 @@ final class LR1Collection ...@@ -25,25 +24,25 @@ final class LR1Collection
// Initialize lookaheads to nothing, propagation to nothing // Initialize lookaheads to nothing, propagation to nothing
LR0ItemSet[] sets = collection.sets(); LR0ItemSet[] sets = collection.sets();
lookaheads = new TreeMap[sets.length]; lookaheads = (TreeMap<LR0Item, SymbolSet>[])new TreeMap<?, ?>[sets.length];
propagation = new TreeMap[sets.length]; propagation = (TreeMap<LR0Item, Vector<LR0ItemAndSetPair>>[])new TreeMap<?, ?>[sets.length];
for(int i = 0; i < sets.length; i++) for(int i = 0; i < sets.length; i++)
{ {
System.out.print("."); System.out.print(".");
lookaheads[i] = new TreeMap(); lookaheads[i] = new TreeMap<>();
propagation[i] = new TreeMap(); propagation[i] = new TreeMap<>();
LR0Item[] items = sets[i].items(); LR0Item[] items = sets[i].items();
for(int j = 0; j < items.length; j++) for(int j = 0; j < items.length; j++)
{ {
lookaheads[i].put(items[j], new SymbolSet()); 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(); 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++) for(int i = 0; i < sets.length; i++)
{ {
...@@ -73,17 +72,16 @@ final class LR1Collection ...@@ -73,17 +72,16 @@ final class LR1Collection
if(destination != null) if(destination != null)
{ {
((SymbolSet) lookaheads[destination.intValue()]. lookaheads[destination.intValue()].get
get
(new LR0Item(closure[k].lr0Item.production, (new LR0Item(closure[k].lr0Item.production,
closure[k].lr0Item.position + 1))). closure[k].lr0Item.position + 1)).
setTerminal(closure[k].terminal); setTerminal(closure[k].terminal);
/*((SymbolSet) lookaheads[collection.GOTO(i, /*lookaheads[collection.GOTO(i,
Production.production(closure[k].lr0Item.production). Production.production(closure[k].lr0Item.production).
rightside(closure[k].lr0Item.position)).intValue()]. rightside(closure[k].lr0Item.position)).intValue()].
get(new LR0Item(closure[k].lr0Item.production, get(new LR0Item(closure[k].lr0Item.production,
closure[k].lr0Item.position + 1))). closure[k].lr0Item.position + 1)).
setTerminal(closure[k].terminal);*/ setTerminal(closure[k].terminal);*/
} }
} }
...@@ -101,13 +99,13 @@ final class LR1Collection ...@@ -101,13 +99,13 @@ final class LR1Collection
if(destination != null) if(destination != null)
{ {
((Vector) propagation[i].get(items[j])). propagation[i].get(items[j]).
addElement(new LR0ItemAndSetPair( addElement(new LR0ItemAndSetPair(
new LR0Item(closure[k].lr0Item.production, new LR0Item(closure[k].lr0Item.production,
closure[k].lr0Item.position + 1), closure[k].lr0Item.position + 1),
destination.intValue())); destination.intValue()));
/*((Vector) propagation[i].get(items[j])). /*propagation[i].get(items[j]).
addElement(new LR0ItemAndSetPair( addElement(new LR0ItemAndSetPair(
new LR0Item(closure[k].lr0Item.production, new LR0Item(closure[k].lr0Item.production,
closure[k].lr0Item.position + 1), closure[k].lr0Item.position + 1),
...@@ -133,15 +131,11 @@ final class LR1Collection ...@@ -133,15 +131,11 @@ final class LR1Collection
for(int j = 0; j < items.length; j++) for(int j = 0; j < items.length; j++)
{ {
for(Enumeration e = ((Vector) propagation[i].get(items[j])). for(LR0ItemAndSetPair pair : propagation[i].get(items[j]))
elements(); e.hasMoreElements();)
{ {
LR0ItemAndSetPair pair = (LR0ItemAndSetPair) e.nextElement(); SymbolSet before = lookaheads[pair.set].get(pair.item).clone();
SymbolSet before = ((SymbolSet) lookaheads[pair.set].get(pair.item)).clone(); lookaheads[pair.set].get(pair.item).or(lookaheads[i].get(items[j]));
((SymbolSet) lookaheads[pair.set].get(pair.item)).
or((SymbolSet) lookaheads[i].get(items[j]));
if(!before.equals(lookaheads[pair.set].get(pair.item))) if(!before.equals(lookaheads[pair.set].get(pair.item)))
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment