/* Generated By:JavaCC: Do not edit this line. CalcParser.java */
import syntaxtree.*;
import java.util.Vector;


public class CalcParser implements CalcParserConstants {

  static final public Goal Goal() throws ParseException {
   AdditiveExpression n0;
   NodeToken n1;
   Token n2;
    n0 = AdditiveExpression();
    n2 = jj_consume_token(0);
      n2.beginColumn++; n2.endColumn++;
      n1 = JTBToolkit.makeNodeToken(n2);
     {if (true) return new Goal(n0,n1);}
    throw new Error("Missing return statement in function");
  }

  static final public AdditiveExpression AdditiveExpression() throws ParseException {
   MultiplicativeExpression n0;
   AdditiveExpressionTail n1;
    n0 = MultiplicativeExpression();
    n1 = AdditiveExpressionTail();
     {if (true) return new AdditiveExpression(n0,n1);}
    throw new Error("Missing return statement in function");
  }

  static final public AdditiveExpressionTail AdditiveExpressionTail() throws ParseException {
   NodeListOptional n0 = new NodeListOptional();
   AdditiveExpressionTerm n1;
    label_1:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case PLUS:
      case MINUS:
        ;
        break;
      default:
        jj_la1[0] = jj_gen;
        break label_1;
      }
      n1 = AdditiveExpressionTerm();
        n0.addNode(n1);
    }
     n0.nodes.trimToSize();
     {if (true) return new AdditiveExpressionTail(n0);}
    throw new Error("Missing return statement in function");
  }

  static final public AdditiveExpressionTerm AdditiveExpressionTerm() throws ParseException {
   NodeChoice n0;
   PlusExpression n1;
   MinusExpression n2;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case PLUS:
      n1 = PlusExpression();
        n0 = new NodeChoice(n1, 0);
      break;
    case MINUS:
      n2 = MinusExpression();
        n0 = new NodeChoice(n2, 1);
      break;
    default:
      jj_la1[1] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
     {if (true) return new AdditiveExpressionTerm(n0);}
    throw new Error("Missing return statement in function");
  }

  static final public PlusExpression PlusExpression() throws ParseException {
   NodeToken n0;
   Token n1;
   MultiplicativeExpression n2;
    n1 = jj_consume_token(PLUS);
            n0 = JTBToolkit.makeNodeToken(n1);
    n2 = MultiplicativeExpression();
     {if (true) return new PlusExpression(n0,n2);}
    throw new Error("Missing return statement in function");
  }

  static final public MinusExpression MinusExpression() throws ParseException {
   NodeToken n0;
   Token n1;
   MultiplicativeExpression n2;
    n1 = jj_consume_token(MINUS);
            n0 = JTBToolkit.makeNodeToken(n1);
    n2 = MultiplicativeExpression();
     {if (true) return new MinusExpression(n0,n2);}
    throw new Error("Missing return statement in function");
  }

  static final public MultiplicativeExpression MultiplicativeExpression() throws ParseException {
   PrimaryExpression n0;
   MultiplicativeExpressionTail n1;
    n0 = PrimaryExpression();
    n1 = MultiplicativeExpressionTail();
     {if (true) return new MultiplicativeExpression(n0,n1);}
    throw new Error("Missing return statement in function");
  }

  static final public MultiplicativeExpressionTail MultiplicativeExpressionTail() throws ParseException {
   NodeListOptional n0 = new NodeListOptional();
   MultiplicativeExpressionTerm n1;
    label_2:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case MULT:
      case DIV:
        ;
        break;
      default:
        jj_la1[2] = jj_gen;
        break label_2;
      }
      n1 = MultiplicativeExpressionTerm();
        n0.addNode(n1);
    }
     n0.nodes.trimToSize();
     {if (true) return new MultiplicativeExpressionTail(n0);}
    throw new Error("Missing return statement in function");
  }

  static final public MultiplicativeExpressionTerm MultiplicativeExpressionTerm() throws ParseException {
   NodeChoice n0;
   MultExpression n1;
   DivExpression n2;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case MULT:
      n1 = MultExpression();
        n0 = new NodeChoice(n1, 0);
      break;
    case DIV:
      n2 = DivExpression();
        n0 = new NodeChoice(n2, 1);
      break;
    default:
      jj_la1[3] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
     {if (true) return new MultiplicativeExpressionTerm(n0);}
    throw new Error("Missing return statement in function");
  }

  static final public MultExpression MultExpression() throws ParseException {
   NodeToken n0;
   Token n1;
   PrimaryExpression n2;
    n1 = jj_consume_token(MULT);
            n0 = JTBToolkit.makeNodeToken(n1);
    n2 = PrimaryExpression();
     {if (true) return new MultExpression(n0,n2);}
    throw new Error("Missing return statement in function");
  }

  static final public DivExpression DivExpression() throws ParseException {
   NodeToken n0;
   Token n1;
   PrimaryExpression n2;
    n1 = jj_consume_token(DIV);
            n0 = JTBToolkit.makeNodeToken(n1);
    n2 = PrimaryExpression();
     {if (true) return new DivExpression(n0,n2);}
    throw new Error("Missing return statement in function");
  }

  static final public PrimaryExpression PrimaryExpression() throws ParseException {
   NodeChoice n0;
   Constant n1;
   BracketExpression n2;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case NUMBER:
      n1 = Constant();
        n0 = new NodeChoice(n1, 0);
      break;
    case LPAR:
      n2 = BracketExpression();
        n0 = new NodeChoice(n2, 1);
      break;
    default:
      jj_la1[4] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
     {if (true) return new PrimaryExpression(n0);}
    throw new Error("Missing return statement in function");
  }

  static final public BracketExpression BracketExpression() throws ParseException {
   NodeToken n0;
   Token n1;
   AdditiveExpression n2;
   NodeToken n3;
   Token n4;
    n1 = jj_consume_token(LPAR);
            n0 = JTBToolkit.makeNodeToken(n1);
    n2 = AdditiveExpression();
    n4 = jj_consume_token(RPAR);
            n3 = JTBToolkit.makeNodeToken(n4);
     {if (true) return new BracketExpression(n0,n2,n3);}
    throw new Error("Missing return statement in function");
  }

  static final public Constant Constant() throws ParseException {
   NodeToken n0;
   Token n1;
    n1 = jj_consume_token(NUMBER);
                 n0 = JTBToolkit.makeNodeToken(n1);
     {if (true) return new Constant(n0);}
    throw new Error("Missing return statement in function");
  }

  static private boolean jj_initialized_once = false;
  /** Generated Token Manager. */
  static public CalcParserTokenManager token_source;
  static JavaCharStream jj_input_stream;
  /** Current token. */
  static public Token token;
  /** Next token. */
  static public Token jj_nt;
  static private int jj_ntk;
  static private int jj_gen;
  static final private int[] jj_la1 = new int[5];
  static private int[] jj_la1_0;
  static {
      jj_la1_init_0();
   }
   private static void jj_la1_init_0() {
      jj_la1_0 = new int[] {0x300,0x300,0xc00,0xc00,0x1040,};
   }

  /** Constructor with InputStream. */
  public CalcParser(java.io.InputStream stream) {
     this(stream, null);
  }
  /** Constructor with InputStream and supplied encoding */
  public CalcParser(java.io.InputStream stream, String encoding) {
    if (jj_initialized_once) {
      System.out.println("ERROR: Second call to constructor of static parser.  ");
      System.out.println("       You must either use ReInit() or set the JavaCC option STATIC to false");
      System.out.println("       during parser generation.");
      throw new Error();
    }
    jj_initialized_once = true;
    try { jj_input_stream = new JavaCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
    token_source = new CalcParserTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 5; i++) jj_la1[i] = -1;
  }

  /** Reinitialise. */
  static public void ReInit(java.io.InputStream stream) {
     ReInit(stream, null);
  }
  /** Reinitialise. */
  static 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 < 5; i++) jj_la1[i] = -1;
  }

  /** Constructor. */
  public CalcParser(java.io.Reader stream) {
    if (jj_initialized_once) {
      System.out.println("ERROR: Second call to constructor of static parser. ");
      System.out.println("       You must 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 JavaCharStream(stream, 1, 1);
    token_source = new CalcParserTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 5; i++) jj_la1[i] = -1;
  }

  /** Reinitialise. */
  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;
    jj_gen = 0;
    for (int i = 0; i < 5; i++) jj_la1[i] = -1;
  }

  /** Constructor with generated Token Manager. */
  public CalcParser(CalcParserTokenManager tm) {
    if (jj_initialized_once) {
      System.out.println("ERROR: Second call to constructor of static parser. ");
      System.out.println("       You must 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 < 5; i++) jj_la1[i] = -1;
  }

  /** Reinitialise. */
  public void ReInit(CalcParserTokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 5; i++) jj_la1[i] = -1;
  }

  static 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();
  }


/** Get the next Token. */
  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;
  }

/** Get the specific 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 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.List<int[]> jj_expentries = new java.util.ArrayList<int[]>();
  static private int[] jj_expentry;
  static private int jj_kind = -1;

  /** Generate ParseException. */
  static public ParseException generateParseException() {
    jj_expentries.clear();
    boolean[] la1tokens = new boolean[13];
    if (jj_kind >= 0) {
      la1tokens[jj_kind] = true;
      jj_kind = -1;
    }
    for (int i = 0; i < 5; 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 < 13; i++) {
      if (la1tokens[i]) {
        jj_expentry = new int[1];
        jj_expentry[0] = i;
        jj_expentries.add(jj_expentry);
      }
    }
    int[][] exptokseq = new int[jj_expentries.size()][];
    for (int i = 0; i < jj_expentries.size(); i++) {
      exptokseq[i] = jj_expentries.get(i);
    }
    return new ParseException(token, exptokseq, tokenImage);
  }

  /** Enable tracing. */
  static final public void enable_tracing() {
  }

  /** Disable tracing. */
  static final public void disable_tracing() {
  }

}

class JTBToolkit {
   static NodeToken makeNodeToken(Token t) {
      return new NodeToken(t.image.intern(), t.kind, t.beginLine, t.beginColumn, t.endLine, t.endColumn);
   }
}
