public <S, P, D extends Pda<S, P>> D filter(Pda<S, P> pda, Predicate<S> filter, PdaFactory<D, S, P, ? super S> fact) { D result = fact.create(pda.getStart(), pda.getStop()); Map<S, S> orig2copy = Maps.newLinkedHashMap(); S start = pda.getStart(); if (orig != start && orig != stop && filter.apply(orig)) { if (pda.getPop(orig) != null) { orig2copy.put(orig, fact.createPop(result, orig)); } else if (pda.getPush(orig) != null) { orig2copy.put(orig, fact.createPush(result, orig)); } else { orig2copy.put(orig, fact.createState(result, orig)); fact.setFollowers(result, copy, folowers);
protected <S, P, T, D extends Pda<S, P>> S clone(S state, Pda<S, P> src, D target, Function<S, T> tokens, PdaFactory<D, S, P, T> fact, Identity<S> identity) { if (state == src.getStart()) return target.getStart(); if (state == src.getStop()) return target.getStop(); P push = src.getPush(state); if (push != null) return identity.get(fact.createPush(target, tokens.apply(state))); P pop = src.getPop(state); if (pop != null) return identity.get(fact.createPop(target, tokens.apply(state))); return identity.get(fact.createState(target, tokens.apply(state))); }
S s = stops.get(c); if (s == null) { s = fact.createPop(pda, tokens.apply(c)); stops.put(c, s); create(cfg, pda, s, c, ff.getFollowers(c), ff, tokens, fact, states, stops, callers); S s = states.get(fol); if (s == null) { s = fact.createPush(pda, tokens.apply(fol)); states.put(fol, s); create(cfg, pda, s, e, ff.getStarts(e), ff, tokens, fact, states, stops, callers); S s = states.get(fol); if (s == null) { s = fact.createState(pda, tokens.apply(fol)); states.put(fol, s); create(cfg, pda, s, fol, ff.getFollowers(fol), ff, tokens, fact, states, stops, callers); fact.setFollowers(pda, state, followerStates);
public <S, P, E, T1, T2, D extends Pda<S, P>> D create(Cfg<E, T1> cfg, FollowerFunction<E> ff, Function<E, T2> element2token, PdaFactory<D, S, P, ? super T2> fact) { D pda = fact.create(null, null); Map<E, S> states = Maps.newLinkedHashMap(); Map<E, S> stops = Maps.newLinkedHashMap(); Multimap<E, E> callers = new CfgUtil().getCallers(cfg); create(cfg, pda, pda.getStart(), cfg.getRoot(), ff.getStarts(cfg.getRoot()), ff, element2token, fact, states, stops, callers); return pda; }
protected <S, P, T, D extends Pda<S, P>> S clone(S state, Pda<S, P> src, D target, Function<S, T> tokens, PdaFactory<D, S, P, T> fact, Identity<S> identity) { if (state == src.getStart()) return target.getStart(); if (state == src.getStop()) return target.getStop(); P push = src.getPush(state); if (push != null) return identity.get(fact.createPush(target, tokens.apply(state))); P pop = src.getPop(state); if (pop != null) return identity.get(fact.createPop(target, tokens.apply(state))); return identity.get(fact.createState(target, tokens.apply(state))); }
public <S, P, E, T1, T2, D extends Pda<S, P>> D create(Cfg<E, T1> cfg, FollowerFunction<E> ff, Function<E, T2> element2token, PdaFactory<D, S, P, ? super T2> fact) { D pda = fact.create(null, null); Map<E, S> states = Maps.newHashMap(); Map<E, S> stops = Maps.newHashMap(); Multimap<E, E> callers = new CfgUtil().getCallers(cfg); create(cfg, pda, pda.getStart(), cfg.getRoot(), ff.getStarts(cfg.getRoot()), true, ff, element2token, fact, states, stops, callers); return pda; }
S s = stops.get(c); if (s == null) { s = fact.createPop(pda, tokens.apply(c)); stops.put(c, s); create(cfg, pda, s, c, ff.getFollowers(c), false, ff, tokens, fact, states, stops, callers); S s = states.get(fol); if (s == null) { s = fact.createPush(pda, tokens.apply(fol)); states.put(fol, s); create(cfg, pda, s, e, ff.getStarts(e), true, ff, tokens, fact, states, stops, callers); S s = states.get(fol); if (s == null) { s = fact.createState(pda, tokens.apply(fol)); states.put(fol, s); create(cfg, pda, s, fol, ff.getFollowers(fol), true, ff, tokens, fact, states, stops, callers); fact.setFollowers(pda, state, followerStates);
public <S, P, T, D extends Pda<S, P>> D expand(Pda<S, P> pda, Function<S, Pda<S, P>> expand, Function<S, T> tokens, PdaFactory<D, S, P, T> fact) { D result = fact.create(tokens.apply(pda.getStart()), tokens.apply(pda.getStop())); Identity<S> identity = new Identity<S>(); Map<S, S> idstates = Maps.newIdentityHashMap(); Pda<S, P> sub = expand.apply(s_old); if (sub != null) { S s_start = identity.get(fact.createPush(result, tokens.apply(s_old))); S s_stop = identity.get(fact.createPop(result, tokens.apply(s_old))); idstates.put(s_old, s_start); idstates.put(sub.getStart(), s_start); for (S s : entry.getValue()) f.add(idstates.get(s)); fact.setFollowers(result, entry.getKey(), f);
public <S, P, T, D extends Pda<S, P>> D expand(Pda<S, P> pda, Function<S, Pda<S, P>> expand, Function<S, T> tokens, PdaFactory<D, S, P, T> fact) { D result = fact.create(tokens.apply(pda.getStart()), tokens.apply(pda.getStop())); Identity<S> identity = new Identity<S>(); Map<S, S> idstates = Maps.newIdentityHashMap(); Pda<S, P> sub = expand.apply(s_old); if (sub != null) { S s_start = identity.get(fact.createPush(result, tokens.apply(s_old))); S s_stop = identity.get(fact.createPop(result, tokens.apply(s_old))); idstates.put(s_old, s_start); idstates.put(sub.getStart(), s_start); for (S s : entry.getValue()) f.add(idstates.get(s)); fact.setFollowers(result, entry.getKey(), f);
R previous = traverser.enter(pda, pda.getStart(), null); if (previous == null) return factory.create(pda.getStart(), pda.getStop()); Map<S, Integer> distances = new NfaUtil().distanceToFinalStateMap(pda); MappedComparator<S, Integer> distanceComp = new MappedComparator<S, Integer>(distances); D result = factory.create(pda.getStart(), pda.getStop()); Map<S, S> old2new = Maps.newHashMap(); old2new.put(pda.getStart(), result.getStart()); continue; else if (pda.getPop(old) != null) old2new.put(old, factory.createPop(result, old)); else if (pda.getPush(old) != null) old2new.put(old, factory.createPush(result, old)); else old2new.put(old, factory.createState(result, old)); for (S f : edges.get(old)) followers.add(old2new.get(f)); factory.setFollowers(result, old2new.get(old), followers);
R previous = traverser.enter(pda, pda.getStart(), null); if (previous == null) return factory == null ? null : factory.create(pda.getStart(), pda.getStop()); MappedComparator<S, Integer> distanceComp = new MappedComparator<S, Integer>(distances); trace.push(newItem(pda, distanceComp, distances, pda.getStart(), previous)); D result = factory.create(pda.getStart(), pda.getStop()); Map<S, S> old2new = Maps.newLinkedHashMap(); old2new.put(pda.getStart(), result.getStart()); continue; else if (pda.getPop(old) != null) old2new.put(old, factory.createPop(result, old)); else if (pda.getPush(old) != null) old2new.put(old, factory.createPush(result, old)); else old2new.put(old, factory.createState(result, old)); for (S f : edges.get(old)) followers.add(old2new.get(f)); factory.setFollowers(result, old2new.get(old), followers);