/* Eg2.java */
/* Generated By:JavaCC: Do not edit this line. Eg2.java */
package examples.java.ex2jtb;

import examples.java.ex2jtb.visitor.*;
import examples.java.ex2jtb.syntaxtree.*;
import examples.java.ex2jtb.hook.*;


public class Eg2 implements Eg2Constants {

  /** The hook for enter / exit node scope hook methods (to be instantiated) */
static   public IEnterExitHook jtb_eeh;


  /** Return variable for the {@link #jc_1} JavaCodeProduction) */
  static int jtbrt_jc_1;

  public static void main(String args[]) {
    System.err.flush();
    System.out.println("Reading from standard input (JTB version)...");
    Eg2 t = new Eg2(System.in);
    try {
      DumpVisitor v = new DumpVisitor();
      ASTStart n = t.ASTStart();
      n.accept(v, "");
      System.out.println("Thank you.");
      System.exit(0);
    }
    catch (Exception e) {
      System.out.flush();
      System.err.println("Oops.");
      System.err.println(e.getMessage());
      e.printStackTrace();
      System.exit(-1);
    }
  }

  static final public ASTStart ASTStart() throws ParseException {ASTExpression n0 = null;
  Token n1 = null;
  ASTStart jtbNode = null;
if (jtb_eeh != null) jtb_eeh.ASTStartEnter();
    n0 = ASTExpression();
    n1 = jj_consume_token(14);
jtbNode = new ASTStart(n0, n1);
if (jtb_eeh != null) jtb_eeh.ASTStartExit(jtbNode);
{if ("" != null) return jtbNode;}
    throw new Error("Missing return statement in function");
}

  static final public ASTExpression ASTExpression() throws ParseException {ASTAdditiveExpression n0 = null;
  ASTExpression jtbNode = null;
if (jtb_eeh != null) jtb_eeh.ASTExpressionEnter();
    n0 = ASTAdditiveExpression();
jtbNode = new ASTExpression(n0);
if (jtb_eeh != null) jtb_eeh.ASTExpressionExit(jtbNode);
{if ("" != null) return jtbNode;}
    throw new Error("Missing return statement in function");
}

  static final public ASTAdditiveExpression ASTAdditiveExpression() throws ParseException {ASTMultiplicativeExpression n0 = null;
  NodeListOptional n1 = new NodeListOptional();
  NodeSequence n2 = null;
  NodeChoice n3 = null;
  Token n4 = null;
  Token n5 = null;
  ASTMultiplicativeExpression n6 = null;
  ASTAdditiveExpression jtbNode = null;
if (jtb_eeh != null) jtb_eeh.ASTAdditiveExpressionEnter();
    n0 = ASTMultiplicativeExpression();
    label_1:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
      case 15:
      case 16:{
        ;
        break;
        }
      default:
        jj_la1[0] = jj_gen;
        break label_1;
      }
n2 = new NodeSequence(2);
      switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
      case 15:{
        n4 = jj_consume_token(15);
n3 = new NodeChoice(n4, 0, 2);
        break;
        }
      case 16:{
        n5 = jj_consume_token(16);
n3 = new NodeChoice(n5, 1, 2);
        break;
        }
      default:
        jj_la1[1] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
n2.addNode(n3);
      n6 = ASTMultiplicativeExpression();
n2.addNode(n6);
n1.addNode(n2);
    }
n1.nodes.trimToSize();
jtbNode = new ASTAdditiveExpression(n0, n1);
if (jtb_eeh != null) jtb_eeh.ASTAdditiveExpressionExit(jtbNode);
{if ("" != null) return jtbNode;}
    throw new Error("Missing return statement in function");
}

  static final public ASTMultiplicativeExpression ASTMultiplicativeExpression() throws ParseException {ASTUnaryExpression n0 = null;
  NodeListOptional n1 = new NodeListOptional();
  NodeSequence n2 = null;
  NodeChoice n3 = null;
  Token n4 = null;
  Token n5 = null;
  Token n6 = null;
  ASTUnaryExpression n7 = null;
  ASTMultiplicativeExpression jtbNode = null;
if (jtb_eeh != null) jtb_eeh.ASTMultiplicativeExpressionEnter();
    n0 = ASTUnaryExpression();
    label_2:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
      case 17:
      case 18:
      case 19:{
        ;
        break;
        }
      default:
        jj_la1[2] = jj_gen;
        break label_2;
      }
n2 = new NodeSequence(2);
      switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
      case 17:{
        n4 = jj_consume_token(17);
n3 = new NodeChoice(n4, 0, 3);
        break;
        }
      case 18:{
        n5 = jj_consume_token(18);
n3 = new NodeChoice(n5, 1, 3);
        break;
        }
      case 19:{
        n6 = jj_consume_token(19);
n3 = new NodeChoice(n6, 2, 3);
        break;
        }
      default:
        jj_la1[3] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
n2.addNode(n3);
      n7 = ASTUnaryExpression();
n2.addNode(n7);
n1.addNode(n2);
    }
n1.nodes.trimToSize();
jtbNode = new ASTMultiplicativeExpression(n0, n1);
if (jtb_eeh != null) jtb_eeh.ASTMultiplicativeExpressionExit(jtbNode);
{if ("" != null) return jtbNode;}
    throw new Error("Missing return statement in function");
}

  static final public ASTUnaryExpression ASTUnaryExpression() throws ParseException {NodeChoice n0 = null;
  NodeSequence n1 = null;
  Token n2 = null;
  ASTExpression n3 = null;
  Token n4 = null;
  ASTMyID n5 = null;
  ASTInteger n6 = null;
  ASTUnaryExpression jtbNode = null;
if (jtb_eeh != null) jtb_eeh.ASTUnaryExpressionEnter();
    switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
    case 20:{
n1 = new NodeSequence(3);
      n2 = jj_consume_token(20);
n1.addNode(n2);
      n3 = ASTExpression();
n1.addNode(n3);
      n4 = jj_consume_token(21);
n1.addNode(n4);
n0 = new NodeChoice(n1, 0, 3);
      break;
      }
    case IDENTIFIER:{
      n5 = ASTMyID();
n0 = new NodeChoice(n5, 1, 3);
n5.f0.image = "reset";
      break;
      }
    case INTEGER_LITERAL:{
      n6 = ASTInteger();
n0 = new NodeChoice(n6, 2, 3);
      break;
      }
    default:
      jj_la1[4] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
jtbNode = new ASTUnaryExpression(n0);
if (jtb_eeh != null) jtb_eeh.ASTUnaryExpressionExit(jtbNode);
{if ("" != null) return jtbNode;}
    throw new Error("Missing return statement in function");
}

  static final public ASTMyID ASTMyID() throws ParseException {Token n0 = null;
  ASTMyID jtbNode = null;
  Token t = null;
if (jtb_eeh != null) jtb_eeh.ASTMyIDEnter();
    n0 = jj_consume_token(IDENTIFIER);
t = n0;
n0.image = t.image + " modified";
    jc_0();
jtbNode = new ASTMyID(n0);
if (jtb_eeh != null) jtb_eeh.ASTMyIDExit(jtbNode);
{if ("" != null) return jtbNode;}
    throw new Error("Missing return statement in function");
}

  static final public ASTInteger ASTInteger() throws ParseException {Token n0 = null;
  ASTjc_1 n1 = null;
  ASTInteger jtbNode = null;
if (jtb_eeh != null) jtb_eeh.ASTIntegerEnter();
    n0 = jj_consume_token(INTEGER_LITERAL);
    n1 = ASTjc_1();
jtbNode = new ASTInteger(n0, n1);
if (jtb_eeh != null) jtb_eeh.ASTIntegerExit(jtbNode);
{if ("" != null) return jtbNode;}
    throw new Error("Missing return statement in function");
}

  static int jc_0() throws ParseException {int i = 0;
  return i;
  }

  static ASTjc_1 ASTjc_1() throws ParseException {if (jtb_eeh != null) jtb_eeh.ASTjc_1Enter();
  int j = 0;jtbrt_jc_1 = j;
  ASTjc_1 jtbNode = new ASTjc_1();
  if (jtb_eeh != null) jtb_eeh.ASTjc_1Exit(jtbNode);
  return jtbNode;
  }

  static private boolean jj_initialized_once = false;
  /** Generated Token Manager. */
  static public Eg2TokenManager token_source;
  static SimpleCharStream 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[] {0x18000,0x18000,0xe0000,0xe0000,0x100880,};
	}

  /** Constructor with InputStream. */
  public Eg2(java.io.InputStream stream) {
	  this(stream, null);
  }
  /** Constructor with InputStream and supplied encoding */
  public Eg2(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 SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
	 token_source = new Eg2TokenManager(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 Eg2(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 SimpleCharStream(stream, 1, 1);
	 token_source = new Eg2TokenManager(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) {
	if (jj_input_stream == null) {
	   jj_input_stream = new SimpleCharStream(stream, 1, 1);
	} else {
	   jj_input_stream.ReInit(stream, 1, 1);
	}
	if (token_source == null) {
 token_source = new Eg2TokenManager(jj_input_stream);
	}

	 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 Eg2(Eg2TokenManager 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(Eg2TokenManager 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_f() {
	 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[22];
	 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 < 22; 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);
  }

  static private boolean trace_enabled;

/** Trace enabled. */
  static final public boolean trace_enabled() {
	 return trace_enabled;
  }

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

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

}
