From 6af13e9dda011e2416e4f0ee3cc347e8e7fcafd7 Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 20 Jul 2006 04:39:33 -0400 Subject: [PATCH] questionable commit that eradicates the lame thing darcs-hash:20060720083933-5007d-d2be37a4b87e971eed9a3ebe4a62ff854c7bd5dc.gz --- src/edu/berkeley/sbp/Parser.java | 20 +++++++--- src/edu/berkeley/sbp/Sequence.java | 13 ++----- src/edu/berkeley/sbp/meta/MetaGrammarBindings.java | 41 ++++++++------------ 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/edu/berkeley/sbp/Parser.java b/src/edu/berkeley/sbp/Parser.java index 2344e15..b2445b0 100644 --- a/src/edu/berkeley/sbp/Parser.java +++ b/src/edu/berkeley/sbp/Parser.java @@ -268,14 +268,24 @@ public abstract class Parser { move.addAll(y, hp); } } - for(Element y : move) { + OUTER: for(Element y : move) { HashSet h = move.getAll(y); State s = all_states.get(h) == null ? new State(h, all_states, all_elements) : all_states.get(h); // if a reduction is "lame", it should wind up in the dead_state after reducing - if (y instanceof Sequence && ((Sequence)y).lame) - ((HashMap)gotoSetNonTerminals).put(y, dead_state); - else - gotoSetNonTerminals.put(y, s); + if (y instanceof Sequence) { + for(Position p : hs) { + if (p.element() != null && (p.element() instanceof Union)) { + Union u = (Union)p.element(); + for(Sequence seq : u) + if (seq.needs.contains((Sequence)y) || seq.hates.contains((Sequence)y)) { + // FIXME: what if there are two "routes" to get to the sequence? + ((HashMap)gotoSetNonTerminals).put(y, dead_state); + continue OUTER; + } + } + } + } + gotoSetNonTerminals.put(y, s); } } diff --git a/src/edu/berkeley/sbp/Sequence.java b/src/edu/berkeley/sbp/Sequence.java index 28f6564..44b30c5 100644 --- a/src/edu/berkeley/sbp/Sequence.java +++ b/src/edu/berkeley/sbp/Sequence.java @@ -18,7 +18,6 @@ public abstract class Sequence extends Element implements Iterable { for(Sequence s : needs) { ret.needs.add(s); s.needed.add(ret); } for(Sequence s : hates) { ret.hates.add(s); s.hated.add(ret); } ret.follow = follow; - ret.lame = lame; return ret; } @@ -26,7 +25,7 @@ public abstract class Sequence extends Element implements Iterable { public static final Sequence empty = new Sequence.Constant.Empty(); /** after matching the sequence, do not add anything to the output tree */ - public static Sequence drop(Element[] e, boolean lame) { return new Constant.Drop(e, lame); } + public static Sequence drop(Element[] e) { return new Constant.Drop(e); } /** after matching the sequence, insert a constant into the output tree */ public static Sequence constant(Element[] e, Object o) { return new Constant(e, o); } @@ -65,7 +64,6 @@ public abstract class Sequence extends Element implements Iterable { final HashSet hated = new HashSet(); final HashSet needs = new HashSet(); final HashSet hates = new HashSet(); - public boolean lame = false; final Position firstp; Position firstp() { return firstp; } @@ -184,15 +182,12 @@ public abstract class Sequence extends Element implements Iterable { return (Forest)Forest.create(loc, result, null, false); } static class Drop extends Constant { - Sequence _clone() { return new Drop(elements, lame); } - public Drop(Element[] e, boolean lame) { - super(e, null); - this.lame = lame; - } + Sequence _clone() { return new Drop(elements); } + public Drop(Element[] e) { super(e, null); } } static class Empty extends Sequence.Constant.Drop { Sequence _clone() { return new Empty(); } - public Empty() { super(new Element[] { }, false); } } + public Empty() { super(new Element[] { }); } } } static class Singleton extends Sequence { diff --git a/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java b/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java index 196394a..3790227 100644 --- a/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java +++ b/src/edu/berkeley/sbp/meta/MetaGrammarBindings.java @@ -78,14 +78,11 @@ public class MetaGrammarBindings extends AnnotationGrammarBindings { Union u2 = new Union(null, false); if (sequences.length==1) u2 = u; for(int j=0; j