Package scriptingLanguage.errors

Examples of scriptingLanguage.errors.UnexpectedTypeException


 
  @Override
  public Token eval(AbstractClass<?> caller, Token first, Token last, AbstractFrame frame) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, InterpreterException {
    Variable<?> f = (Variable<?>) first.getCar(), l = (Variable<?>) last.getCar();
    if (!Interpreter.isPrimitive(f.getType()) || !Interpreter.isPrimitive(l.getType()))
      throw new UnexpectedTypeException("The types, " + f.getType() + " and " + l.getType() + ", are not compatible with the " + data + " operation.");
    PrimitiveObject<?>[] p = Interpreter.castPrimitives((PrimitiveObject<?>) f, (PrimitiveObject<?>) l);
    switch (data) {
      case "<":
        return new Token(new PrimitiveObject<>(Interpreter.booleanClass, p[0].getType().compareValues(p[0].getSource(), p[1].getSource()) < 0), Interpreter.booleanType);
      case "<=":
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(), l = (Variable<?>) last.getCar();
    if (!Interpreter.isPrimitive(f.getType()) || !Interpreter.isPrimitive(l.getType()))
      throw new UnexpectedTypeException("The types, " + f.getType() + " and " + l.getType() + ", are not compatible with the " + data + " operation.");
    PrimitiveObject<?>[] p = Interpreter.castPrimitives((PrimitiveObject<?>) f, (PrimitiveObject<?>) l);
    if (data.equals("=="))
      return new Token(new PrimitiveObject<>(Interpreter.booleanClass, p[0].getType().compareValues(p[0].getSource(), p[1].getSource()) == 0), Interpreter.booleanType);
    if (data.equals("!="))
      return new Token(new PrimitiveObject<>(Interpreter.booleanClass, p[0].getType().compareValues(p[0].getSource(), p[1].getSource()) != 0), Interpreter.booleanType);
View Full Code Here

            (boolean) ((PrimitiveObject<Boolean>) l).getSource()), Interpreter.booleanType);
      PrimitiveObject<?>[] p = Interpreter.castPrimitives((PrimitiveObject<?>) f, (PrimitiveObject<?>) l);
      return new Token(p[0].getType().makePrimitiveObject(p[0].getType().equals(Interpreter.characterClass) ? (((Character) p[0].getSource()).charValue() & ((Character) p[1].getSource()).charValue()) :
          (((Number) p[0].getSource()).longValue() & ((Number) p[1].getSource()).longValue())), p[0].getType().getTokenType());
    }
    throw new UnexpectedTypeException("The operation, " + data + ", is not defined for the types, " + f.getType() + " and " + l.getType() + ".");
  }
View Full Code Here

            (boolean) ((PrimitiveObject<Boolean>) l).getSource()), Interpreter.booleanType);
      PrimitiveObject<?>[] p = Interpreter.castPrimitives((PrimitiveObject<?>) f, (PrimitiveObject<?>) l);
      return new Token(p[0].getType().makePrimitiveObject(p[0].getType().equals(Interpreter.characterClass) ? (((Character) p[0].getSource()).charValue() ^ ((Character) p[1].getSource()).charValue()) :
          (((Number) p[0].getSource()).longValue() ^ ((Number) p[1].getSource()).longValue())), p[0].getType().getTokenType());
    }
    throw new UnexpectedTypeException("The operation, " + data + ", is not defined for the types, " + f.getType() + " and " + l.getType() + ".");
  }
View Full Code Here

            (boolean) ((PrimitiveObject<Boolean>) l).getSource()), Interpreter.booleanType);
      PrimitiveObject<?>[] p = Interpreter.castPrimitives((PrimitiveObject<?>) f, (PrimitiveObject<?>) l);
      return new Token(p[0].getType().makePrimitiveObject(p[0].getType().equals(Interpreter.characterClass) ? (((Character) p[0].getSource()).charValue() | ((Character) p[1].getSource()).charValue()) :
          (((Number) p[0].getSource()).longValue() | ((Number) p[1].getSource()).longValue())), p[0].getType().getTokenType());
    }
    throw new UnexpectedTypeException("The operation, " + data + ", is not defined for the types, " + f.getType() + " and " + l.getType() + ".");
  }
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();
    if (!f.getType().equals(Interpreter.booleanClass))
      throw new UnexpectedTypeException("The type, " + f.getType() + ", is not compatible with the attempted operation.");
    if (!((Variable<Boolean>) f).getSource())
      return new Token(new PrimitiveObject<>(Interpreter.booleanClass, false), Interpreter.booleanType);
    if (last.getCarType().equals(Interpreter.blockType))
      last = (Token) last.getCar();
    last = Interpreter.eval(caller, last, frame);
    if (!((Variable<?>) last.getCar()).getType().equals(Interpreter.booleanClass))
      throw new UnexpectedTypeException("The type, " + last.getCarType() + ", is not compatible with the attempted operation.");
    return new Token(new PrimitiveObject<>(Interpreter.booleanClass, ((Variable<Boolean>) last.getCar()).getSource()), Interpreter.booleanType);
  }
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();
    if (!f.getType().equals(Interpreter.booleanClass))
      throw new UnexpectedTypeException("The type, " + f.getType() + ", is not compatible with the attempted operation.");
    if (((Variable<Boolean>) f).getSource())
      return new Token(new PrimitiveObject<>(Interpreter.booleanClass, true), Interpreter.booleanType);
    if (last.getCarType().equals(Interpreter.blockType))
      last = (Token) last.getCar();
    last = Interpreter.eval(caller, last, frame);
    if (!((Variable<?>) last.getCar()).getType().equals(Interpreter.booleanClass))
      throw new UnexpectedTypeException("The type, " + last.getCarType() + ", is not compatible with the attempted operation.");
    return new Token(new PrimitiveObject<>(Interpreter.booleanClass, ((Variable<Boolean>) last.getCar()).getSource()), Interpreter.booleanType);
  }
View Full Code Here

  }
 
  @Override
  public Token eval(AbstractClass<?> caller, Token first, Token last, AbstractFrame frame) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, InterpreterException {
    if (!first.getCarType().equals(Interpreter.booleanType))
      throw new UnexpectedTypeException("The first argument to the ternary operator must be a boolean, but it got a " + ((Variable<?>) first.getCar()).getType());
    return Interpreter.eval(caller, ((PrimitiveObject<Boolean>) first.getCar()).getSource() ? ((Ternary) last.getCar()).getTrue() : ((Ternary) last.getCar()).getFalse(), frame);
  }
View Full Code Here

TOP

Related Classes of scriptingLanguage.errors.UnexpectedTypeException

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.