From: adam Date: Fri, 10 Feb 2006 07:05:15 +0000 (-0500) Subject: added tracking of position to Forest nodes X-Git-Tag: tag_for_25-Mar~297 X-Git-Url: http://git.megacz.com/?p=sbp.git;a=commitdiff_plain;h=743754674298bb8a3303bdffd3b5c5cc0de1b158 added tracking of position to Forest nodes darcs-hash:20060210070515-5007d-840031e0ff1fb782492c1407c584bd79091e7032.gz --- diff --git a/src/edu/berkeley/sbp/Forest.java b/src/edu/berkeley/sbp/Forest.java index ceb67eb..e74d81e 100644 --- a/src/edu/berkeley/sbp/Forest.java +++ b/src/edu/berkeley/sbp/Forest.java @@ -1,6 +1,6 @@ package edu.berkeley.sbp; import edu.berkeley.sbp.*; -import edu.berkeley.sbp.*; +import edu.berkeley.sbp.Sequence.Position; import edu.berkeley.sbp.util.*; import java.io.*; import java.util.*; @@ -20,6 +20,7 @@ public abstract class Forest /*extends PrintableTree>*/ impl /** expand this forest into a set of trees */ public HashSet> expand(boolean toss) { + //if (toss) scan(); final HashSetTreeConsumer ret = new HashSetTreeConsumer(); visit(new TreeMaker2(toss, ret), null, null); if (toss && ret.size() > 1) throw new InnerAmbiguous(this); @@ -38,11 +39,14 @@ public abstract class Forest /*extends PrintableTree>*/ impl public void addTree(Tree t) { super.add(t); } } - static Forest singleton(Input.Location loc) { return create(loc, null, new Forest[] { }, false, true); } - static Forest singleton(Input.Location loc, Forest body) { return create(loc, null, new Forest[] { body }, false, true); } - static Forest leaf(Input.Location loc, T tag) { return create(loc, tag, null, false, false); } - public static Forest create(Input.Location loc, T tag, Forest[] tokens, boolean unwrap, boolean singleton) { - return new MyBody(loc, tag, tokens, unwrap, singleton); + static Forest singleton(Input.Location loc, Position p) { + return create(loc, null, new Forest[] { }, false, true, p); } + static Forest singleton(Input.Location loc, Forest body, Position p) { + return create(loc, null, new Forest[] { body }, false, true, p); } + static Forest leaf(Input.Location loc, T tag, Position p) { return create(loc, tag, null, false, false, p); } + + public static Forest create(Input.Location loc, T tag, Forest[] tokens, boolean unwrap, boolean singleton, Position p) { + return new MyBody(loc, tag, tokens, unwrap, singleton, p); } // Body ////////////////////////////////////////////////////////////////////////////// @@ -62,8 +66,9 @@ public abstract class Forest /*extends PrintableTree>*/ impl private final Forest[] tokens; private final boolean unwrap; private final boolean singleton; + private final Sequence.Position reduction; - private MyBody(Input.Location loc, T tag, Forest[] tokens, boolean unwrap, boolean singleton) { + private MyBody(Input.Location loc, T tag, Forest[] tokens, boolean unwrap, boolean singleton, Position reduction) { this.location = loc; this.tag = tag; this.tokens = tokens==null ? emptyForestArray : new Forest[tokens.length]; @@ -71,6 +76,7 @@ public abstract class Forest /*extends PrintableTree>*/ impl if (tokens != null) for(int i=0; i h) { diff --git a/src/edu/berkeley/sbp/Parser.java b/src/edu/berkeley/sbp/Parser.java index 0c9ed84..1ea89ad 100644 --- a/src/edu/berkeley/sbp/Parser.java +++ b/src/edu/berkeley/sbp/Parser.java @@ -22,7 +22,7 @@ public abstract class Parser { GSS gss = new GSS(); Input.Location loc = input.getLocation(); GSS.Phase current = gss.new Phase(null, this, null, input.next(1, 0, 0), loc, null); - current.newNode(null, Forest.leaf(null, null), pt.start, true); + current.newNode(null, Forest.leaf(null, null, null), pt.start, true); int count = 1; for(;;) { loc = input.getLocation(); diff --git a/src/edu/berkeley/sbp/Sequence.java b/src/edu/berkeley/sbp/Sequence.java index d9d035a..071c219 100644 --- a/src/edu/berkeley/sbp/Sequence.java +++ b/src/edu/berkeley/sbp/Sequence.java @@ -80,7 +80,7 @@ public abstract class Sequence extends Element implements Iterable { return epsilonForm; } - protected abstract Forest postReduce(Input.Location loc, Forest[] args); + protected abstract Forest postReduce(Input.Location loc, Forest[] args, Position p); // Position ////////////////////////////////////////////////////////////////////////////// @@ -130,7 +130,7 @@ public abstract class Sequence extends Element implements Iterable { if (holder[i]==null) holder[i] = elements[i].epsilonForm(); if (holder[i]==null) throw new Error("bad " + i); } - Forest ret = Sequence.this.postReduce(loc, holder); + Forest ret = Sequence.this.postReduce(loc, holder, this); for(int k=0; k { private final Object result; public Constant(Element[] e, Object result) { super(e); this.result = result; } Sequence _clone() { return new Constant(elements, result); } - public Forest postReduce(Input.Location loc, Forest[] args) { - return (Forest)Forest.leaf(loc, result); + public Forest postReduce(Input.Location loc, Forest[] args, Position p) { + return (Forest)Forest.leaf(loc, result, p); } static class Drop extends Constant { Sequence _clone() { return new Drop(elements, lame); } @@ -190,7 +190,7 @@ public abstract class Sequence extends Element implements Iterable { private final int idx; public Singleton(Element e) { this(new Element[] { e }, 0); } public Singleton(Element[] e, int idx) { super(e); this.idx = idx; } - public Forest postReduce(Input.Location loc, Forest[] args) { return (Forest)Forest.singleton(loc, args[idx]); } + public Forest postReduce(Input.Location loc, Forest[] args, Position p) { return (Forest)Forest.singleton(loc, args[idx], p); } Sequence _clone() { return new Singleton(elements,idx); } } @@ -199,15 +199,15 @@ public abstract class Sequence extends Element implements Iterable { public Unwrap(Element[] e) { super(e); this.drops = null; } public Unwrap(Element[] e, boolean[] drops) { super(e); this.drops = drops; } Sequence _clone() { return new Unwrap(elements, drops); } - public Forest postReduce(Input.Location loc, Forest[] args) { + public Forest postReduce(Input.Location loc, Forest[] args, Position p) { for(int i=0; i[] args2 = new Forest[count]; int j = 0; for(int i=0; i { this.drops = drops == null ? new boolean[e.length] : drops; for(int i=0; i Forest postReduce(Input.Location loc, Forest[] args) { + public Forest postReduce(Input.Location loc, Forest[] args, Position p) { Forest[] args2 = new Forest[count]; int j = 0; for(int i=0; i