gt:     jj_ntk = -1;
context: /* Generated By:JavaCC: Do not edit this line. MroiLisp.java */
  package mroi;
  import java.util.*;
  import mroi.*;
  import com.vividsolutions.jts.geom.*;
  import com.vividsolutions.jts.io.*;
  import java.io.FileInputStream;
  
  
  public class MroiLisp implements MroiLispConstants {
          public WKTReader rr = new WKTReader();
  
          public Integer previousNonemptyFrame(Map<Integer,MZipper<RoiContainer>> m, int frame) {
                  for (int i = frame-1; i > 0; i--) {
                          if (m.get(i).size() > 0) {
                                  return i;
                          }
                  }
                  return null;
          }
  
          public RoiContainer findIdInFrame(Map<Integer,MZipper<RoiContainer>> m, int id, int frame) {
                  List<RoiContainer> l = m.get(frame).asList();
                  for (RoiContainer r : l) {
                          if (r.id == id)
                                  return r;
                  }
                  return null;
          }
  
          public static void main(String args[]) throws Exception {
                  MroiLisp parser = new MroiLisp(new FileInputStream("/Users/ross/test.rois"));
                  System.out.println(parser.roiFile().toString());
          }
  
    final public RoiContainer roiContainer(Map<Integer,Integer> predecessorMap) throws ParseException, Exception {
          Token tid, tgeom, tprevid;
          Integer id, previd;
          Geometry geom;
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case NULL:
        jj_consume_token(NULL);
                    {if (true) return null;}
        break;
      case LPAREN:
        jj_consume_token(LPAREN);
        tid = jj_consume_token(NUMBER);
        tgeom = jj_consume_token(GEOMETRY);
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case NUMBER:
          tprevid = jj_consume_token(NUMBER);
          break;
        case NULL:
          tprevid = jj_consume_token(NULL);
          break;
        default:
          jj_la1[0] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
        }
        jj_consume_token(RPAREN);
                  id = Integer.decode(tid.image);
                  geom = rr.read(tgeom.image.substring(1,tgeom.image.length()-1));
                  if (tprevid.image.equalsIgnoreCase("null")) {
                          previd = null;
                  } else {
                          previd = Integer.decode(tprevid.image);
                          predecessorMap.put(id,previd);
                  }
                  {if (true) return new RoiContainer(id,geom);} // Doesn't handle previd right!
  
        break;
      default:
        jj_la1[1] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      throw new Error("Missing return statement in function");
    }
  
    final public ArrayList<RoiContainer> list(Map<Integer,Integer> predecessorMap) throws ParseException, Exception {
          ArrayList<RoiContainer> arr = new ArrayList<RoiContainer>();
          RoiContainer r;
      jj_consume_token(LPAREN);
      label_1:
      while (true) {
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case LPAREN:
        case NULL:
          ;
          break;
        default:
          jj_la1[2] = jj_gen;
          break label_1;
        }
        r = roiContainer(predecessorMap);
                                                       arr.add(r);
      }
      jj_consume_token(RPAREN);
                  if (arr.size() == 0) {
                          {if (true) return null;}
                  } else {
                          {if (true) return arr;}
                  }
      throw new Error("Missing return statement in function");
    }
  
    final public MZipper<RoiContainer> mzipper(Map<Integer,Integer> p) throws ParseException, Exception {
          List<RoiContainer> lefts;
          RoiContainer current;
          List<RoiContainer> rights;
      jj_consume_token(LPAREN);
      lefts = list(p);
      current = roiContainer(p);
      rights = list(p);
      jj_consume_token(RPAREN);
                  if (current==null) {
                          {if (true) return new NZipper<RoiContainer>(lefts,rights);}
                  } else {
                          {if (true) return new JZipper<RoiContainer>(lefts,current,rights);}
                  }
      throw new Error("Missing return statement in function");
    }
  
    final public void frame(Map<Integer,MZipper<RoiContainer>> m, Map<Integer,Integer> p) throws ParseException, Exception {
          Token tframe;
          MZipper<RoiContainer> z;
      jj_consume_token(LPAREN);
      tframe = jj_consume_token(NUMBER);
      jj_consume_token(11);
      z = mzipper(p);
      jj_consume_token(RPAREN);
                  m.put(Integer.decode(tframe.image), z);
    }
  
    final public Map<Integer,MZipper<RoiContainer>> roiFile() throws ParseException, Exception {
          Map<Integer,Integer> p = new HashMap<Integer,Integer>();
          Map<Integer,MZipper<RoiContainer>> m = new HashMap<Integer,MZipper<RoiContainer>>();
      jj_consume_token(LPAREN);
      label_2:
      while (true) {
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case LPAREN:
          ;
          break;
        default:
          jj_la1[3] = jj_gen;
          break label_2;
        }
        frame(m,p);
      }
      jj_consume_token(RPAREN);
                  Integer prevFrame;
                  for (Integer frame : m.keySet()) {
                          prevFrame = previousNonemptyFrame(m, frame);
                          if (prevFrame != null) {
                                  for (RoiContainer currentRoi : m.get(frame).asList()) {
                                          if (p.containsKey(currentRoi.id)) {
                                                  currentRoi.setPredecessor(findIdInFrame(m, p.get(currentRoi.id), prevFrame));
                                          }
                                  }
                          }
                  }
                  {if (true) return m;}
      throw new Error("Missing return statement in function");
    }
  
    /** Generated Token Manager. */
    public MroiLispTokenManager token_source;
    SimpleCharStream jj_input_stream;
    /** Current token. */
    public Token token;
    /** Next token. */
    public Token jj_nt;
    private int jj_ntk;
    private int jj_gen;
    final private int[] jj_la1 = new int[4];
    static private int[] jj_la1_0;
    static {
        jj_la1_init_0();
     }
     private static void jj_la1_init_0() {
        jj_la1_0 = new int[] {0x300,0x220,0x220,0x20,};
     }
  
    /** Constructor with InputStream. */
    public MroiLisp(java.io.InputStream stream) {
       this(stream, null);
    }
    /** Constructor with InputStream and supplied encoding */
    public MroiLisp(java.io.InputStream stream, String encoding) {
      try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
      token_source = new MroiLispTokenManager(jj_input_stream);
      token = new Token();
      jj_ntk = -1;
      jj_gen = 0;
      for (int i = 0; i < 4; i++) jj_la1[i] = -1;
    }
  
    /** Reinitialise. */
    public void ReInit(java.io.InputStream stream) {
       ReInit(stream, null);
    }
    /** Reinitialise. */
    public void ReInit(java.io.InputStream stream, String encoding) {
      try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
      token_source.ReInit(jj_input_stream);
      token = new Token();
      jj_ntk = -1;
      jj_gen = 0;
      for (int i = 0; i < 4; i++) jj_la1[i] = -1;
    }
  
    /** Constructor. */
    public MroiLisp(java.io.Reader stream) {
      jj_input_stream = new SimpleCharStream(stream, 1, 1);
      token_source = new MroiLispTokenManager(jj_input_stream);
      token = new Token();
      jj_ntk = -1;
      jj_gen = 0;
      for (int i = 0; i < 4; i++) jj_la1[i] = -1;
    }
  
    /** Reinitialise. */
    public void ReInit(java.io.Reader stream) {
      jj_input_stream.ReInit(stream, 1, 1);
      token_source.ReInit(jj_input_stream);
      token = new Token();
      jj_ntk = -1;
      jj_gen = 0;
      for (int i = 0; i < 4; i++) jj_la1[i] = -1;
    }
  
    /** Constructor with generated Token Manager. */
    public MroiLisp(MroiLispTokenManager tm) {
      token_source = tm;
      token = new Token();
  