/* Generated By:JJTree&JavaCC: Do not edit this line. drawphase2.java */
public class drawphase2/*@bgen(jjtree)*/implements drawphase2TreeConstants, drawphase2Constants {/*@bgen(jjtree)*/
  protected static JJTdrawphase2State jjtree = new JJTdrawphase2State();public static void main(String args[])
  {
    drawphase2 parser = new drawphase2(System.in);
    try
    {
      ASTProgram p = parser.Program();
      if (args.length == 1 && args[0].equals("-d"))
      {
       p.dump("");
      }
      else
      {
          //this is the default colour
        p.generate("black",0,0,1);
      }
    }
    catch (ParseException e)
    {
      System.out.println("drawphase1:  Encountered errors during parse.");
      e.printStackTrace();
    }
    catch (Exception e1)
    {
      System.out.println("drawphase1:  Encountered errors during interpretation/tree building.");
      e1.printStackTrace();
    }
    catch (Error e2)
    {
      System.out.println("drawphase1:  Encountered errors during interpretation.");
      e2.printStackTrace();
    }
  }

  static final public ASTProgram Program() throws ParseException {
                        /*@bgen(jjtree) Program */
  ASTProgram jjtn000 = new ASTProgram(JJTPROGRAM);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      jj_consume_token(PICTURE);
      jj_consume_token(LBRACE);
      Int();
      Int();
      jj_consume_token(RBRACE);
      Segment();
      jj_consume_token(0);
    jjtree.closeNodeScope(jjtn000, true);
    jjtc000 = false;
    {if (true) return jjtn000;}
    } catch (Throwable jjte000) {
    if (jjtc000) {
      jjtree.clearNodeScope(jjtn000);
      jjtc000 = false;
    } else {
      jjtree.popNode();
    }
    if (jjte000 instanceof RuntimeException) {
      {if (true) throw (RuntimeException)jjte000;}
    }
    if (jjte000 instanceof ParseException) {
      {if (true) throw (ParseException)jjte000;}
    }
    {if (true) throw (Error)jjte000;}
    } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
    }
    }
    throw new Error("Missing return statement in function");
  }

  static final public void Command() throws ParseException {
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case LINE:
      Line();
      break;
    case RECTANGLE:
      Rectangle();
      break;
    case SQUARE:
      Square();
      break;
    case ELLIPSE:
      Ellipse();
      break;
    case CIRCLE:
      Circle();
      break;
    case TRIANGLE:
      Triangle();
      break;
    case POLYGON:
      Polygon();
      break;
    case TEXT:
      Text();
      break;
    case COLOUR:
      Colour();
      break;
    case BRUSH:
      Brush();
      break;
    case OFFSET:
      Offset();
      break;
    case STR:
      Str();
      break;
    default:
      jj_la1[0] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  static final public void Segment() throws ParseException {
                  /*@bgen(jjtree) Segment */
  ASTSegment jjtn000 = new ASTSegment(JJTSEGMENT);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      jj_consume_token(22);
      label_1:
      while (true) {
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case STR:
        case LINE:
        case RECTANGLE:
        case SQUARE:
        case ELLIPSE:
        case CIRCLE:
        case TRIANGLE:
        case POLYGON:
        case TEXT:
        case COLOUR:
        case BRUSH:
        case OFFSET:
          Command();
          break;
        case 22:
          Segment();
          break;
        default:
          jj_la1[1] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
        }
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case STR:
        case LINE:
        case RECTANGLE:
        case SQUARE:
        case ELLIPSE:
        case CIRCLE:
        case TRIANGLE:
        case POLYGON:
        case TEXT:
        case COLOUR:
        case BRUSH:
        case OFFSET:
        case 22:
          ;
          break;
        default:
          jj_la1[2] = jj_gen;
          break label_1;
        }
      }
      jj_consume_token(23);
    } catch (Throwable jjte000) {
          if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte000 instanceof RuntimeException) {
            {if (true) throw (RuntimeException)jjte000;}
          }
          if (jjte000 instanceof ParseException) {
            {if (true) throw (ParseException)jjte000;}
          }
          {if (true) throw (Error)jjte000;}
    } finally {
          if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
          }
    }
  }

  static final public void Line() throws ParseException {
               /*@bgen(jjtree) Line */
  ASTLine jjtn000 = new ASTLine(JJTLINE);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      jj_consume_token(LINE);
      jj_consume_token(LBRACE);
      Int();
      Int();
      Int();
      Int();
      jj_consume_token(RBRACE);
    } catch (Throwable jjte000) {
          if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte000 instanceof RuntimeException) {
            {if (true) throw (RuntimeException)jjte000;}
          }
          if (jjte000 instanceof ParseException) {
            {if (true) throw (ParseException)jjte000;}
          }
          {if (true) throw (Error)jjte000;}
    } finally {
          if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
          }
    }
  }

  static final public void Rectangle() throws ParseException {
                    /*@bgen(jjtree) Rectangle */
  ASTRectangle jjtn000 = new ASTRectangle(JJTRECTANGLE);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      jj_consume_token(RECTANGLE);
      jj_consume_token(LBRACE);
      Int();
      Int();
      Int();
      Int();
      jj_consume_token(RBRACE);
    } catch (Throwable jjte000) {
          if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte000 instanceof RuntimeException) {
            {if (true) throw (RuntimeException)jjte000;}
          }
          if (jjte000 instanceof ParseException) {
            {if (true) throw (ParseException)jjte000;}
          }
          {if (true) throw (Error)jjte000;}
    } finally {
          if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
          }
    }
  }

  static final public void Square() throws ParseException {
                 /*@bgen(jjtree) Square */
  ASTSquare jjtn000 = new ASTSquare(JJTSQUARE);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      jj_consume_token(SQUARE);
      jj_consume_token(LBRACE);
      Int();
      Int();
      Int();
      jj_consume_token(RBRACE);
    } catch (Throwable jjte000) {
          if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte000 instanceof RuntimeException) {
            {if (true) throw (RuntimeException)jjte000;}
          }
          if (jjte000 instanceof ParseException) {
            {if (true) throw (ParseException)jjte000;}
          }
          {if (true) throw (Error)jjte000;}
    } finally {
          if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
          }
    }
  }

  static final public void Ellipse() throws ParseException {
                  /*@bgen(jjtree) Ellipse */
  ASTEllipse jjtn000 = new ASTEllipse(JJTELLIPSE);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      jj_consume_token(ELLIPSE);
      jj_consume_token(LBRACE);
      Int();
      Int();
      Int();
      Int();
      jj_consume_token(RBRACE);
    } catch (Throwable jjte000) {
          if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte000 instanceof RuntimeException) {
            {if (true) throw (RuntimeException)jjte000;}
          }
          if (jjte000 instanceof ParseException) {
            {if (true) throw (ParseException)jjte000;}
          }
          {if (true) throw (Error)jjte000;}
    } finally {
          if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
          }
    }
  }

  static final public void Circle() throws ParseException {
                 /*@bgen(jjtree) Circle */
  ASTCircle jjtn000 = new ASTCircle(JJTCIRCLE);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      jj_consume_token(CIRCLE);
      jj_consume_token(LBRACE);
      Int();
      Int();
      Int();
      jj_consume_token(RBRACE);
    } catch (Throwable jjte000) {
          if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte000 instanceof RuntimeException) {
            {if (true) throw (RuntimeException)jjte000;}
          }
          if (jjte000 instanceof ParseException) {
            {if (true) throw (ParseException)jjte000;}
          }
          {if (true) throw (Error)jjte000;}
    } finally {
          if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
          }
    }
  }

  static final public void Triangle() throws ParseException {
                   /*@bgen(jjtree) Triangle */
  ASTTriangle jjtn000 = new ASTTriangle(JJTTRIANGLE);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      jj_consume_token(TRIANGLE);
      jj_consume_token(LBRACE);
      Int();
      Int();
      Int();
      Int();
      Int();
      Int();
      jj_consume_token(RBRACE);
    } catch (Throwable jjte000) {
          if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte000 instanceof RuntimeException) {
            {if (true) throw (RuntimeException)jjte000;}
          }
          if (jjte000 instanceof ParseException) {
            {if (true) throw (ParseException)jjte000;}
          }
          {if (true) throw (Error)jjte000;}
    } finally {
          if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
          }
    }
  }

  static final public void Polygon() throws ParseException {
                  /*@bgen(jjtree) Polygon */
  ASTPolygon jjtn000 = new ASTPolygon(JJTPOLYGON);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      jj_consume_token(POLYGON);
      jj_consume_token(LBRACE);
      Int();
      Int();
      label_2:
      while (true) {
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case INT:
          ;
          break;
        default:
          jj_la1[3] = jj_gen;
          break label_2;
        }
        Int();
        Int();
      }
      jj_consume_token(RBRACE);
    } catch (Throwable jjte000) {
          if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte000 instanceof RuntimeException) {
            {if (true) throw (RuntimeException)jjte000;}
          }
          if (jjte000 instanceof ParseException) {
            {if (true) throw (ParseException)jjte000;}
          }
          {if (true) throw (Error)jjte000;}
    } finally {
          if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
          }
    }
  }

  static final public void Text() throws ParseException {
               /*@bgen(jjtree) Text */
  ASTText jjtn000 = new ASTText(JJTTEXT);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      jj_consume_token(TEXT);
      jj_consume_token(LBRACE);
      Int();
      Int();
      Int();
      Str();
      jj_consume_token(RBRACE);
    } catch (Throwable jjte000) {
          if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte000 instanceof RuntimeException) {
            {if (true) throw (RuntimeException)jjte000;}
          }
          if (jjte000 instanceof ParseException) {
            {if (true) throw (ParseException)jjte000;}
          }
          {if (true) throw (Error)jjte000;}
    } finally {
          if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
          }
    }
  }

  static final public void Colour() throws ParseException {
                 /*@bgen(jjtree) Colour */
  ASTColour jjtn000 = new ASTColour(JJTCOLOUR);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      jj_consume_token(COLOUR);
      Str();
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case STR:
      case LINE:
      case RECTANGLE:
      case SQUARE:
      case ELLIPSE:
      case CIRCLE:
      case TRIANGLE:
      case POLYGON:
      case TEXT:
      case COLOUR:
      case BRUSH:
      case OFFSET:
        Command();
        break;
      case 22:
        Segment();
        break;
      default:
        jj_la1[4] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    } catch (Throwable jjte000) {
          if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte000 instanceof RuntimeException) {
            {if (true) throw (RuntimeException)jjte000;}
          }
          if (jjte000 instanceof ParseException) {
            {if (true) throw (ParseException)jjte000;}
          }
          {if (true) throw (Error)jjte000;}
    } finally {
          if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
          }
    }
  }

  static final public void Brush() throws ParseException {
                /*@bgen(jjtree) Brush */
  ASTBrush jjtn000 = new ASTBrush(JJTBRUSH);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      jj_consume_token(BRUSH);
      jj_consume_token(LBRACE);
      Int();
      jj_consume_token(RBRACE);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case STR:
      case LINE:
      case RECTANGLE:
      case SQUARE:
      case ELLIPSE:
      case CIRCLE:
      case TRIANGLE:
      case POLYGON:
      case TEXT:
      case COLOUR:
      case BRUSH:
      case OFFSET:
        Command();
        break;
      case 22:
        Segment();
        break;
      default:
        jj_la1[5] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    } catch (Throwable jjte000) {
          if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte000 instanceof RuntimeException) {
            {if (true) throw (RuntimeException)jjte000;}
          }
          if (jjte000 instanceof ParseException) {
            {if (true) throw (ParseException)jjte000;}
          }
          {if (true) throw (Error)jjte000;}
    } finally {
          if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
          }
    }
  }

  static final public void Offset() throws ParseException {
                 /*@bgen(jjtree) Offset */
  ASTOffset jjtn000 = new ASTOffset(JJTOFFSET);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      jj_consume_token(OFFSET);
      jj_consume_token(LBRACE);
      Int();
      Int();
      jj_consume_token(RBRACE);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case STR:
      case LINE:
      case RECTANGLE:
      case SQUARE:
      case ELLIPSE:
      case CIRCLE:
      case TRIANGLE:
      case POLYGON:
      case TEXT:
      case COLOUR:
      case BRUSH:
      case OFFSET:
        Command();
        break;
      case 22:
        Segment();
        break;
      default:
        jj_la1[6] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    } catch (Throwable jjte000) {
          if (jjtc000) {
            jjtree.clearNodeScope(jjtn000);
            jjtc000 = false;
          } else {
            jjtree.popNode();
          }
          if (jjte000 instanceof RuntimeException) {
            {if (true) throw (RuntimeException)jjte000;}
          }
          if (jjte000 instanceof ParseException) {
            {if (true) throw (ParseException)jjte000;}
          }
          {if (true) throw (Error)jjte000;}
    } finally {
          if (jjtc000) {
            jjtree.closeNodeScope(jjtn000, true);
          }
    }
  }

  static final public void Int() throws ParseException {
                     Token t;
          ASTInt jjtn001 = new ASTInt(JJTINT);
          boolean jjtc001 = true;
          jjtree.openNodeScope(jjtn001);
    try {
      t = jj_consume_token(INT);
                  jjtree.closeNodeScope(jjtn001, true);
                  jjtc001 = false;
                        jjtn001.val = Integer.parseInt(t.image);
    } finally {
          if (jjtc001) {
            jjtree.closeNodeScope(jjtn001, true);
          }
    }
  }

  static final public void Str() throws ParseException {
                     Token t;
          ASTStr jjtn001 = new ASTStr(JJTSTR);
          boolean jjtc001 = true;
          jjtree.openNodeScope(jjtn001);
    try {
      t = jj_consume_token(STR);
                  jjtree.closeNodeScope(jjtn001, true);
                  jjtc001 = false;
                        jjtn001.val = t.image;
    } finally {
          if (jjtc001) {
            jjtree.closeNodeScope(jjtn001, true);
          }
    }
  }

  static private boolean jj_initialized_once = false;
  static public drawphase2TokenManager token_source;
  static SimpleCharStream jj_input_stream;
  static public Token token, jj_nt;
  static private int jj_ntk;
  static private int jj_gen;
  static final private int[] jj_la1 = new int[7];
  static private int[] jj_la1_0;
  static {
      jj_la1_0();
   }
   private static void jj_la1_0() {
      jj_la1_0 = new int[] {0x3ffa00,0x7ffa00,0x7ffa00,0x100,0x7ffa00,0x7ffa00,0x7ffa00,};
   }

  public drawphase2(java.io.InputStream stream) {
    if (jj_initialized_once) {
      System.out.println("ERROR: Second call to constructor of static parser.  You must");
      System.out.println("       either use ReInit() or set the JavaCC option STATIC to false");
      System.out.println("       during parser generation.");
      throw new Error();
    }
    jj_initialized_once = true;
    jj_input_stream = new SimpleCharStream(stream, 1, 1);
    token_source = new drawphase2TokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  static public void ReInit(java.io.InputStream stream) {
    jj_input_stream.ReInit(stream, 1, 1);
    token_source.ReInit(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jjtree.reset();
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  public drawphase2(java.io.Reader stream) {
    if (jj_initialized_once) {
      System.out.println("ERROR: Second call to constructor of static parser.  You must");
      System.out.println("       either use ReInit() or set the JavaCC option STATIC to false");
      System.out.println("       during parser generation.");
      throw new Error();
    }
    jj_initialized_once = true;
    jj_input_stream = new SimpleCharStream(stream, 1, 1);
    token_source = new drawphase2TokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  static 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;
    jjtree.reset();
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  public drawphase2(drawphase2TokenManager tm) {
    if (jj_initialized_once) {
      System.out.println("ERROR: Second call to constructor of static parser.  You must");
      System.out.println("       either use ReInit() or set the JavaCC option STATIC to false");
      System.out.println("       during parser generation.");
      throw new Error();
    }
    jj_initialized_once = true;
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  public void ReInit(drawphase2TokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jjtree.reset();
    jj_gen = 0;
    for (int i = 0; i < 7; i++) jj_la1[i] = -1;
  }

  static final private Token jj_consume_token(int kind) throws ParseException {
    Token oldToken;
    if ((oldToken = token).next != null) token = token.next;
    else token = token.next = token_source.getNextToken();
    jj_ntk = -1;
    if (token.kind == kind) {
      jj_gen++;
      return token;
    }
    token = oldToken;
    jj_kind = kind;
    throw generateParseException();
  }

  static final public Token getNextToken() {
    if (token.next != null) token = token.next;
    else token = token.next = token_source.getNextToken();
    jj_ntk = -1;
    jj_gen++;
    return token;
  }

  static final public Token getToken(int index) {
    Token t = token;
    for (int i = 0; i < index; i++) {
      if (t.next != null) t = t.next;
      else t = t.next = token_source.getNextToken();
    }
    return t;
  }

  static final private int jj_ntk() {
    if ((jj_nt=token.next) == null)
      return (jj_ntk = (token.next=token_source.getNextToken()).kind);
    else
      return (jj_ntk = jj_nt.kind);
  }

  static private java.util.Vector jj_expentries = new java.util.Vector();
  static private int[] jj_expentry;
  static private int jj_kind = -1;

  static public ParseException generateParseException() {
    jj_expentries.removeAllElements();
    boolean[] la1tokens = new boolean[24];
    for (int i = 0; i < 24; i++) {
      la1tokens[i] = false;
    }
    if (jj_kind >= 0) {
      la1tokens[jj_kind] = true;
      jj_kind = -1;
    }
    for (int i = 0; i < 7; i++) {
      if (jj_la1[i] == jj_gen) {
        for (int j = 0; j < 32; j++) {
          if ((jj_la1_0[i] & (1<<j)) != 0) {
            la1tokens[j] = true;
          }
        }
      }
    }
    for (int i = 0; i < 24; i++) {
      if (la1tokens[i]) {
        jj_expentry = new int[1];
        jj_expentry[0] = i;
        jj_expentries.addElement(jj_expentry);
      }
    }
    int[][] exptokseq = new int[jj_expentries.size()][];
    for (int i = 0; i < jj_expentries.size(); i++) {
      exptokseq[i] = (int[])jj_expentries.elementAt(i);
    }
    return new ParseException(token, exptokseq, tokenImage);
  }

  static final public void enable_tracing() {
  }

  static final public void disable_tracing() {
  }

}
