X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmisc%2FCartesian.java;h=56650194b7fdad455505666ca8e0b7a4cc05b69a;hp=676a4cf3f597def00bcaf4ac18260f8cc8faad4e;hb=2cca97362e80d5a3cd3e02d791a10cd7c6f6b29c;hpb=c8a17fdd2e149fe5feecd96c71b7f2cab286ab96 diff --git a/src/edu/berkeley/sbp/misc/Cartesian.java b/src/edu/berkeley/sbp/misc/Cartesian.java index 676a4cf..5665019 100644 --- a/src/edu/berkeley/sbp/misc/Cartesian.java +++ b/src/edu/berkeley/sbp/misc/Cartesian.java @@ -11,21 +11,21 @@ public class Cartesian { public static abstract class Input implements edu.berkeley.sbp.Input { - public abstract Token next() throws IOException; + public abstract Token _next() throws IOException; public abstract boolean isCR(); long then = 0; private Cartesian.Location location = new Cartesian.Location(0, 1); public edu.berkeley.sbp.Input.Location getLocation() { return location; } - public Token next(int numstates, int resets, int waits) throws IOException { + public Token next() throws IOException { int line = location.getRow(); int col = location.getCol(); - Token t = next(); + Token t = _next(); if (t==null) return null; String s = " line "+line+", col " + col; while(s.length() < 20) s += " "; - s += "[ambiguity level: " + (numstates-1) + "] [resets: " + resets + "] [waits: " + waits + "]"; + //s += "[ambiguity level: " + (numstates-1) + "] [resets: " + resets + "] [waits: " + waits + "]"; long now = System.currentTimeMillis(); if (now-then > 10) { then = now; @@ -59,5 +59,24 @@ public class Cartesian { if (col > c.col) return 1; return 0; } + public Input.Region createRegion(Input.Location loc) { + return new Region(this, (Cartesian.Location)loc); } + } + + public static class Region implements Input.Region { + public final Location start; + public final Location end; + public String toString() { + if (start.row==end.row) return start.row+":"+(start.col+"-"+end.col); + return start+"-"+end; + } + public Region(Location a, Location 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"); + } + } } }