- int ret = compareTo0(r);
- if (ret == 0) {
- Walk.Cache cache = node.state().cache();
- if (canKill(cache, position, r.position) && canKill(cache, r.position, position)) throw new Error();
- if (canKill(cache, position, r.position)) ret = 1;
- else if (canKill(cache, r.position, position)) ret = -1;
- if (canNeed(cache, position, r.position)) ret = 1;
- else if (canNeed(cache, r.position, position)) ret = -1;
- }
- return -1 * ret;
- }
-
- private static boolean isRightNullable(Walk.Cache c, Position p) {
- if (p.isLast()) return true;
- if (!c.possiblyEpsilon(p.element())) return false;
- return isRightNullable(c, p.next());
- }
-
- public static boolean canKill(Walk.Cache cache, Position mep, Position himp) {
- if (!isRightNullable(cache, mep)) return false;
- if (!isRightNullable(cache, himp)) return false;
- Sequence me = mep.owner();
- Sequence him = himp.owner();
- for(Sequence killer : him.hates()) {
- HashSet<Sequence> eq2 = new Walk.EquivalentTo(killer, cache).walk();
- if (eq2.contains(me)) return true;
+ if (parent.phase()!=null || r.parent.phase()!=null) {
+ if (parent.phase()==null) return 1;
+ if (r.parent.phase()==null) return -1;
+ if (parent.phase().pos < r.parent.phase().pos) return 1;
+ if (parent.phase().pos > r.parent.phase().pos) return -1;