Package scriptingLanguage.frames

Examples of scriptingLanguage.frames.Frame


    return eval(args);
  }
 
  @Override
  public Token eval(ArrayList<Token> args) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, InterpreterException {
    Frame base = new Frame(getDeclared(), getDeclared().getInterpreter());
    for (int i = 0; i < args.size(); i++)
      base.writeVariable(this.getParameters()[i].getName(), args.get(i), true);
    Token result = getDeclared().getInterpreter().eval(container, getSource(), base);
    AbstractClass<?> returnType = ((AbstractMethodClass) getType()).getReturnType();
    if (returnType.equals(Interpreter.voidClass) && !result.isNull())
      throw new UnexpectedTypeException("Cannot return a value from a void function.");
    if (((Variable<?>) (result = result.getNextToken()).getCar()).getType().extend(returnType) == -1)
View Full Code Here


 
  public InterpreterClass(String name, Token source, AbstractFrame frame, Type<?> tokenType) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, InterpreterException {
    super(name, source, tokenType);
    Interpreter interpreter = frame.getInterpreter();
    frames = new Frame[4];
    frames[0] = new Frame(frame, interpreter);
    frames[1] = new Frame(frames[0], interpreter);
    frames[2] = new Frame(frames[1], interpreter);
    frames[3] = new Frame(frames[2], interpreter);
    objects = new ArrayList<>();
    methods = new ArrayList<>();
    variables = new ArrayList<>();
    if (source.getCarType().equals(Interpreter.extendsType)) {
      if (!source.getCarType().equals(Interpreter.identifierType))
View Full Code Here

      lines.add(head);
    return lines;
  }
 
  public String eval(String program) throws InterpreterException, LexerException {
    Frame frame = new Frame(root, this);
    Token output = eval(ObjectClass, lexer.lex(program), frame);
    return output.getCarType().equals(breakType) ? output.getNextToken().toString() : output.toString();
  }
View Full Code Here

    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

    return null;
  }
 
  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))
            if (result.getCar().equals("continue"))
              continue;
            else
              return result.getCar().equals("break") ? null : result;
View Full Code Here

TOP

Related Classes of scriptingLanguage.frames.Frame

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.