Ejemplo n.º 1
0
 /**
  * Parse and execute. Parsing begins right after the "new" keyword and the operation name token.
  *
  * @param sp is the script parser to use to help in the parsing.
  * @param currentStream is the current token stream.
  * @return the variable reference that got created. Should never be null.
  */
 @Override
 public VariableReference parseAndCreate(ScriptParser sp, TokenStream currentStream)
     throws ScriptException {
   VariableReference connectionName = sp.evaluateExpression(currentStream);
   if (connectionName == null) sp.syntaxError(currentStream, "Need connection name expression");
   String connectionNameString =
       sp.resolveMustExist(currentStream, connectionName).getStringValue();
   return new VariableConnectionName(connectionNameString);
 }
  /**
   * Assembles the source code.
   *
   * @param var the variable to assign the value to
   */
  @Override
  public void assemble(Register var) throws IOException {
    AssembleExpression.assembleIfRequired(this.fontFace);
    String write = name + " " + var + " " + this.fontFace;

    if (this.height != null) {
      AssembleExpression.assembleIfRequired(this.height);
      write += " " + this.height;

      if (this.weight != null) {
        AssembleExpression.assembleIfRequired(this.weight);
        write += " " + this.weight;

        if (this.italic != null) {
          AssembleExpression.assembleIfRequired(this.italic);
          if (this.italic.getBooleanValue() == true) write += " /ITALIC";

          if (this.underline != null) {
            AssembleExpression.assembleIfRequired(this.underline);
            if (this.underline.getBooleanValue() == true) write += " /UNDERLINE";

            if (this.strike != null) {
              AssembleExpression.assembleIfRequired(this.strike);
              if (this.strike.getBooleanValue() == true) write += " /STRIKE";
            }
          }
        }
      }
    }

    ScriptParser.writeLine(write);
  }
Ejemplo n.º 3
0
 /**
  * Assembles the source code.
  *
  * @param var the variable to assign the value to
  */
 @Override
 public void assemble(Register var) throws IOException {
   Expression varOrString = AssembleExpression.getRegisterOrExpression(this.string);
   if (this.maxLen != null) {
     Expression varOrMaxLen = AssembleExpression.getRegisterOrExpression(this.maxLen);
     if (this.startOffset != null) {
       Expression varOrStartOffset = AssembleExpression.getRegisterOrExpression(this.startOffset);
       ScriptParser.writeLine(
           name + " " + var + " " + varOrString + " " + varOrMaxLen + " " + varOrStartOffset);
       varOrStartOffset.setInUse(false);
     } else {
       ScriptParser.writeLine(name + " " + var + " " + varOrString + " " + varOrMaxLen);
     }
     varOrMaxLen.setInUse(false);
   } else {
     ScriptParser.writeLine(name + " " + var + " " + varOrString);
   }
   varOrString.setInUse(false);
 }
 /** Assembles the source code. */
 @Override
 public void assemble() throws IOException {
   Expression varOrIniFile = AssembleExpression.getRegisterOrExpression(this.iniFile);
   ScriptParser.writeLine(name + " " + varOrIniFile);
   varOrIniFile.setInUse(false);
 }
 /**
  * Assembles the source code.
  *
  * @param var the variable to assign the value to
  */
 @Override
 public void assemble(Register var) throws IOException {
   ScriptParser.writeLine(name + " " + var);
 }
 /** Assembles the source code. */
 @Override
 public void assemble() throws IOException {
   AssembleExpression.assembleIfRequired(this.value);
   ScriptParser.writeLine(name + " " + this.value);
 }
Ejemplo n.º 7
0
  public void run() {
    while (true) {
      boolean doParse;
      mStatusLock.lock();
      doParse = mParse;
      if (mAbort) {
        mAbort = false;
      }
      mStatusLock.unlock();
      if (!doParse) {
        yield();
        try {
          sleep(500);
        } catch (InterruptedException e) {
        }
        continue;
      }

      mStreamLock.lock();
      if (mNext != mInputStream) {
        mInputStream = mNext;
        if (mInputStream == null) {
          mStatusLock.lock();
          mParse = false;
          mStatusLock.unlock();
          mStreamLock.unlock();
          continue;
        }
      }
      mStreamLock.unlock();
      try {
        // open file
        mStreamLock.lock();
        ANTLRInputStream ais = new ANTLRInputStream(mInputStream);
        mStreamLock.unlock();
        ScriptLexer lexer = new ScriptLexer(ais);
        CommonTokenStream cts = new CommonTokenStream(lexer);
        ScriptParser parser = new ScriptParser(cts);

        if (checkAbort()) {
          continue;
        }

        // parse it and get the model
        ScriptModel sm = parser.script();
        if (mScriptName != null) {
          mStatusLock.lock();
          sm.setName(mScriptName.getName());
          mStatusLock.unlock();
        }

        // close resources
        parser = null;
        cts = null;
        lexer = null;
        ais = null;
        mStreamLock.lock();
        mInputStream.close();
        mStreamLock.unlock();

        if (checkAbort()) {
          continue;
        }
        mStatusLock.lock();
        mParse = false; // we parsed successfully
        mStatusLock.unlock();

        // check for invalid lines
        ArrayList<Integer> l = new ArrayList<Integer>();
        for (CommandModel cm : sm) {
          if (!cm.getBody().validates()) {
            l.add(new Integer(cm.getStartLine()));
          }
        }
        int inv[] = new int[l.size()];
        for (int i = 0; i < inv.length; i++) {
          inv[i] = l.get(i).intValue();
        }

        if (checkAbort()) {
          continue;
        }

        // update GUI
        SwingUtilities.invokeLater(new ParserGuiConnection(sm, inv));
      } catch (Exception e) {
        ErrorHandler.getInstance().logErrorDetails(e);
      }
    }
  }
Ejemplo n.º 8
0
 /**
  * Parse and skip. Parsing begins right after the "new" keyword and the operation name token.
  *
  * @param sp is the script parser to use to help in the parsing.
  * @param currentStream is the current token stream.
  */
 @Override
 public void parseAndSkip(ScriptParser sp, TokenStream currentStream) throws ScriptException {
   sp.skipExpression(currentStream);
 }
Ejemplo n.º 9
0
  /**
   * Assembles the source code.
   *
   * @throws IOException
   */
  @Override
  public void assemble() throws IOException {
    // Do not assemble anything if there are no cases!
    if (this.casesList.isEmpty()) return;

    // Give each case a label.
    for (SwitchCaseStatement statement : this.casesList)
      statement.setLabel(LabelList.getCurrent().getNext());
    if (this.defaultCase != null) this.defaultCase.setLabel(LabelList.getCurrent().getNext());

    Label gotoEnd = LabelList.getCurrent().getNext();
    Label gotoStart = LabelList.getCurrent().getNext();

    // Go to the jump table which is assembled after the switch case labels and
    // statements.
    ScriptParser.writeLine("Goto " + gotoStart);

    // Using "break;" inside a switch jumps to the end.
    Label parentBreak = CodeInfo.getCurrent().setBreakLabel(gotoEnd);

    // Assemble all the statements inside the switch { }. This includes the
    // case labels.
    for (Statement statement : this.statementList) statement.assemble();

    // Restore the parent break label.
    CodeInfo.getCurrent().setBreakLabel(parentBreak);

    // Label at the top of the jump table.
    gotoStart.write();

    // Jump instructions can jump directly to the case labels.
    if (this.switchExpression instanceof JumpExpression) {
      ((JumpExpression) this.switchExpression).assemble(this.casesList);
    }
    // Other expressions we just assemble them if required and compare their
    // result.
    else {
      Expression varOrSwitchExpression =
          AssembleExpression.getRegisterOrExpression(this.switchExpression);
      for (SwitchCaseStatement caseStatement : this.casesList) {
        // Type is an integer; use IntCmp.
        if (caseStatement.getMatch().getType().equals(ExpressionType.Integer)) {
          ScriptParser.writeLine(
              String.format(
                  "IntCmp %s %s %s",
                  varOrSwitchExpression, caseStatement.getMatch(), caseStatement.getLabel()));
        }
        // Type is a string; use StrCmp or StrCmpS (if special `` quotes were
        // used).
        else {
          ScriptParser.writeLine(
              String.format(
                  "StrCmp%s %s %s %s",
                  caseStatement.getMatch().getType().equals(ExpressionType.StringSpecial)
                      ? "S"
                      : "",
                  varOrSwitchExpression,
                  caseStatement.getMatch(),
                  caseStatement.getLabel()));
        }
      }
      varOrSwitchExpression.setInUse(false);
    }

    // Default case jump.
    if (this.defaultCase != null) ScriptParser.writeLine("Goto " + this.defaultCase.getLabel());

    gotoEnd.write();
  }