make sure we track Input.Region for epsilon reductions (important for ambiguity-hunting)
authoradam <adam@megacz.com>
Sun, 23 Jul 2006 06:20:25 +0000 (02:20 -0400)
committeradam <adam@megacz.com>
Sun, 23 Jul 2006 06:20:25 +0000 (02:20 -0400)
darcs-hash:20060723062025-5007d-1a90bd90e98f2f4926b9e9def5457198b4ba4ae7.gz

src/edu/berkeley/sbp/Ambiguous.java
src/edu/berkeley/sbp/Element.java
src/edu/berkeley/sbp/Forest.java
src/edu/berkeley/sbp/GSS.java
src/edu/berkeley/sbp/Parser.java
src/edu/berkeley/sbp/Sequence.java
src/edu/berkeley/sbp/Union.java
tests/java15.test

index 6138577..37a857c 100644 (file)
@@ -20,6 +20,7 @@ public class Ambiguous extends Exception {
         // FIXME: print the input region that was ambiguously matched
         StringBuffer sb = new StringBuffer();
         sb.append("unresolved ambiguity at "+ambiguity.getRegion()+"; shared subtrees are shown as \"*\" ");
         // FIXME: print the input region that was ambiguously matched
         StringBuffer sb = new StringBuffer();
         sb.append("unresolved ambiguity at "+ambiguity.getRegion()+"; shared subtrees are shown as \"*\" ");
+        //sb.append("\noffending text: ");
         for(Tree<?> result : ht) {
             sb.append("\n  possibility: ");
             StringBuffer sb2 = new StringBuffer();
         for(Tree<?> result : ht) {
             sb.append("\n  possibility: ");
             StringBuffer sb2 = new StringBuffer();
index 7eb6a59..f7a8978 100644 (file)
@@ -16,6 +16,6 @@ public abstract class Element implements SequenceOrElement {
     abstract StringBuffer toString(StringBuffer sb);
 
     /** returns the Forest resulting from matching this element against the empty string */
     abstract StringBuffer toString(StringBuffer sb);
 
     /** returns the Forest resulting from matching this element against the empty string */
-    Forest<?> epsilonForm() { throw new Error("element " + this + " has no epsilon form"); }
+    Forest<?> epsilonForm(Input.Region loc) { throw new Error("element " + this + " has no epsilon form"); }
 
 }
 
 }
index ee3bfbc..43ffb10 100644 (file)
@@ -21,6 +21,7 @@ public abstract class Forest<NodeType> implements GraphViz.ToGraphViz {
     public void expand(HashSet<Tree<NodeType>> ht) { expand(ht, new HashSet<Forest<NodeType>>(), null); }
 
     static <NodeType> Forest<NodeType> create(Input.Region loc, NodeType head, Forest<NodeType>[] children, boolean lift) {
     public void expand(HashSet<Tree<NodeType>> ht) { expand(ht, new HashSet<Forest<NodeType>>(), null); }
 
     static <NodeType> Forest<NodeType> create(Input.Region loc, NodeType head, Forest<NodeType>[] children, boolean lift) {
+        if (loc == null) throw new Error();
         return new One<NodeType>(loc, head, children, lift);
     }
 
         return new One<NodeType>(loc, head, children, lift);
     }
 
index 5ede971..d4cf42f 100644 (file)
@@ -327,7 +327,7 @@ class GSS {
                     }
                     if (n==null) return;
                     Forest[] holder = new Forest[r.pos];
                     }
                     if (n==null) return;
                     Forest[] holder = new Forest[r.pos];
-                    if (r.pos==0) n.finish(r, r.zero(), n.phase());
+                    if (r.pos==0) n.finish(r, r.zero(n.phase().getLocation().createRegion(n.phase().getLocation())), n.phase());
                     else          n.reduce(r, r.pos-1,  n.phase(), null);
                 } else {
                     if (r.pos<=0) throw new Error("called wrong form of reduce()");
                     else          n.reduce(r, r.pos-1,  n.phase(), null);
                 } else {
                     if (r.pos<=0) throw new Error("called wrong form of reduce()");
index c77ad6e..74d7101 100644 (file)
@@ -27,7 +27,7 @@ public abstract class Parser<Token, NodeType> {
         Input.Location loc = input.getLocation();
         Token tok = input.next();
         GSS.Phase current = gss.new Phase<Token>(null, this, null, tok, loc, input.getLocation(), null);
         Input.Location loc = input.getLocation();
         Token tok = input.next();
         GSS.Phase current = gss.new Phase<Token>(null, this, null, tok, loc, input.getLocation(), null);
-        current.newNode(null, Forest.create(null, null, null, false), pt.start, true);
+        current.newNode(null, Forest.create(loc.createRegion(loc), null, null, false), pt.start, true);
         int count = 1;
         for(int idx=0;;idx++) {
             Input.Location oldloc = loc;
         int count = 1;
         for(int idx=0;;idx++) {
             Input.Location oldloc = loc;
index 5680d6c..84a2dc6 100644 (file)
@@ -84,10 +84,10 @@ public abstract class Sequence implements Iterable<Element>, SequenceOrElement {
 
     // DO NOT MESS WITH THE FOLLOWING LINE!!!
     private Forest.Many epsilonForm = null;
 
     // DO NOT MESS WITH THE FOLLOWING LINE!!!
     private Forest.Many epsilonForm = null;
-    Forest epsilonForm() {
+    Forest epsilonForm(Input.Region loc) {
         if (epsilonForm!=null) return epsilonForm;
         epsilonForm = new Forest.Many();
         if (epsilonForm!=null) return epsilonForm;
         epsilonForm = new Forest.Many();
-        epsilonForm.merge(firstp().rewrite(null, false));
+        epsilonForm.merge(firstp().rewrite(loc, false));
         return epsilonForm;
     }
 
         return epsilonForm;
     }
 
@@ -100,10 +100,10 @@ public abstract class Sequence implements Iterable<Element>, SequenceOrElement {
     class Position implements IntegerMappable {
 
         private Forest zero = null;
     class Position implements IntegerMappable {
 
         private Forest zero = null;
-        public Forest zero() {
+        public Forest zero(Input.Region reg) {
             if (zero != null) return zero;
             if (pos > 0) throw new Error();
             if (zero != null) return zero;
             if (pos > 0) throw new Error();
-            return zero = rewrite(null);
+            return zero = rewrite(reg);
         }
 
 
         }
 
 
@@ -135,10 +135,10 @@ public abstract class Sequence implements Iterable<Element>, SequenceOrElement {
 
         final <T> Forest<T> rewrite(Input.Region loc) { return rewrite(loc, true); }
         private final <T> Forest<T> rewrite(Input.Region loc, boolean epsilonCheck) {
 
         final <T> Forest<T> rewrite(Input.Region loc) { return rewrite(loc, true); }
         private final <T> Forest<T> rewrite(Input.Region loc, boolean epsilonCheck) {
-            if (epsilonCheck && this==firstp()) return epsilonForm();
+            if (epsilonCheck && this==firstp()) return epsilonForm(loc);
             for(int i=0; i<pos; i++) if (holder[i]==null) throw new Error("realbad " + i);
             for(int i=pos; i<elements.length; i++) {
             for(int i=0; i<pos; i++) if (holder[i]==null) throw new Error("realbad " + i);
             for(int i=pos; i<elements.length; i++) {
-                if (holder[i]==null) holder[i] = elements[i].epsilonForm();
+                if (holder[i]==null) holder[i] = elements[i].epsilonForm(loc);
                 if (holder[i]==null) throw new Error("bad " + i);
             }
             Forest<T> ret = Sequence.this.postReduce(loc, holder, this);
                 if (holder[i]==null) throw new Error("bad " + i);
             }
             Forest<T> ret = Sequence.this.postReduce(loc, holder, this);
index d52c6e9..f1f65b1 100644 (file)
@@ -70,14 +70,14 @@ public class Union extends Element implements Iterable<Sequence> {
     // Epsilon Form //////////////////////////////////////////////////////////////////////////////
 
     // FIXME
     // Epsilon Form //////////////////////////////////////////////////////////////////////////////
 
     // FIXME
-    private Forest.Many epsilonForm = null;
-    Forest epsilonForm() {
-        if (epsilonForm != null) return epsilonForm;
-        epsilonForm = new Forest.Many();
+    //private Forest.Many epsilonForm = null;
+    Forest epsilonForm(Input.Region loc) {
+        //if (epsilonForm != null) return epsilonForm;
+        Forest.Many epsilonForm = new Forest.Many();
         for(Sequence s : this) {
             // FIXME FIXME FIXME
             if (new Walk.Cache().possiblyEpsilon(s))
         for(Sequence s : this) {
             // FIXME FIXME FIXME
             if (new Walk.Cache().possiblyEpsilon(s))
-                epsilonForm.merge(s.epsilonForm());
+                epsilonForm.merge(s.epsilonForm(loc));
         }
         return epsilonForm;
     }
         }
         return epsilonForm;
     }
index 968eaf7..976fb75 100644 (file)
@@ -7,5 +7,6 @@ public class Baz < A extends Object , Q super Foo<Bar<Baz>,Bop> > {
   }
 
   protected abstract int bar(int c);
   }
 
   protected abstract int bar(int c);
+  protected abstract int bop(  );
 
 }
 
 }