/* EGTGrammar.java */
/* Generated By:JavaCC: Do not edit this line. EGTGrammar.java */
package grammars.fm;

import grammars.fm.visitor.*;
import grammars.fm.syntaxtree.*;


public class EGTGrammar implements EGTGrammarConstants {


  /* --- User code --- */

  public static void main(String args[]) {
    System.err.flush();
    System.out.println("EGTGrammar Reading...");
    EGTGrammar egtg = new EGTGrammar(System.in);
    try {
      System.out.println("... Parsing...");
      classDeclaration cd = egtg.classDeclaration();
      IVis2Visitor v = new DepthFirstVis2Visitor();
      System.out.println("... Visiting...");
      int rc = cd.accept(v, "  ");
      System.out.println("EGTGrammar ended.");
      System.exit(0);
    }
    catch (final Exception e) {
      System.out.flush();
      System.err.println("Oops!");
      System.err.println(e.getMessage());
      System.exit(-1);
    }
  }

  final public classDeclaration classDeclaration() throws ParseException {// --- JTB generated node declarations ---
  skip n0 = null;
  Token n1 = null;
  Token n2 = null;
  NodeListOptional n3 = new NodeListOptional();
  method n4 = null;
  Token n5 = null;
  Token n6 = null;
  Token n7 = null;
  classDeclaration jtbNode = null;
    // --- user BNFProduction ExpansionChoices ---
      n0 = skip();
    n1 = jj_consume_token(1);
    className();
    n2 = jj_consume_token(2);
    label_1:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
      case ID:{
        ;
        break;
        }
      default:
        jj_la1[0] = jj_gen;
        break label_1;
      }
      n4 = method();
n3.addNode(n4);
    }
n3.nodes.trimToSize();
    n5 = jj_consume_token(3);
    n6 = jj_consume_token(4);
    n7 = jj_consume_token(0);
n7.beginColumn++;
n7.endColumn++;
jtbNode = new classDeclaration(n0, n1, n2, n3, n5, n6, n7);
{if ("" != null) return jtbNode;}
    throw new Error("Missing return statement in function");
}

  final public className className() throws ParseException {// --- JTB generated node declarations ---
  Token n0 = null;
  className jtbNode = null;
  // --- user BNFProduction java block ---
  char b, e = '\u0000';
    // --- user BNFProduction ExpansionChoices ---
      n0 = jj_consume_token(ID);
b = '\b';
jtbNode = new className(n0);
{if ("" != null) return jtbNode;}
    throw new Error("Missing return statement in function");
}

  final public method method() throws ParseException {// --- JTB generated node declarations ---
  methodName n0 = null;
  Token n1 = null;
  NodeList n2 = new NodeList();
  instruction n3 = null;
  Token n4 = null;
  method jtbNode = null;
    // --- user BNFProduction ExpansionChoices ---
      n0 = methodName();
    n1 = jj_consume_token(5);
    label_2:
    while (true) {
      n3 = instruction();
n2.addNode(n3);
      switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
      case ID:{
        ;
        break;
        }
      default:
        jj_la1[1] = jj_gen;
        break label_2;
      }
    }
n2.nodes.trimToSize();
    n4 = jj_consume_token(6);
jtbNode = new method(n0, n1, n2, n4);
{if ("" != null) return jtbNode;}
    throw new Error("Missing return statement in function");
}

  final public methodName methodName() throws ParseException {// --- JTB generated node declarations ---
  Token n0 = null;
  methodName jtbNode = null;
    // --- user BNFProduction ExpansionChoices ---
      n0 = jj_consume_token(ID);
jtbNode = new methodName(n0);
{if ("" != null) return jtbNode;}
    throw new Error("Missing return statement in function");
}

  final public instruction instruction() throws ParseException {// --- JTB generated node declarations ---
  Token n0 = null;
  Token n1 = null;
  instruction jtbNode = null;
    // --- user BNFProduction ExpansionChoices ---
      n0 = jj_consume_token(ID);
    n1 = jj_consume_token(7);
jtbNode = new instruction(n0, n1);
{if ("" != null) return jtbNode;}
    throw new Error("Missing return statement in function");
}

  skip skip() throws ParseException {Token tk = getNextToken();
  return new skip();
  }

  /** Generated Token Manager. */
  public EGTGrammarTokenManager 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[2];
  static private int[] jj_la1_0;
  static {
	   jj_la1_init_0();
	}
	private static void jj_la1_init_0() {
	   jj_la1_0 = new int[] {0x800,0x800,};
	}

  /** Constructor with InputStream. */
  public EGTGrammar(java.io.InputStream stream) {
	  this(stream, null);
  }
  /** Constructor with InputStream and supplied encoding */
  public EGTGrammar(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 EGTGrammarTokenManager(jj_input_stream);
	 token = new Token();
	 jj_ntk = -1;
	 jj_gen = 0;
	 for (int i = 0; i < 2; 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 < 2; i++) jj_la1[i] = -1;
  }

  /** Constructor. */
  public EGTGrammar(java.io.Reader stream) {
	 jj_input_stream = new SimpleCharStream(stream, 1, 1);
	 token_source = new EGTGrammarTokenManager(jj_input_stream);
	 token = new Token();
	 jj_ntk = -1;
	 jj_gen = 0;
	 for (int i = 0; i < 2; i++) jj_la1[i] = -1;
  }

  /** Reinitialise. */
  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 EGTGrammarTokenManager(jj_input_stream);
	}

	 token_source.ReInit(jj_input_stream);
	 token = new Token();
	 jj_ntk = -1;
	 jj_gen = 0;
	 for (int i = 0; i < 2; i++) jj_la1[i] = -1;
  }

  /** Constructor with generated Token Manager. */
  public EGTGrammar(EGTGrammarTokenManager tm) {
	 token_source = tm;
	 token = new Token();
	 jj_ntk = -1;
	 jj_gen = 0;
	 for (int i = 0; i < 2; i++) jj_la1[i] = -1;
  }

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

  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. */
  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. */
  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;
  }

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

  private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>();
  private int[] jj_expentry;
  private int jj_kind = -1;

  /** Generate ParseException. */
  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 < 2; 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);
  }

  private boolean trace_enabled;

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

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

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

}
