⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scriptedit.java

📁 脚本开发工具和源代码,用于J2me中RPG游戏的脚本开发和执行,相当好用的一套工具,并含有脚本开发工具的源代码和一个现成的游戏脚本
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        Control.setInsStatus(Control.STATUS_IF_STM);
    InstructionListStatement();
                        pc = Control.getPC() + 1; //增加了一个跳转指令
                        t = new Teminal();
                        t.setType(Teminal.INTEGER);
                        t.setValue(pc);
                        ins.setNum1(t);  //if指令

                        //添加跳转指令
                        ins = new Instruction();
                        ins.setName(Instruction.JUMP);
                        script.add(ins);
                        Control.pushJC(ins);
                        Control.nextPC();
                        Control.setInsStatus(Control.STATUS_NORMAL);
    label_7:
    while (true) {
      if (jj_2_1(2)) {
        ;
      } else {
        break label_7;
      }
      jj_consume_token(ELSE);
      jj_consume_token(IF);
                        t = new Teminal();
                        t.setType(Teminal.MSYMBOL);
                        t.setValue(Expression.LPAREN);
                        exp.pushO(t);

                        //设置指令状态
                        Control.setInsStatus(Control.STATUS_IF_EXP);
      jj_consume_token(LPAREN);
      Expression();
      jj_consume_token(RPAREN);
                        ins = new Instruction();
                        ins.setName(Instruction.IF);
                        script.add(ins);
                        Control.nextPC();
                        Control.setInsStatus(Control.STATUS_IF_STM);
      InstructionListStatement();
                        pc = Control.getPC() + 1; //增加了一个跳转指令
                        t = new Teminal();
                        t.setType(Teminal.INTEGER);
                        t.setValue(pc);
                        ins.setNum1(t);  //if指令

                        //添加跳转指令
                        ins = new Instruction();
                        ins.setName(Instruction.JUMP);
                        script.add(ins);
                        Control.pushJC(ins);
                        Control.nextPC();
                        Control.setInsStatus(Control.STATUS_NORMAL);
    }
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case ELSE:
      jj_consume_token(ELSE);
                        Control.setInsStatus(Control.STATUS_IF_STM);
      InstructionListStatement();
                        //不需要跳转指令了
                        flag = true;
                        //设置指令状态
                        Control.setInsStatus(Control.STATUS_NORMAL);
      break;
    default:
      jj_la1[16] = jj_gen;
      ;
    }
                //最后一个jump指令不需跳转 
                if(!flag)
                {
                        ins = Control.popJC();
                        script.remove(ins);
                        Control.setPC(Control.getPC() - 1);
                }

                pc = Control.getPC();
                while(Control.getJCSize() > preJC)
                {
                        ins = Control.popJC();
                        t = new Teminal();
                        t.setType(Teminal.INTEGER);
                        t.setValue(pc);
                        ins.setNum1(t);
                        if(ins.getName().equals(Instruction.BREAK) ||
                                 ins.getName().equals(Instruction.CONTINUE)) {
                                ins.setName(Instruction.JUMP);
                        }
                }
  }

  static final public void InstructionListStatement() throws ParseException {
    jj_consume_token(LBRACE);
    label_8:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case IF:
      case WHILE:
      case BREAK:
      case CONTINUE:
      case STOP:
      case RETURN:
      case IDENTIFIER:
        ;
        break;
      default:
        jj_la1[17] = jj_gen;
        break label_8;
      }
      Statement();
    }
    jj_consume_token(RBRACE);
  }

  static final public void WhileStatement() throws ParseException {
        Teminal t;
        Instruction ins;
        int pc, prePC, preJC;
    jj_consume_token(WHILE);
    jj_consume_token(LPAREN);
                        exp = new Expression();
                        t = new Teminal();
                        t.setType(Teminal.MSYMBOL);
                        t.setValue(Expression.LPAREN);
                        exp.pushO(t);

                        //回跳地点为表达式之前
                        prePC = Control.getPC();
                        //进入前的JC栈数
                        preJC = Control.getJCSize();
                        //设置指令状态
                        Control.setInsStatus(Control.STATUS_WHILE_EXP);
    Expression();
    jj_consume_token(RPAREN);
                        exp.popO();
                        if(exp.oStackSize() != 0 || exp.tStackSize() != 0)
                                {if (true) throw new ParseException("If Expression Error!");}

                        ins = new Instruction();
                        ins.setName(Instruction.IF);
                        script.add(ins);
                        Control.nextPC();
                        Control.setInsStatus(Control.STATUS_WHILE_STM);
    InstructionListStatement();
                        pc = Control.getPC() + 1; //增加了一个跳转指令
                        t = new Teminal();
                        t.setType(Teminal.INTEGER);
                        t.setValue(pc);
                        ins.setNum1(t);  //if指令

                        //添加跳转指令
                        ins = new Instruction();
                        ins.setName(Instruction.JUMP);
                        t = new Teminal();
                        t.setType(Teminal.INTEGER);
                        t.setValue(prePC); //回跳
                        ins.setNum1(t);
                        script.add(ins);
                        Control.nextPC();
                        Control.setInsStatus(Control.STATUS_NORMAL);
                pc = Control.getPC();
                while(Control.getJCSize() > preJC) {
                        ins = Control.popJC();
                        t = new Teminal();
                        t.setType(Teminal.INTEGER);
                        if(ins.getName().equals(Instruction.BREAK)) {
                                t.setValue(pc);
                                ins.setName(Instruction.JUMP);
                        }
                        else if(ins.getName().equals(Instruction.CONTINUE)) {
                                t.setValue(prePC);
                                ins.setName(Instruction.JUMP);
                        }
                        ins.setNum1(t);
                }
  }

  static final public void ArgumentList() throws ParseException {
    Parameter();
    label_9:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case COMMA:
        ;
        break;
      default:
        jj_la1[18] = jj_gen;
        break label_9;
      }
      jj_consume_token(COMMA);
      Parameter();
    }
  }

  static final public void Parameter() throws ParseException {
        int type;
        Token value;
        String strValue;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case TRUE:
    case FALSE:
    case INTEGER_LITERAL:
    case STRING_LITERAL:
    case IDENTIFIER:
    case PLUS:
    case MINUS:
      PrimaryPrefix();
      break;
    case SCRIPT:
      jj_consume_token(SCRIPT);
      jj_consume_token(DOT);
      value = jj_consume_token(IDENTIFIER);
                type = Teminal.SCRIPT;
                strValue = value.image;
                Teminal t = new Teminal(type, strValue);
                //附加调试信息
                Token token = getToken(0);
                t.setLine(token.beginLine);
                Instruction ins = new Instruction();
                ins.setName(Instruction.PUSH);
                ins.setNum1(t);
                script.add(ins);
                Control.nextPC();
      break;
    default:
      jj_la1[19] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  static final public void PrimaryPrefix() throws ParseException {
        int type;
        Token value, symbol;
        String strValue;
        symbol = new Token();
        symbol.image = "";
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case INTEGER_LITERAL:
    case PLUS:
    case MINUS:
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case PLUS:
      case MINUS:
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case PLUS:
          symbol = jj_consume_token(PLUS);
          break;
        case MINUS:
          symbol = jj_consume_token(MINUS);
          break;
        default:
          jj_la1[20] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
        }
        break;
      default:
        jj_la1[21] = jj_gen;
        ;
      }
      value = jj_consume_token(INTEGER_LITERAL);
          type = Teminal.INTEGER; strValue = symbol.image + value.image;
      break;
    case STRING_LITERAL:
      value = jj_consume_token(STRING_LITERAL);
    type = Teminal.STRING; strValue = value.image.substring(1, value.image.length() - 1);
      break;
    case TRUE:
      value = jj_consume_token(TRUE);
          type = Teminal.BOOLEAN; strValue = value.image;
      break;
    case FALSE:
      value = jj_consume_token(FALSE);
    type = Teminal.BOOLEAN; strValue = value.image;
      break;
    case IDENTIFIER:
      value = jj_consume_token(IDENTIFIER);
          type = Teminal.IDENTIFER; strValue = value.image;
      break;
    default:
      jj_la1[22] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
                Teminal t = new Teminal(type, strValue);
                //附加调试信息
                Token token = getToken(0);
                t.setLine(token.beginLine);
                Instruction ins = new Instruction();
                ins.setName(Instruction.PUSH);
                ins.setNum1(t);
                script.add(ins);
                Control.nextPC();
  }

  static final public void Expression() throws ParseException {
        Teminal t;
    ConditionalAndExpression();
    label_10:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case SC_OR:
        ;
        break;
      default:
        jj_la1[23] = jj_gen;
        break label_10;
      }
      jj_consume_token(SC_OR);
                                t = new Teminal();
                                t.setType(Teminal.RSYMBOL);
                                t.setValue(Expression.OR);
                                exp.pushO(t);
      ConditionalAndExpression();
    }
  }

  static final public void ConditionalAndExpression() throws ParseException {
        Teminal t;
    PrimaryExpression();
    label_11:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case SC_AND:
        ;
        break;
      default:
        jj_la1[24] = jj_gen;
        break label_11;
      }
      jj_consume_token(SC_AND);
                        t = new Teminal();
                        t.setType(Teminal.RSYMBOL);
                        t.setValue(Expression.AND);
                        exp.pushO(t);
      PrimaryExpression();
    }
  }

  static final public void PrimaryExpression() throws ParseException {
        Teminal t;
        Instruction ins;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case LPAREN:
      jj_consume_token(LPAREN);
                        t = new Teminal();
                        t.setType(Teminal.MSYMBOL);
                        t.setValue(Expression.LPAREN);
                        exp.pushO(t);
      Expression();
      jj_consume_token(RPAREN);
                        t = exp.popO();
                        if(t.getIntValue() != Expression.LPAREN)
                                {if (true) throw new ParseException("Expression Syntax Error!");}
      break;
    case INTEGER_LITERAL:
    case IDENTIFIER:
    case PLUS:
    case MINUS:
      ConditionExpression();
                while(true) {
                        t = exp.peekO();
                        if(t.getType() == Teminal.RSYMBOL) {
                                t = exp.popO();
                                ins = new Instruction();
                                ins.setName(Instruction.POPU);
                                ins.setNum1(t);
                                script.add(ins);
                                Control.nextPC();
                        }
                        else {
                                break;
                        }
                }
      break;
    default:
      jj_la1[25] = jj_gen;
      jj_consume_token(-1);
      throw new ParseException();
    }
  }

  static final public void ConditionExpression() throws ParseException {
        Teminal t1, t2;
        Teminal op = new Teminal();
        Instruction ins;
    if (jj_2_2(3)) {
      ConditionPrefix();
      jj_consume_token(EQ);
      ConditionPrefix();
          t2 = exp.popT(); t1 = exp.popT(); op.setType(Teminal.OSYMBOL); op.setValue(Expression.EQ);
    } else if (jj_2_3(3)) {
      ConditionPrefix();
      jj_consume_token(NE);
      ConditionPrefix();
          t2 = exp.popT(); t1 = exp.popT(); op.setType(Teminal.OSYMBOL); op.setValue(Expression.NE);
    } else if (jj_2_4(3)) {
      ConditionPrefix();
      jj_consume_token(LT);
      ConditionPrefix();
          t2 = exp.popT(); t1 = exp.popT(); op.setType(Teminal.OSYMBOL); op.setValue(Expression.LT);
    } else if (jj_2_5(3)) {
      ConditionPrefix();
      jj_consume_token(GT);
      ConditionPrefix();
          t2 = exp.popT(); t1 = exp.popT(); op.setType(Teminal.OSYMBOL); op.setValue(Expression.GT);
    } else if (jj_2_6(3)) {
      ConditionPrefix();
      jj_consume_token(LE);
      ConditionPrefix();
          t2 = exp.popT(); t1 = exp.popT(); op.setType(Teminal.OSYMBOL); op.setValue(Expression.LE);
    } else if (jj_2_7(3)) {
      ConditionPrefix();
      jj_consume_token(GE);
      ConditionPrefix();
          t2 = exp.popT(); t1 = exp.popT(); op.setType(Teminal.OSYMBOL); op.setValue(Expression.GE);
    } else {
      jj_consume_token(-1);
      throw new ParseException();
    }
                ins = new Instruction();
                ins.setName(Instruction.CALP);
                ins.setNum1(t1);
                ins.setNum2(t2);
                ins.setOp(op);
                script.add(ins);
                Control.nextPC();
  }

  static final public void ConditionPrefix() throws ParseException {
        int type;
        Token value, symbol;
        symbol = new Token();
        symbol.image = "";
        String strValue;
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case INTEGER_LITERAL:
    case PLUS:
    case MINUS:
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case PLUS:
      case MINUS:
        switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
        case PLUS:
          symbol = jj_consume_token(PLUS);
          break;
        case MINUS:
          symbol = jj_consume_token(MINUS);
          break;
        default:
          jj_la1[26] = jj_gen;
          jj_consume_token(-1);
          throw new ParseException();
        }
        break;
      default:
        jj_la1[27] = jj_gen;
        ;
      }
      value = jj_consume_token(INTEGER_LITERAL);
          type = Teminal.INTEGER; strValue = symbol.image + value.image;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -