Click here to Skip to main content
15,891,136 members
Articles / Programming Languages / Java

Create Your Own Programming Language

Rate me:
Please Sign up or sign in to vote.
4.87/5 (53 votes)
21 Jan 2010CPOL12 min read 487.2K   15.4K   87  
I've created my own programming language called Alef++ for fun, and for better understanding: What is a programing language? How does it work? Can I can create my own?
/* Generated By:JavaCC: Do not edit this line. St4tic.java */
package st4tic;

import st4tic.syntaxtree.*;
import st4tic.visitor.*;
import st4tic.interpreter.*;
import java.util.Vector;


public class St4tic implements St4ticConstants {

  final public Start Start() throws ParseException {
   NodeList n0 = new NodeList();
   NodeSequence n1;
   Require n2;
   NodeToken n3;
   Token n4;
   NodeListOptional n5 = new NodeListOptional();
   StatementExpression n6;
    label_1:
    while (true) {
        n1 = new NodeSequence(2);
      n2 = Require();
        n1.addNode(n2);
      n4 = jj_consume_token(DOT);
               n3 = JTBToolkit.makeNodeToken(n4);
        n1.addNode(n3);
        n0.addNode(n1);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case REQUERE:
        ;
        break;
      default:
        jj_la1[0] = jj_gen;
        break label_1;
      }
    }
     n0.nodes.trimToSize();
    label_2:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case IF:
      case WHILE:
      case DEF:
      case IDENTIFIER:
        ;
        break;
      default:
        jj_la1[1] = jj_gen;
        break label_2;
      }
      n6 = StatementExpression();
        n5.addNode(n6);
    }
     n5.nodes.trimToSize();
     {if (true) return new Start(n0,n5);}
    throw new Error("Missing return statement in function");
  }

  final public Require Require() throws ParseException {
   NodeToken n0;
   Token n1;
   NodeList n2 = new NodeList();
   NodeToken n3;
   Token n4;
    n1 = jj_consume_token(REQUERE);
                  n0 = JTBToolkit.makeNodeToken(n1);
    label_3:
    while (true) {
      n4 = jj_consume_token(IDENTIFIER);
                        n3 = JTBToolkit.makeNodeToken(n4);
        n2.addNode(n3);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case IDENTIFIER:
        ;
        break;
      default:
        jj_la1[2] = jj_gen;
        break label_3;
      }
    }
     n2.nodes.trimToSize();
     {if (true) return new Require(n0,n2);}
    throw new Error("Missing return statement in function");
  }

  final public MathExpression MathExpression() throws ParseException {
   AdditiveExpression n0;
    n0 = AdditiveExpression();
     {if (true) return new MathExpression(n0);}
    throw new Error("Missing return statement in function");
  }

  final public AdditiveExpression AdditiveExpression() throws ParseException {
   MultiplicativeExpression n0;
   NodeListOptional n1 = new NodeListOptional();
   NodeSequence n2;
   NodeChoice n3;
   NodeToken n4;
   Token n5;
   NodeToken n6;
   Token n7;
   MultiplicativeExpression n8;
    n0 = MultiplicativeExpression();
    label_4:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case PLUS:
      case MINUS:
        ;
        break;
      default:
        jj_la1[3] = jj_gen;
        break label_4;
      }
        n2 = new NodeSequence(2);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case PLUS:
        n5 = jj_consume_token(PLUS);
                     n4 = JTBToolkit.makeNodeToken(n5);
              n3 = new NodeChoice(n4, 0);
        break;
      case MINUS:
        n7 = jj_consume_token(MINUS);
                     n6 = JTBToolkit.makeNodeToken(n7);
              n3 = new NodeChoice(n6, 1);
        break;
      default:
        jj_la1[4] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
        n2.addNode(n3);
      n8 = MultiplicativeExpression();
        n2.addNode(n8);
        n1.addNode(n2);
    }
     n1.nodes.trimToSize();
     {if (true) return new AdditiveExpression(n0,n1);}
    throw new Error("Missing return statement in function");
  }

  final public MultiplicativeExpression MultiplicativeExpression() throws ParseException {
   UnaryExpression n0;
   NodeListOptional n1 = new NodeListOptional();
   NodeSequence n2;
   NodeChoice n3;
   NodeToken n4;
   Token n5;
   NodeToken n6;
   Token n7;
   NodeToken n8;
   Token n9;
   UnaryExpression n10;
    n0 = UnaryExpression();
    label_5:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case MUL:
      case DIV:
      case MOD:
        ;
        break;
      default:
        jj_la1[5] = jj_gen;
        break label_5;
      }
        n2 = new NodeSequence(2);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case MUL:
        n5 = jj_consume_token(MUL);
                     n4 = JTBToolkit.makeNodeToken(n5);
              n3 = new NodeChoice(n4, 0);
        break;
      case DIV:
        n7 = jj_consume_token(DIV);
                     n6 = JTBToolkit.makeNodeToken(n7);
              n3 = new NodeChoice(n6, 1);
        break;
      case MOD:
        n9 = jj_consume_token(MOD);
                     n8 = JTBToolkit.makeNodeToken(n9);
              n3 = new NodeChoice(n8, 2);
        break;
      default:
        jj_la1[6] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
        n2.addNode(n3);
      n10 = UnaryExpression();
        n2.addNode(n10);
        n1.addNode(n2);
    }
     n1.nodes.trimToSize();
     {if (true) return new MultiplicativeExpression(n0,n1);}
    throw new Error("Missing return statement in function");
  }

  final public UnaryExpression UnaryExpression() throws ParseException {
   NodeChoice n0;
   NodeSequence n1;
   NodeToken n2;
   Token n3;
   MathExpression n4;
   NodeToken n5;
   Token n6;
   NodeToken n7;
   Token n8;
   VariableName n9;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case 30:
        n1 = new NodeSequence(3);
      n3 = jj_consume_token(30);
               n2 = JTBToolkit.makeNodeToken(n3);
        n1.addNode(n2);
      n4 = MathExpression();
        n1.addNode(n4);
      n6 = jj_consume_token(31);
               n5 = JTBToolkit.makeNodeToken(n6);
        n1.addNode(n5);
        n0 = new NodeChoice(n1, 0);
      break;
    case INTEGER_LITERAL:
      n8 = jj_consume_token(INTEGER_LITERAL);
                             n7 = JTBToolkit.makeNodeToken(n8);
        n0 = new NodeChoice(n7, 1);
      break;
    case IDENTIFIER:
      n9 = VariableName();
        n0 = new NodeChoice(n9, 2);
      break;
    default:
      jj_la1[7] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
     {if (true) return new UnaryExpression(n0);}
    throw new Error("Missing return statement in function");
  }

  final public RelationalExprssion RelationalExprssion() throws ParseException {
   RelationalEqualityExpression n0;
    n0 = RelationalEqualityExpression();
     {if (true) return new RelationalExprssion(n0);}
    throw new Error("Missing return statement in function");
  }

  final public RelationalEqualityExpression RelationalEqualityExpression() throws ParseException {
   RelationalGreaterExpression n0;
   NodeOptional n1 = new NodeOptional();
   NodeSequence n2;
   NodeChoice n3;
   NodeToken n4;
   Token n5;
   NodeToken n6;
   Token n7;
   RelationalGreaterExpression n8;
    n0 = RelationalGreaterExpression();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case EQ:
    case NE:
        n2 = new NodeSequence(2);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case EQ:
        n5 = jj_consume_token(EQ);
                      n4 = JTBToolkit.makeNodeToken(n5);
              n3 = new NodeChoice(n4, 0);
        break;
      case NE:
        n7 = jj_consume_token(NE);
                      n6 = JTBToolkit.makeNodeToken(n7);
              n3 = new NodeChoice(n6, 1);
        break;
      default:
        jj_la1[8] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
        n2.addNode(n3);
      n8 = RelationalGreaterExpression();
        n2.addNode(n8);
        n1.addNode(n2);
      break;
    default:
      jj_la1[9] = jj_gen;
      ;
    }
     {if (true) return new RelationalEqualityExpression(n0,n1);}
    throw new Error("Missing return statement in function");
  }

  final public RelationalGreaterExpression RelationalGreaterExpression() throws ParseException {
   RelationalLessExpression n0;
   NodeOptional n1 = new NodeOptional();
   NodeSequence n2;
   NodeChoice n3;
   NodeToken n4;
   Token n5;
   NodeToken n6;
   Token n7;
   RelationalLessExpression n8;
    n0 = RelationalLessExpression();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case GT:
    case GE:
        n2 = new NodeSequence(2);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case GT:
        n5 = jj_consume_token(GT);
                     n4 = JTBToolkit.makeNodeToken(n5);
              n3 = new NodeChoice(n4, 0);
        break;
      case GE:
        n7 = jj_consume_token(GE);
                      n6 = JTBToolkit.makeNodeToken(n7);
              n3 = new NodeChoice(n6, 1);
        break;
      default:
        jj_la1[10] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
        n2.addNode(n3);
      n8 = RelationalLessExpression();
        n2.addNode(n8);
        n1.addNode(n2);
      break;
    default:
      jj_la1[11] = jj_gen;
      ;
    }
     {if (true) return new RelationalGreaterExpression(n0,n1);}
    throw new Error("Missing return statement in function");
  }

  final public RelationalLessExpression RelationalLessExpression() throws ParseException {
   UnaryRelational n0;
   NodeOptional n1 = new NodeOptional();
   NodeSequence n2;
   NodeChoice n3;
   NodeToken n4;
   Token n5;
   NodeToken n6;
   Token n7;
   UnaryRelational n8;
    n0 = UnaryRelational();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case LT:
    case LE:
        n2 = new NodeSequence(2);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case LT:
        n5 = jj_consume_token(LT);
                     n4 = JTBToolkit.makeNodeToken(n5);
              n3 = new NodeChoice(n4, 0);
        break;
      case LE:
        n7 = jj_consume_token(LE);
                      n6 = JTBToolkit.makeNodeToken(n7);
              n3 = new NodeChoice(n6, 1);
        break;
      default:
        jj_la1[12] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
        n2.addNode(n3);
      n8 = UnaryRelational();
        n2.addNode(n8);
        n1.addNode(n2);
      break;
    default:
      jj_la1[13] = jj_gen;
      ;
    }
     {if (true) return new RelationalLessExpression(n0,n1);}
    throw new Error("Missing return statement in function");
  }

  final public UnaryRelational UnaryRelational() throws ParseException {
   MathExpression n0;
    n0 = MathExpression();
     {if (true) return new UnaryRelational(n0);}
    throw new Error("Missing return statement in function");
  }

  final public IfExpression IfExpression() throws ParseException {
   NodeToken n0;
   Token n1;
   RelationalExprssion n2;
   NodeToken n3;
   Token n4;
   NodeListOptional n5 = new NodeListOptional();
   StatementExpression n6;
   NodeToken n7;
   Token n8;
    n1 = jj_consume_token(IF);
             n0 = JTBToolkit.makeNodeToken(n1);
    n2 = RelationalExprssion();
    n4 = jj_consume_token(DO);
             n3 = JTBToolkit.makeNodeToken(n4);
    label_6:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case IF:
      case WHILE:
      case DEF:
      case IDENTIFIER:
        ;
        break;
      default:
        jj_la1[14] = jj_gen;
        break label_6;
      }
      n6 = StatementExpression();
        n5.addNode(n6);
    }
     n5.nodes.trimToSize();
    n8 = jj_consume_token(STOP);
               n7 = JTBToolkit.makeNodeToken(n8);
     {if (true) return new IfExpression(n0,n2,n3,n5,n7);}
    throw new Error("Missing return statement in function");
  }

  final public WhileExpression WhileExpression() throws ParseException {
   NodeToken n0;
   Token n1;
   RelationalExprssion n2;
   NodeToken n3;
   Token n4;
   NodeListOptional n5 = new NodeListOptional();
   StatementExpression n6;
   NodeToken n7;
   Token n8;
    n1 = jj_consume_token(WHILE);
                n0 = JTBToolkit.makeNodeToken(n1);
    n2 = RelationalExprssion();
    n4 = jj_consume_token(DO);
             n3 = JTBToolkit.makeNodeToken(n4);
    label_7:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case IF:
      case WHILE:
      case DEF:
      case IDENTIFIER:
        ;
        break;
      default:
        jj_la1[15] = jj_gen;
        break label_7;
      }
      n6 = StatementExpression();
        n5.addNode(n6);
    }
     n5.nodes.trimToSize();
    n8 = jj_consume_token(STOP);
               n7 = JTBToolkit.makeNodeToken(n8);
     {if (true) return new WhileExpression(n0,n2,n3,n5,n7);}
    throw new Error("Missing return statement in function");
  }

  final public VariableDeclaration VariableDeclaration() throws ParseException {
   NodeToken n0;
   Token n1;
   VariableName n2;
   NodeToken n3;
   Token n4;
   MathExpression n5;
   NodeToken n6;
   Token n7;
    n1 = jj_consume_token(DEF);
              n0 = JTBToolkit.makeNodeToken(n1);
    n2 = VariableName();
    n4 = jj_consume_token(ASSIGN);
            n3 = JTBToolkit.makeNodeToken(n4);
    n5 = MathExpression();
    n7 = jj_consume_token(DOT);
            n6 = JTBToolkit.makeNodeToken(n7);
     {if (true) return new VariableDeclaration(n0,n2,n3,n5,n6);}
    throw new Error("Missing return statement in function");
  }

  final public VariableAssign VariableAssign() throws ParseException {
   VariableName n0;
   NodeToken n1;
   Token n2;
   MathExpression n3;
   NodeToken n4;
   Token n5;
    n0 = VariableName();
    n2 = jj_consume_token(ASSIGN);
            n1 = JTBToolkit.makeNodeToken(n2);
    n3 = MathExpression();
    n5 = jj_consume_token(DOT);
            n4 = JTBToolkit.makeNodeToken(n5);
     {if (true) return new VariableAssign(n0,n1,n3,n4);}
    throw new Error("Missing return statement in function");
  }

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

  final public JavaStaticMethods JavaStaticMethods() throws ParseException {
   NodeToken n0;
   Token n1;
   NodeList n2 = new NodeList();
   NodeSequence n3;
   NodeToken n4;
   Token n5;
   NodeToken n6;
   Token n7;
   NodeToken n8;
   Token n9;
   MathExpression n10;
   NodeListOptional n11 = new NodeListOptional();
   NodeSequence n12;
   NodeToken n13;
   Token n14;
   MathExpression n15;
   NodeToken n16;
   Token n17;
   NodeToken n18;
   Token n19;
    n1 = jj_consume_token(IDENTIFIER);
                     n0 = JTBToolkit.makeNodeToken(n1);
    label_8:
    while (true) {
        n3 = new NodeSequence(2);
      n5 = jj_consume_token(COLON);
               n4 = JTBToolkit.makeNodeToken(n5);
        n3.addNode(n4);
      n7 = jj_consume_token(IDENTIFIER);
                        n6 = JTBToolkit.makeNodeToken(n7);
        n3.addNode(n6);
        n2.addNode(n3);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case COLON:
        ;
        break;
      default:
        jj_la1[16] = jj_gen;
        break label_8;
      }
    }
     n2.nodes.trimToSize();
    n9 = jj_consume_token(30);
            n8 = JTBToolkit.makeNodeToken(n9);
    n10 = MathExpression();
    label_9:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case 32:
        ;
        break;
      default:
        jj_la1[17] = jj_gen;
        break label_9;
      }
        n12 = new NodeSequence(2);
      n14 = jj_consume_token(32);
                n13 = JTBToolkit.makeNodeToken(n14);
        n12.addNode(n13);
      n15 = MathExpression();
        n12.addNode(n15);
        n11.addNode(n12);
    }
     n11.nodes.trimToSize();
    n17 = jj_consume_token(31);
             n16 = JTBToolkit.makeNodeToken(n17);
    n19 = jj_consume_token(DOT);
             n18 = JTBToolkit.makeNodeToken(n19);
     {if (true) return new JavaStaticMethods(n0,n2,n8,n10,n11,n16,n18);}
    throw new Error("Missing return statement in function");
  }

  final public StatementExpression StatementExpression() throws ParseException {
   NodeChoice n0;
   VariableDeclaration n1;
   VariableAssign n2;
   JavaStaticMethods n3;
   IfExpression n4;
   WhileExpression n5;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case DEF:
      n1 = VariableDeclaration();
        n0 = new NodeChoice(n1, 0);
      break;
    default:
      jj_la1[18] = jj_gen;
      if (jj_2_1(2)) {
        n2 = VariableAssign();
        n0 = new NodeChoice(n2, 1);
      } else {
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case IDENTIFIER:
          n3 = JavaStaticMethods();
        n0 = new NodeChoice(n3, 2);
          break;
        case IF:
          n4 = IfExpression();
        n0 = new NodeChoice(n4, 3);
          break;
        case WHILE:
          n5 = WhileExpression();
        n0 = new NodeChoice(n5, 4);
          break;
        default:
          jj_la1[19] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
        }
      }
    }
     {if (true) return new StatementExpression(n0);}
    throw new Error("Missing return statement in function");
  }

  private boolean jj_2_1(int xla) {
    jj_la = xla; jj_lastpos = jj_scanpos = token;
    try { return !jj_3_1(); }
    catch(LookaheadSuccess ls) { return true; }
    finally { jj_save(0, xla); }
  }

  private boolean jj_3R_10() {
    if (jj_3R_11()) return true;
    if (jj_scan_token(ASSIGN)) return true;
    return false;
  }

  private boolean jj_3R_11() {
    if (jj_scan_token(IDENTIFIER)) return true;
    return false;
  }

  private boolean jj_3_1() {
    if (jj_3R_10()) return true;
    return false;
  }

  /** Generated Token Manager. */
  public St4ticTokenManager token_source;
  SimpleCharStream jj_input_stream;
  /** Current token. */
  public Token token;
  /** Next token. */
  public Token jj_nt;
  private int jj_ntk;
  private Token jj_scanpos, jj_lastpos;
  private int jj_la;
  private int jj_gen;
  final private int[] jj_la1 = new int[20];
  static private int[] jj_la1_0;
  static private int[] jj_la1_1;
  static {
      jj_la1_init_0();
      jj_la1_init_1();
   }
   private static void jj_la1_init_0() {
      jj_la1_0 = new int[] {0x40,0x8000980,0x8000000,0x300000,0x300000,0x1c00000,0x1c00000,0x4c000000,0x84000,0x84000,0x28000,0x28000,0x50000,0x50000,0x8000980,0x8000980,0x2000,0x0,0x800,0x8000180,};
   }
   private static void jj_la1_init_1() {
      jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,};
   }
  final private JJCalls[] jj_2_rtns = new JJCalls[1];
  private boolean jj_rescan = false;
  private int jj_gc = 0;

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

  /** 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 < 20; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  }

  /** Constructor. */
  public St4tic(java.io.Reader stream) {
    jj_input_stream = new SimpleCharStream(stream, 1, 1);
    token_source = new St4ticTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 20; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  }

  /** 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 < 20; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  }

  /** Constructor with generated Token Manager. */
  public St4tic(St4ticTokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 20; i++) jj_la1[i] = -1;
    for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
  }

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

  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++;
      if (++jj_gc > 100) {
        jj_gc = 0;
        for (int i = 0; i < jj_2_rtns.length; i++) {
          JJCalls c = jj_2_rtns[i];
          while (c != null) {
            if (c.gen < jj_gen) c.first = null;
            c = c.next;
          }
        }
      }
      return token;
    }
    token = oldToken;
    jj_kind = kind;
    throw generateParseException();
  }

  static private final class LookaheadSuccess extends java.lang.Error { }
  final private LookaheadSuccess jj_ls = new LookaheadSuccess();
  private boolean jj_scan_token(int kind) {
    if (jj_scanpos == jj_lastpos) {
      jj_la--;
      if (jj_scanpos.next == null) {
        jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
      } else {
        jj_lastpos = jj_scanpos = jj_scanpos.next;
      }
    } else {
      jj_scanpos = jj_scanpos.next;
    }
    if (jj_rescan) {
      int i = 0; Token tok = token;
      while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
      if (tok != null) jj_add_error_token(kind, i);
    }
    if (jj_scanpos.kind != kind) return true;
    if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
    return false;
  }


/** 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() {
    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;
  private int[] jj_lasttokens = new int[100];
  private int jj_endpos;

  private void jj_add_error_token(int kind, int pos) {
    if (pos >= 100) return;
    if (pos == jj_endpos + 1) {
      jj_lasttokens[jj_endpos++] = kind;
    } else if (jj_endpos != 0) {
      jj_expentry = new int[jj_endpos];
      for (int i = 0; i < jj_endpos; i++) {
        jj_expentry[i] = jj_lasttokens[i];
      }
      jj_entries_loop: for (java.util.Iterator it = jj_expentries.iterator(); it.hasNext();) {
        int[] oldentry = (int[])(it.next());
        if (oldentry.length == jj_expentry.length) {
          for (int i = 0; i < jj_expentry.length; i++) {
            if (oldentry[i] != jj_expentry[i]) {
              continue jj_entries_loop;
            }
          }
          jj_expentries.add(jj_expentry);
          break jj_entries_loop;
        }
      }
      if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
    }
  }

  /** Generate ParseException. */
  public ParseException generateParseException() {
    jj_expentries.clear();
    boolean[] la1tokens = new boolean[33];
    if (jj_kind >= 0) {
      la1tokens[jj_kind] = true;
      jj_kind = -1;
    }
    for (int i = 0; i < 20; 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;
          }
          if ((jj_la1_1[i] & (1<<j)) != 0) {
            la1tokens[32+j] = true;
          }
        }
      }
    }
    for (int i = 0; i < 33; i++) {
      if (la1tokens[i]) {
        jj_expentry = new int[1];
        jj_expentry[0] = i;
        jj_expentries.add(jj_expentry);
      }
    }
    jj_endpos = 0;
    jj_rescan_token();
    jj_add_error_token(0, 0);
    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. */
  final public void enable_tracing() {
  }

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

  private void jj_rescan_token() {
    jj_rescan = true;
    for (int i = 0; i < 1; i++) {
    try {
      JJCalls p = jj_2_rtns[i];
      do {
        if (p.gen > jj_gen) {
          jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
          switch (i) {
            case 0: jj_3_1(); break;
          }
        }
        p = p.next;
      } while (p != null);
      } catch(LookaheadSuccess ls) { }
    }
    jj_rescan = false;
  }

  private void jj_save(int index, int xla) {
    JJCalls p = jj_2_rtns[index];
    while (p.gen > jj_gen) {
      if (p.next == null) { p = p.next = new JJCalls(); break; }
      p = p.next;
    }
    p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
  }

  static final class JJCalls {
    int gen;
    Token first;
    int arg;
    JJCalls next;
  }

}

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

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
Morocco Morocco
Adrabi!, Just another Ghost in the Shell =)

Comments and Discussions