Package scriptingLanguage.errors

Examples of scriptingLanguage.errors.UnexpectedTokenException


  }
 
  public static Pair<String, InterpreterMethod> initMethod(AbstractClass<?> caller, Token source, AbstractFrame declared) throws InterpreterException {
    //source s/b [type] [name](<args>) { body } or [type] (<args>) { body }
    if (!source.getCarType().equals(Interpreter.identifierType))
      throw new UnexpectedTokenException("Expected an identifier, got a " + source.getCarType().getName() + ".  " + source.toString());
    String t = (String) source.getCar();
    while ((source = source.getNextToken()).equals(Interpreter.callType))
      t = t + ((String) source.getCar()) + (source = source.getNextToken()).getCar();
    AbstractClass<?> type = declared.getType(declared.getImport(t));
    if (source.getCarType().equals(Interpreter.parenthesesType))
View Full Code Here


    objects = new ArrayList<>();
    methods = new ArrayList<>();
    variables = new ArrayList<>();
    if (source.getCarType().equals(Interpreter.extendsType)) {
      if (!source.getCarType().equals(Interpreter.identifierType))
        throw new UnexpectedTokenException("Expected an identifier, got a " + source.getCarType().getName() + ".  " + source.toString());
      String extend = "";
      while (!(source = source.getNextToken()).getCarType().equals(Interpreter.curlyBracesType))
        extend = extend + source.getCar();
      superclass = frame.getType(extend);
    }
View Full Code Here

  }
 
  @Override
  public Token eval(AbstractClass<?> caller, Token parameters, AbstractFrame frame) throws InterpreterException {
    if (!parameters.getCarType().equals(Interpreter.identifierType))
      throw new UnexpectedTokenException("Expected an identifier, got a " + parameters.getCarType().getName() + ".  " + parameters.toString());
    Object data = getSource();
    String name = (String) parameters.getCar();
    if ((parameters = parameters.getNextToken()).getCarType().equals(Interpreter.parenthesesType)) {
      ArrayList<Token> args = Interpreter.evalFunctionArguments(caller, (Token) parameters.getCar(), frame);
      Class<?> source = (Class<?>) (getSource() instanceof Class<?> ? getSource() : getSource().getClass());
View Full Code Here

      int len = indecies.length();
      if (len > 0) {
        if (len != depth)
          throw new InvalidAssignmentException("Either none of the dimensions specified for an array can have a size or all of them must have a size.");
        if (last.getCarType().equals(Interpreter.curlyBracesType))
          throw new UnexpectedTokenException("If the dimensions of an array have a specified length, then the contents of the array cannot be specified.");
        return clazz.eval(caller, indecies, frame);
      }
      if (len == 0 && !last.getCarType().equals(Interpreter.curlyBracesType))
        throw new UnexpectedTokenException("If none of the dimensions have a specified length, then the contents of the array must be specified.");
      return clazz.eval(caller, last, frame);
    }
    if (!last.getCarType().equals(Interpreter.parenthesesType))
      throw new UnexpectedTokenException("Expected parentheses to complete the constructor call, but got " + last.getCarType());
    return clazz.eval(caller, (Token) last.getCar(), frame);
  }
View Full Code Here

        frame.addImport(line.getNextToken().toString());
        continue;
      }
      if (line.getCarType().equals(ifelseType)) {
        if (!line.getCar().equals("if"))
          throw new UnexpectedTokenException("If-else blocks must be started with an 'if'");
        lines.add(0, line);
        line = evalIfElse(caller, lines, frame);
        if (line == null)
          continue;
      }
View Full Code Here

    return (name.substring(name.length() - 2).equals(", ") ? name.substring(0, name.length() - 2) : name) + "}";
  }
 
  private static void makeNewType(Token line, AbstractFrame frame) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, InterpreterException {
    if (!(line = line.getNextToken()).getCarType().equals(identifierType))
      throw new UnexpectedTokenException("Expected an identifier, got a " + line.getCarType() + ".  " + line.toString());
    String type = (String) line.getCar();
    frame.addType(type, new InterpreterClass(type, line.getNextToken(), frame));
  }
View Full Code Here

      if (line.isNull()) //End of line, so we are done
        break;
      if (line.getCarType().equals(separatorType)) //Start of next assignment
        continue;
      if (!line.getCar().equals("="))
        throw new UnexpectedTokenException("Expected an = operator, but got a " + line.getCar() + " operator.");
      Token rest = line.split(), head = rest, last = null;
      while (!(head = head.getNextToken()).getCarType().equals(separatorType) && !head.isNull());
      if (head.getNextToken().getCarType().equals(separatorType))
        last = head.split();
      ((Variable<?>) value.getCar()).write(depth != 0 && rest.getCarType().equals(curlyBracesType) ? ((Variable<?>) clazz.eval(caller, rest, declared).getCar()) :
View Full Code Here

   * @throws ArrayIndexOutOfBoundsException
   * @throws InterpreterException
   */
  private static Token evalIfElse(AbstractClass<?> caller, ArrayList<Token> lines, AbstractFrame frame) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, InterpreterException {
    if (!lines.get(0).getCar().equals("if"))
      throw new UnexpectedTokenException("If-else blocks must be started with an 'if'");
    while (lines.size() > 0 && lines.get(0).getCarType().equals(ifelseType)) {
      Token line = lines.remove(0);
      if (!line.getCarType().equals(ifelseType))
        throw new UnexpectedTokenException("Expected a if-else, got a " + line.getCarType() + ".  " + line.toString());
      if (line.getCar().equals("else"))
        return eval(caller, (Token) line.getNextToken().getCar(), new Frame(frame));
      if (!line.getNextToken().getCarType().equals(parenthesesType))
        throw new UnexpectedTokenException("Expected a parenthesis, got a " + line.getNextToken().getCarType() + ".  " + line.toString());
      Token value = eval(caller, (Token) line.getNextToken().getCar(), new Frame(frame));
      if (!((Variable<?>) value.getCar()).getType().equals(booleanClass))
        throw new UnexpectedTokenException("Expected a boolean, got a " + value.getCarType() + ".  " + line.toString());
      if ((boolean) ((PrimitiveObject<Boolean>) value.getCar()).getSource())
        return eval(caller, (Token) line.getNextToken().getNextToken().getCar(), new Frame(frame));
    }
    return null;
  }
View Full Code Here

  private static Token evalLoop(AbstractClass<?> caller, ArrayList<Token> lines, AbstractFrame frame) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, InterpreterException {
    Token line = lines.remove(0);
    frame = new Frame(frame);
    if (line.getCar().equals("for")) {
      if (!line.getNextToken().getCarType().equals(parenthesesType))
        throw new UnexpectedTokenException("Expected a parenthesis, got a " + line.getNextToken().getCarType() + ".  " + line.toString());
      ArrayList<Token> inner = splitLines((Token) line.getNextToken().getCar());
      Token block = line.getNextToken().getNextToken();
      if (block.getCarType().equals(curlyBracesType))
        block = (Token) block.getCar();
      else
        block = null;
      eval(caller, inner.remove(0), frame);
      if (inner.size() < 2)
        throw new UnendedLineException("A for loop requires three arguments, got " + inner.size() + 1 + ".");
      Token incrementer = inner.remove(1);
      while (!incrementer.isNull()) {
        Token item = new Token();
        do {
          item = item.append(incrementer.singular());
        } while (!(incrementer = incrementer.getNextToken()).getCarType().equals(separatorType) && !incrementer.isNull());
        if (!incrementer.isNull())
          incrementer = incrementer.getNextToken();
        inner.add(item.getFirstToken());
      }
      while (((PrimitiveObject<Boolean>) eval(caller, inner.get(0), frame).getCar()).getSource()) {
        if (block != null) {
          Token result = eval(caller, block.clone(), new Frame(frame));
          if (result.getCarType().equals(breakType))
            if (result.getCar().equals("continue"))
              continue;
            else
              return result.getCar().equals("break") ? null : result;
        }
        for (int i = 0; i < inner.size(); i++)
          eval(caller, inner.get(i).clone(), frame);
      }
    }
    else {
      Token block = null;
      if (line.getCar().equals("do")) {
        if (!line.getNextToken().getCarType().equals(curlyBracesType))
          throw new UnexpectedTokenException("Expected a curly brace, got a " + line.getNextToken().getCarType() + ".  " + line.toString());
        block = (Token) line.getNextToken().getCar();
        Token result = eval(caller, block.clone(), new Frame(frame));
        if (result.getCarType().equals(breakType) && !result.getCar().equals("continue"))
          return result.getCar().equals("break") ? null : result;
        line = lines.remove(0);
      }
      else
        block = (Token) line.getNextToken().getNextToken().getCar();
      if (!line.getNextToken().getCarType().equals(parenthesesType))
        throw new UnexpectedTokenException("Expected a parenthesis, got a " + line.getNextToken().getCarType() + ".  " + line.toString());
      Token condition = (Token) line.getNextToken().getCar();
      while (((PrimitiveObject<Boolean>) eval(caller, condition.clone(), frame).getCar()).getSource()) {
        if (block != null) {
          Token result = eval(caller, block.clone(), new Frame(frame));
          if (result.getCarType().equals(breakType))
View Full Code Here

 
  @Override
  public Token eval(AbstractClass<?> caller, Token first, Token last, AbstractFrame frame) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, InterpreterException {
    Variable<?> f = (Variable<?>) (first.getCar() instanceof String ? frame.readVariable((String) first.getCar()).getCar() : first.getCar());
    if (!(f instanceof AbstractObject<?>))
      throw new UnexpectedTokenException("Expected an object, got a " + f.getType() + ".  ");
    return f.eval(caller, (Token) last.getCar(), frame);
  }
View Full Code Here

TOP

Related Classes of scriptingLanguage.errors.UnexpectedTokenException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.