From ac3843911c47a601ffd679d2e075b519d3a18d6a Mon Sep 17 00:00:00 2001 From: adam Date: Thu, 30 Mar 2006 14:33:32 -0500 Subject: [PATCH] checkpoint darcs-hash:20060330193332-5007d-3012776ca736d0766a550ff016cf5f8c1d485dbf.gz --- src/edu/berkeley/sbp/Input.java | 40 +++++++++++++++++++--- src/edu/berkeley/sbp/misc/CartesianInput.java | 8 ++--- src/edu/berkeley/sbp/misc/CartesianLocation.java | 14 -------- src/edu/berkeley/sbp/misc/MetaGrammar.java | 2 ++ src/edu/berkeley/sbp/tib/Tib.java | 2 +- 5 files changed, 43 insertions(+), 23 deletions(-) delete mode 100644 src/edu/berkeley/sbp/misc/CartesianLocation.java diff --git a/src/edu/berkeley/sbp/Input.java b/src/edu/berkeley/sbp/Input.java index eeb3cc1..be41cbe 100644 --- a/src/edu/berkeley/sbp/Input.java +++ b/src/edu/berkeley/sbp/Input.java @@ -10,14 +10,46 @@ import edu.berkeley.sbp.util.*; public interface Input { /** returns the token just beyond the current location and advances beyond it */ - public Token next() throws IOException; + public Token next() throws IOException; /** returns the location the input stream is currently at */ - public Location getLocation(); + public Location getLocation(); - /** a location *between tokens* in the input stream */ - public static interface Location { + /** a location between tokens in the input stream */ + public static interface Location extends Comparable { public String toString(); + + /** an implementation of Location for a cartesian grid (row, col) */ + public static class Cartesian implements Location, Comparable { + protected final int row; + protected final int col; + public String toString() { return row+":"+col; } + public int getCol() { return col; } + public int getRow() { return row; } + public Cartesian(int col, int row) { this.row = row; this.col = col; } + public int compareTo(Location loc) throws ClassCastException { + if (!(loc instanceof Cartesian)) throw new ClassCastException(); + Cartesian c = (Cartesian)loc; + if (row < c.row) return -1; + if (row > c.row) return 1; + if (col < c.col) return -1; + if (col > c.col) return 1; + return 0; + } + } + } + + public static class Region /* implements Topology> */ { + public final Loc start; + public final Loc end; + public Region(Loc a, Loc b) { + switch(a.compareTo(b)) { + case -1: + case 0: start=a; end=b; return; + case 1: start=b; end=a; return; + default: throw new Error("impossible"); + } + } } } diff --git a/src/edu/berkeley/sbp/misc/CartesianInput.java b/src/edu/berkeley/sbp/misc/CartesianInput.java index a78df9a..3af71f1 100644 --- a/src/edu/berkeley/sbp/misc/CartesianInput.java +++ b/src/edu/berkeley/sbp/misc/CartesianInput.java @@ -13,12 +13,12 @@ public abstract class CartesianInput implements Input { public abstract boolean isCR(); long then = 0; - private CartesianLocation location = new CartesianLocation(1, 0); + private Input.Location.Cartesian location = new Input.Location.Cartesian(0, 1); public Input.Location getLocation() { return location; } public Token next(int numstates, int resets, int waits) throws IOException { - int line = location.line; - int col = location.col; + int line = location.getRow(); + int col = location.getCol(); Token t = next(); if (t==null) return null; String s = " line "+line+", col " + col; @@ -35,7 +35,7 @@ public abstract class CartesianInput implements Input { } else { col++; } - location = new CartesianLocation(line, col); + location = new Input.Location.Cartesian(col, line); return t; } } diff --git a/src/edu/berkeley/sbp/misc/CartesianLocation.java b/src/edu/berkeley/sbp/misc/CartesianLocation.java deleted file mode 100644 index b5d7bb7..0000000 --- a/src/edu/berkeley/sbp/misc/CartesianLocation.java +++ /dev/null @@ -1,14 +0,0 @@ -package edu.berkeley.sbp.misc; -import java.io.*; -import java.util.*; -import java.lang.reflect.*; -import java.lang.ref.*; -import edu.berkeley.sbp.*; -import edu.berkeley.sbp.util.*; - -public class CartesianLocation implements Input.Location { - public final int line; - public final int col; - public String toString() { return line + ":" + col; } - public CartesianLocation(int line, int col) { this.line = line; this.col = col; } -} diff --git a/src/edu/berkeley/sbp/misc/MetaGrammar.java b/src/edu/berkeley/sbp/misc/MetaGrammar.java index 5ea468d..59b6a21 100644 --- a/src/edu/berkeley/sbp/misc/MetaGrammar.java +++ b/src/edu/berkeley/sbp/misc/MetaGrammar.java @@ -528,6 +528,7 @@ public class MetaGrammar extends StringWalker { + // DO NOT EDIT STUFF BELOW: IT IS AUTOMATICALLY GENERATED new edu.berkeley.sbp.Tree(null, "grammar", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "=", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "s", new edu.berkeley.sbp.Tree[] { })}), new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "psx", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "ps", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "!", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "nonTerminal", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "w", new edu.berkeley.sbp.Tree[] { }), @@ -1190,3 +1191,4 @@ new edu.berkeley.sbp.Tree(null, "grammar", new edu.berkeley.sbp.Tree[] { new edu + diff --git a/src/edu/berkeley/sbp/tib/Tib.java b/src/edu/berkeley/sbp/tib/Tib.java index 93f2ce1..4805d1e 100644 --- a/src/edu/berkeley/sbp/tib/Tib.java +++ b/src/edu/berkeley/sbp/tib/Tib.java @@ -42,7 +42,7 @@ public class Tib implements Input { int _row = 1; int _col = 0; - public Input.Location getLocation() { return new CartesianLocation(_row, _col); } + public Input.Location getLocation() { return new Input.Location.Cartesian(_col, _row); } private BufferedReader br; char left = CharRange.left; -- 1.7.10.4