package edu.berkeley.sbp;
-import edu.berkeley.sbp.util.*;
-import edu.berkeley.sbp.*;
import edu.berkeley.sbp.*;
+import edu.berkeley.sbp.util.*;
import edu.berkeley.sbp.Sequence.Position;
import java.io.*;
import java.util.*;
public Topology<Tok> walkAtom(Atom r) { cs = cs.union(r); return cs; }
}
- class First<Tok extends Token> extends WalkTokenSet<Tok> {
+ static class First<Tok extends Token> extends WalkTokenSet<Tok> {
public First(Topology<Tok> cs, Walk.Cache cache) { super(cs, cache); }
public Topology<Tok> sequence(Sequence seq) {
for(Position p = seq.firstp(); p!=null && !p.isLast(); p = p.next()) {
Sequence a = (Sequence)x;
Position mp = null;
for(Position pos = a.firstp(); pos != null && !pos.isLast(); pos = pos.next()) {
- if (matched) cs = cs.union(new First<Tok>(cs.empty(), c).walk(pos.element()));
+ if (matched) cs = cs.union(c.first(pos.element(), cs.empty()));
if (pos.isLast()) { matched = (matched && pos.element().possiblyEpsilon(c)); continue; }
boolean good = false;
if (e instanceof Atom) {
if (top==null) continue;
if (!(top.containsAll(((Atom)e)))) continue;
} else {
- if (c.ys.get(pos.element()).contains(e)) good = true;
+ if (c.ys.contains(pos.element(),e)) good = true;
}
if (good) {
mp = pos;
public final HashMap<Element,Boolean> possiblyEpsilon = new HashMap<Element,Boolean>();
public HashMap<Element,Boolean> eof = new HashMap<Element,Boolean>();
public HashMap<Element,Topology> follow = new HashMap<Element,Topology>();
- public HashMap<Element,HashSet<Element>> ys = new HashMap<Element,HashSet<Element>>();
+ public HashMapBag<Element,Element> ys = new HashMapBag<Element,Element>();
public HashMap<Element,Topology> atoms = new HashMap<Element,Topology>();
+ public <Tok extends Token> Topology<Tok> first(Element e, Topology<Tok> empty) {
+ return new Walk.First<Tok>(empty, this).walk(e);
+ }
}
}