/* Generated By:JJTree&JavaCC: Do not edit this line. FtScript.java */
package eu.dnetlib.data.collective.transformation.rulelanguage.parser;
import eu.dnetlib.data.collective.transformation.rulelanguage.Rules;
public class FtScript/*@bgen(jjtree)*/implements FtScriptTreeConstants, FtScriptConstants {/*@bgen(jjtree)*/
  protected JJTFtScriptState jjtree = new JJTFtScriptState();

  final public ASTStart Start() throws ParseException {
                   /*@bgen(jjtree) Start */
  ASTStart jjtn000 = new ASTStart(JJTSTART);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      script();
    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");
  }

/**
 * id = value
 */
  final public void assign(Rules r) throws ParseException {
                                  /*@bgen(jjtree) MyAssign */
                                  ASTMyAssign jjtn000 = new ASTMyAssign(JJTMYASSIGN);
                                  boolean jjtc000 = true;
                                  jjtree.openNodeScope(jjtn000);String value = ""; Token t;
    try {
                                                           jjtn000.setRule(r);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DOLLAR_QNAME:
      case XPATH:
      case JOBCONST:
        t = inputField();
                                                        jjtree.closeNodeScope(jjtn000, true);
                                                        jjtc000 = false;
                                                       jjtn000.setFieldExpression(t.image);
        break;
      case QUOTED_STRING:
        value = quotedString();
                                                        jjtree.closeNodeScope(jjtn000, true);
                                                        jjtc000 = false;
                                                       jjtn000.setAttribute(value);
        break;
      default:
        jj_la1[0] = 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);
                                                            }
    }
  }

  final public void attrib_list() throws ParseException {
    jj_consume_token(LBRACKET);
    label_1:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DOLLAR_QNAME:
      case XPATH:
      case JOBCONST:
      case IDENTIFIER:
        ;
        break;
      default:
        jj_la1[1] = jj_gen;
        break label_1;
      }
      attribute();
    }
    jj_consume_token(RBRACKET);
  }

  final public void attribute() throws ParseException {
                                 /*@bgen(jjtree) MyAttribute */
                                 ASTMyAttribute jjtn000 = new ASTMyAttribute(JJTMYATTRIBUTE);
                                 boolean jjtc000 = true;
                                 jjtree.openNodeScope(jjtn000);String value; Token t=null;
    try {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case IDENTIFIER:
        value = identifier();
                                jjtn000.setAttributeValue(value);
        break;
      case DOLLAR_QNAME:
      case XPATH:
      case JOBCONST:
        t = inputField();
          value = t.image;
          jjtn000.setAttributeInputField(value);
        break;
      default:
        jj_la1[2] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case COMMA:
        jj_consume_token(COMMA);
        break;
      default:
        jj_la1[3] = jj_gen;
        ;
      }
    } 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);
          }
    }
  }

/**
 *  a conditional Rule, which contains the condition, the Rule on which the condition holds and the alternative rule
 */
  final public void conditionalStmt() throws ParseException {
                                       /*@bgen(jjtree) MyCondition */
                                       ASTMyCondition jjtn000 = new ASTMyCondition(JJTMYCONDITION);
                                       boolean jjtc000 = true;
                                       jjtree.openNodeScope(jjtn000);Rules r1 = new Rules(); Rules r2 = new Rules(); Token cond; Token apply;
    try {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case APPLY:
        jj_consume_token(APPLY);
        apply = inputField();
    jjtn000.setApplyExpression(apply.image);
        break;
      default:
        jj_la1[4] = jj_gen;
        ;
      }
      jj_consume_token(IF);
      cond = inputField();
                                jjtn000.setConditionalExpression(cond.image); jjtn000.setPrimaryRule(r1); jjtn000.setSecondaryRule(r2);
      rule(r1);
      jj_consume_token(ELSE);
      rule(r2);
    } 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);
    }
    }
  }

  final public void empty(Rules r) throws ParseException {
                                /*@bgen(jjtree) MyEmpty */
  ASTMyEmpty jjtn000 = new ASTMyEmpty(JJTMYEMPTY);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
                                              jjtn000.setRule(r);
      jj_consume_token(EMPTY);
                                               jjtree.closeNodeScope(jjtn000, true);
                                               jjtc000 = false;
                                              jjtn000.setEmpty(true);
    } finally {
                                               if (jjtc000) {
                                                 jjtree.closeNodeScope(jjtn000, true);
                                               }
    }
  }

  final public String identifier() throws ParseException {
                             Token t;
    t = jj_consume_token(IDENTIFIER);
                    {if (true) return t.image;}
    throw new Error("Missing return statement in function");
  }

  final public void importDeclaration() throws ParseException {
 /*@bgen(jjtree) MyImport */
 ASTMyImport jjtn000 = new ASTMyImport(JJTMYIMPORT);
 boolean jjtc000 = true;
 jjtree.openNodeScope(jjtn000);String scriptName;
    try {
      jj_consume_token(IMPORT);
      jj_consume_token(LPAREN);
      scriptName = identifier();
      jj_consume_token(RPAREN);
      jj_consume_token(SEMICOLON);
                                                             jjtree.closeNodeScope(jjtn000, true);
                                                             jjtc000 = false;
                                                             jjtn000.setScriptName(scriptName);
    } 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);
    }
    }
  }

  final public Token anyExpression() throws ParseException {
                                Token t;
    t = jj_consume_token(IDENTIFIER);
    {if (true) return t;}
    throw new Error("Missing return statement in function");
  }

  final public Token inputField() throws ParseException {
                            Token t;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case XPATH:
      t = jj_consume_token(XPATH);
    {if (true) return t;}
      break;
    case JOBCONST:
      t = jj_consume_token(JOBCONST);
    {if (true) return t;}
      break;
    case DOLLAR_QNAME:
      t = jj_consume_token(DOLLAR_QNAME);
    {if (true) return t;}
      break;
    default:
      jj_la1[5] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    throw new Error("Missing return statement in function");
  }

/*
 * becomes obsolete
 */
  final public String key() throws ParseException {
                      String key;
    key = identifier();
    jj_consume_token(EQUAL);
    {if (true) return key;}
    throw new Error("Missing return statement in function");
  }

  final public void literal() throws ParseException {
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case CHARACTER_LITERAL:
      jj_consume_token(CHARACTER_LITERAL);
      break;
    case STRING_LITERAL:
      jj_consume_token(STRING_LITERAL);
      break;
    default:
      jj_la1[6] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  final public void nsDeclaration() throws ParseException {
 /*@bgen(jjtree) MyNs */
 ASTMyNs jjtn000 = new ASTMyNs(JJTMYNS);
 boolean jjtc000 = true;
 jjtree.openNodeScope(jjtn000);String nsPrefix; String nsUri;
    try {
      jj_consume_token(DECLARE_NAMESPACE);
      nsPrefix = identifier();
      jj_consume_token(EQUAL);
      nsUri = quotedString();
      jj_consume_token(SEMICOLON);
          jjtree.closeNodeScope(jjtn000, true);
          jjtc000 = false;
          jjtn000.setNsDeclaration(nsPrefix, nsUri);
    } 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);
          }
    }
  }

  final public void preprocess() throws ParseException {
                                  /*@bgen(jjtree) MyPreprocess */
                                  ASTMyPreprocess jjtn000 = new ASTMyPreprocess(JJTMYPREPROCESS);
                                  boolean jjtc000 = true;
                                  jjtree.openNodeScope(jjtn000);String preprocessId;
    try {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case PREPROCESS:
        jj_consume_token(PREPROCESS);
        preprocessId = identifier();
        jj_consume_token(EQUAL);
        jj_consume_token(DBLOOKUP);
        jj_consume_token(LPAREN);
                                     String sqlExpr;
        sqlExpr = quotedString();
        jj_consume_token(RPAREN);
                                     jjtn000.preprocess(preprocessId, "dblookup", sqlExpr);
        jj_consume_token(SEMICOLON);
        break;
      case BLACKLIST:
        jj_consume_token(BLACKLIST);
        jj_consume_token(LPAREN);
                String blacklistDataSourceId;
        blacklistDataSourceId = quotedString();
        jj_consume_token(RPAREN);
     jjtn000.preprocess("blacklist", blacklistDataSourceId);
        jj_consume_token(SEMICOLON);
        break;
      default:
        jj_la1[7] = 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);
    }
    }
  }

  final public void set(Rules r) throws ParseException {
                            /*@bgen(jjtree) MySet */
                            ASTMySet jjtn000 = new ASTMySet(JJTMYSET);
                            boolean jjtc000 = true;
                            jjtree.openNodeScope(jjtn000);Token expr; String value = "";
    try {
       jjtn000.setRule(r);
      jj_consume_token(SET);
      jj_consume_token(LPAREN);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DOLLAR_QNAME:
      case XPATH:
      case JOBCONST:
        expr = inputField();
                                     jjtn000.setValueExpression(expr.image);
        break;
      case QUOTED_STRING:
        value = quotedString();
                                     jjtn000.setAttribute(value);
        break;
      default:
        jj_la1[8] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      label_2:
      while (true) {
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case COMMA:
          ;
          break;
        default:
          jj_la1[9] = jj_gen;
          break label_2;
        }
        jj_consume_token(COMMA);
                       r = new Rules();
        rule(r);
                           jjtn000.addAttributeRule(r);
      }
      jj_consume_token(RPAREN);
    } 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);
    }
    }
  }

  final public void skip(Rules r) throws ParseException {
                             /*@bgen(jjtree) MySkip */
  ASTMySkip jjtn000 = new ASTMySkip(JJTMYSKIP);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
    jjtn000.setRule(r);
      jj_consume_token(SKIPRECORD);
                                         jjtn000.skipRecord();
      jj_consume_token(LPAREN);
      jj_consume_token(RPAREN);
    } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
    }
    }
  }

  final public void copy(Rules r) throws ParseException {
                              /*@bgen(jjtree) MyCopy */
  ASTMyCopy jjtn000 = new ASTMyCopy(JJTMYCOPY);
  boolean jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
       jjtn000.setRule(r);
      jj_consume_token(COPY);
      jj_consume_token(LPAREN);
                                                  String templateMatchExpression; String applyTemplateSelectExpression; String copySelectExpression;
      templateMatchExpression = quotedString();
      jj_consume_token(COMMA);
      applyTemplateSelectExpression = quotedString();
      jj_consume_token(COMMA);
      copySelectExpression = quotedString();
      jj_consume_token(RPAREN);
                                                  jjtree.closeNodeScope(jjtn000, true);
                                                  jjtc000 = false;
                                           jjtn000.copy(templateMatchExpression, applyTemplateSelectExpression, copySelectExpression);
    } 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);
    }
    }
  }

  final public void op(Rules r) throws ParseException {
                          /*@bgen(jjtree) MyOp */
                          ASTMyOp jjtn000 = new ASTMyOp(JJTMYOP);
                          boolean jjtc000 = true;
                          jjtree.openNodeScope(jjtn000);String functionName = ""; Token expr; Token expr2; Token vocab; String defaultPattern = ""; String function = ""; String elementName = ""; String regExpr; Token feature;
    try {
                                             jjtn000.setRule(r);
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case GETVALUE:
        jj_consume_token(GETVALUE);
        jj_consume_token(LPAREN);
        functionName = identifier();
        jj_consume_token(COMMA);
        attrib_list();
        jj_consume_token(RPAREN);
                                              jjtree.closeNodeScope(jjtn000, true);
                                              jjtc000 = false;
                                             jjtn000.getValue(functionName);
        break;
      case CONVERT:
        jj_consume_token(CONVERT);
        jj_consume_token(LPAREN);
        expr = inputField();
        jj_consume_token(COMMA);
        vocab = jj_consume_token(IDENTIFIER);
        label_3:
        while (true) {
          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
          case COMMA:
            ;
            break;
          default:
            jj_la1[10] = jj_gen;
            break label_3;
          }
          jj_consume_token(COMMA);
          defaultPattern = quotedString();
          jj_consume_token(COMMA);
          function = quotedString();
        }
        jj_consume_token(RPAREN);
                                              jjtree.closeNodeScope(jjtn000, true);
                                              jjtc000 = false;
                                             jjtn000.convert(expr.image, vocab.image, defaultPattern, function);
        break;
      case EXTRACT:
        jj_consume_token(EXTRACT);
        jj_consume_token(LPAREN);
        feature = jj_consume_token(IDENTIFIER);
        jj_consume_token(RPAREN);
                                              jjtree.closeNodeScope(jjtn000, true);
                                              jjtc000 = false;
                                             jjtn000.extract(feature.image);
        break;
      case REGEXPR:
        jj_consume_token(REGEXPR);
        jj_consume_token(LPAREN);
        expr = inputField();
        jj_consume_token(COMMA);
        expr2 = inputField();
        jj_consume_token(COMMA);
        regExpr = quotedString();
        jj_consume_token(RPAREN);
                                                  jjtree.closeNodeScope(jjtn000, true);
                                                  jjtc000 = false;
                                                 jjtn000.regExpr(expr.image, expr2.image, regExpr);
        break;
      case SPLIT:
        jj_consume_token(SPLIT);
        jj_consume_token(LPAREN);
        expr = inputField();
        jj_consume_token(COMMA);
        elementName = quotedString();
        jj_consume_token(COMMA);
        regExpr = quotedString();
        jj_consume_token(RPAREN);
                                          jjtree.closeNodeScope(jjtn000, true);
                                          jjtc000 = false;
                                         jjtn000.split(expr.image, elementName, regExpr);
        break;
      case LOOKUP:
        jj_consume_token(LOOKUP);
                                                  String propertyKey;
        jj_consume_token(LPAREN);
        expr = inputField();
        jj_consume_token(COMMA);
        propertyKey = quotedString();
        jj_consume_token(RPAREN);
                                          jjtree.closeNodeScope(jjtn000, true);
                                          jjtc000 = false;
                                          jjtn000.lookup(expr.image, propertyKey);
        break;
      case IDENTIFIEREXTRACT:
        jj_consume_token(IDENTIFIEREXTRACT);
                                                  String xpathExprJsonString; Token xpathExprInputSource;
        jj_consume_token(LPAREN);
        // "{//abc, //def }" ?json list of xpath-expr
                    // xpath-expr of input source
                    // regExpr          
                        xpathExprJsonString = singleQuotedString();
        jj_consume_token(COMMA);
        xpathExprInputSource = inputField();
        jj_consume_token(COMMA);
        regExpr = singleQuotedString();
        jj_consume_token(RPAREN);
                                                  jjtree.closeNodeScope(jjtn000, true);
                                                  jjtc000 = false;
                                           jjtn000.identifierExtract(xpathExprJsonString, xpathExprInputSource.image, regExpr);
        break;
      case CONCAT:
        jj_consume_token(CONCAT);
                                                  jjtn000.concat();
        jj_consume_token(LPAREN);
                                                  String v; Token t;
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case QUOTED_STRING:
          v = quotedString();
                                               jjtn000.addConcat(v);
          break;
        case DOLLAR_QNAME:
          t = jj_consume_token(DOLLAR_QNAME);
                                                                                                                  jjtn000.addConcat(t.image);
          break;
        default:
          jj_la1[11] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
        }
        label_4:
        while (true) {
          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
          case COMMA:
            ;
            break;
          default:
            jj_la1[12] = jj_gen;
            break label_4;
          }
          jj_consume_token(COMMA);
          switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
          case QUOTED_STRING:
            v = quotedString();
                                     jjtn000.addConcat(v);
            break;
          case DOLLAR_QNAME:
            t = jj_consume_token(DOLLAR_QNAME);
                                                                                                          jjtn000.addConcat(t.image);
            break;
          default:
            jj_la1[13] = jj_gen;
            jj_consume_token(-1);
            throw new ParseException();
          }
        }
        jj_consume_token(RPAREN);
        break;
      default:
        jj_la1[14] = 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);
                                              }
    }
  }

  final public String leftExprOutputField() throws ParseException {
                                      String leftExpr;
    leftExpr = identifier();
    jj_consume_token(EQUAL);
                                      {if (true) return leftExpr;}
    throw new Error("Missing return statement in function");
  }

  final public String leftExprVar() throws ParseException {
                              String leftExpr;
    leftExpr = variable();
    jj_consume_token(EQUAL);
                                      {if (true) return leftExpr;}
    throw new Error("Missing return statement in function");
  }

  final public String leftExprTemplate() throws ParseException {
                                   String leftExpr;
    leftExpr = template();
    jj_consume_token(EQUAL);
                                     {if (true) return leftExpr;}
    throw new Error("Missing return statement in function");
  }

  final public String singleQuotedString() throws ParseException {
                                      Token t;
    t = jj_consume_token(SINGLE_QUOTE);
      {if (true) return t.image;}
    throw new Error("Missing return statement in function");
  }

  final public String quotedString() throws ParseException {
                               Token t;
    t = jj_consume_token(QUOTED_STRING);
      {if (true) return t.image;}
    throw new Error("Missing return statement in function");
  }

  final public void rule(Rules r) throws ParseException {
                             String ruleDecl; String leftExpr;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case STATIC:
      ruleDecl = ruleDecl();
                                   r.setRuleDeclaration(ruleDecl);
      break;
    default:
      jj_la1[15] = jj_gen;
      ;
    }
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case IDENTIFIER:
      leftExpr = leftExprOutputField();
             String[] fieldArray = leftExpr.split("@");
             r.setTargetField(fieldArray[0]);
             if (fieldArray.length > 1)
             {
               r.setAttribute(fieldArray[1]);
             }
      break;
    case DOLLAR_QNAME:
      leftExpr = leftExprVar();
                                                r.setVariable(leftExpr);
      break;
    case PERCENT_QNAME:
      leftExpr = leftExprTemplate();
                                                   r.setTemplate(leftExpr);
      break;
    default:
      jj_la1[16] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
    if (jj_2_1(2)) {
      assign(r);
    } else {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case EXTRACT:
      case IDENTIFIEREXTRACT:
      case CONVERT:
      case REGEXPR:
      case GETVALUE:
      case SPLIT:
      case LOOKUP:
      case CONCAT:
        op(r);
        break;
      case SET:
        set(r);
        break;
      case COPY:
        copy(r);
        break;
      case EMPTY:
        empty(r);
        break;
      case SKIPRECORD:
        skip(r);
        break;
      default:
        jj_la1[17] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
    jj_consume_token(SEMICOLON);
  }

  final public String ruleDecl() throws ParseException {
                           Token t;
    t = jj_consume_token(STATIC);
    {if (true) return t.image;}
    throw new Error("Missing return statement in function");
  }

  final public void script() throws ParseException {
    scriptDeclaration();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case IMPORT:
      importDeclaration();
      break;
    default:
      jj_la1[18] = jj_gen;
      ;
    }
    label_5:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DECLARE_NAMESPACE:
        ;
        break;
      default:
        jj_la1[19] = jj_gen;
        break label_5;
      }
      nsDeclaration();
    }
    label_6:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case PREPROCESS:
      case BLACKLIST:
        ;
        break;
      default:
        jj_la1[20] = jj_gen;
        break label_6;
      }
      preprocess();
    }
    label_7:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case IF:
      case STATIC:
      case APPLY:
      case DOLLAR_QNAME:
      case PERCENT_QNAME:
      case IDENTIFIER:
        ;
        break;
      default:
        jj_la1[21] = jj_gen;
        break label_7;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case STATIC:
      case DOLLAR_QNAME:
      case PERCENT_QNAME:
      case IDENTIFIER:
        stmt();
        break;
      case IF:
      case APPLY:
        conditionalStmt();
        break;
      default:
        jj_la1[22] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
    }
    jj_consume_token(END);
    jj_consume_token(0);
  }

  final public void scriptDeclaration() throws ParseException {
 /*@bgen(jjtree) MyScript */
 ASTMyScript jjtn000 = new ASTMyScript(JJTMYSCRIPT);
 boolean jjtc000 = true;
 jjtree.openNodeScope(jjtn000);String scriptName; ASTMyScript.SCRIPTTYPE scriptType;
    try {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case DECLARE_SCRIPT:
        jj_consume_token(DECLARE_SCRIPT);
            jjtn000.setScriptType(ASTMyScript.SCRIPTTYPE.MAINSCRIPT);
        break;
      case DECLARE_SUBSCRIPT:
        jj_consume_token(DECLARE_SUBSCRIPT);
            jjtn000.setScriptType(ASTMyScript.SCRIPTTYPE.SUBSCRIPT);
        break;
      default:
        jj_la1[23] = jj_gen;
        jj_consume_token(-1);
        throw new ParseException();
      }
      scriptName = quotedString();
      jj_consume_token(SEMICOLON);
          jjtree.closeNodeScope(jjtn000, true);
          jjtc000 = false;
          jjtn000.setScript(scriptName);
    } 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);
          }
    }
  }

  final public void stmt() throws ParseException {
                    Rules r = new Rules();
    rule(r);
  }

  final public String string() throws ParseException {
                         Token t;
    t = jj_consume_token(STRING_LITERAL);
                              {if (true) return t.image.substring(1, t.image.length()-1);}
    throw new Error("Missing return statement in function");
  }

  final public String variable() throws ParseException {
                            Token t;
    t = jj_consume_token(DOLLAR_QNAME);
                          {if (true) return t.image;}
    throw new Error("Missing return statement in function");
  }

  final public String template() throws ParseException {
                            Token t;
    t = jj_consume_token(PERCENT_QNAME);
                           {if (true) return t.image;}
    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_12() {
    if (jj_scan_token(QUOTED_STRING)) return true;
    return false;
  }

  private boolean jj_3R_11() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_13()) {
    jj_scanpos = xsp;
    if (jj_3R_14()) {
    jj_scanpos = xsp;
    if (jj_3R_15()) return true;
    }
    }
    return false;
  }

  private boolean jj_3R_13() {
    if (jj_scan_token(XPATH)) return true;
    return false;
  }

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

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

  private boolean jj_3R_8() {
    Token xsp;
    xsp = jj_scanpos;
    if (jj_3R_9()) {
    jj_scanpos = xsp;
    if (jj_3R_10()) return true;
    }
    return false;
  }

  private boolean jj_3R_15() {
    if (jj_scan_token(DOLLAR_QNAME)) return true;
    return false;
  }

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

  private boolean jj_3R_14() {
    if (jj_scan_token(JOBCONST)) return true;
    return false;
  }

  /** Generated Token Manager. */
  public FtScriptTokenManager 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[24];
  static private int[] jj_la1_0;
  static private int[] jj_la1_1;
  static private int[] jj_la1_2;
  static {
      jj_la1_init_0();
      jj_la1_init_1();
      jj_la1_init_2();
   }
   private static void jj_la1_init_0() {
      jj_la1_0 = new int[] {0x0,0x0,0x0,0x0,0x20000000,0x0,0x0,0x800000,0x0,0x0,0x0,0x0,0x0,0x0,0x407c000,0x8000000,0x0,0x470fc000,0x200,0x100000,0x800000,0x28000800,0x28000800,0x600000,};
   }
   private static void jj_la1_init_1() {
      jj_la1_1 = new int[] {0x16800000,0x6800000,0x6800000,0x80,0x0,0x6800000,0xc0000000,0x1,0x16800000,0x80,0x80,0x10800000,0x80,0x10800000,0x6,0x0,0x1800000,0x6,0x0,0x0,0x1,0x1800000,0x1800000,0x0,};
   }
   private static void jj_la1_init_2() {
      jj_la1_2 = new int[] {0x0,0x2,0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x2,0x2,0x0,};
   }
  final private JJCalls[] jj_2_rtns = new JJCalls[1];
  private boolean jj_rescan = false;
  private int jj_gc = 0;

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

  /** Constructor. */
  public FtScript(java.io.Reader stream) {
    jj_input_stream = new SimpleCharStream(stream, 1, 1);
    token_source = new FtScriptTokenManager(jj_input_stream);
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 24; 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;
    jjtree.reset();
    jj_gen = 0;
    for (int i = 0; i < 24; 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 FtScript(FtScriptTokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jj_gen = 0;
    for (int i = 0; i < 24; 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(FtScriptTokenManager tm) {
    token_source = tm;
    token = new Token();
    jj_ntk = -1;
    jjtree.reset();
    jj_gen = 0;
    for (int i = 0; i < 24; 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[70];
    if (jj_kind >= 0) {
      la1tokens[jj_kind] = true;
      jj_kind = -1;
    }
    for (int i = 0; i < 24; 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;
          }
          if ((jj_la1_2[i] & (1<<j)) != 0) {
            la1tokens[64+j] = true;
          }
        }
      }
    }
    for (int i = 0; i < 70; 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;
  }

}
