Package de.tuhrig.thofu.types

Examples of de.tuhrig.thofu.types.LList


    try {

      parser.validate(expression);

      LList tokens = parser.parse(expression);

      LObject result = execute(tokens, root);
     
      return result.toString();
    }
View Full Code Here


        parse(tmp, tokens);
      }
      else if (current.equals(LEFT_PARENTHESIS)) {

        LList tmp = new LList();

        if (list == null)
          list = tmp;
        else
          list.add((LObject) tmp);
View Full Code Here

        String command = buffer.toString().trim();

        if (!command.trim().equals(EMPTY)) {
         
          LList tmp = parse(command);
         
          objects.add(tmp);
        }

        buffer = new StringBuffer();
View Full Code Here

      if(environment.contains((LSymbol) tokens))
        return tokens.run(environment, null);
    }
    else if(tokens instanceof LList && !(tokens instanceof LTupel)) {
     
      LList tmp = (LList) tokens;
     
      LObject first = replace(tmp.getFirst(), environment);
     
      // only replace in-built operations
      if(first instanceof LOperation && !(first instanceof LLambda)) {
       
        tmp.set(0, first);
      }
     
      ListIterator<LObject> iterator = tmp.listIterator();
     
      while(iterator.hasNext()) {
       
        LObject token = iterator.next();
       
View Full Code Here

  @Override
  public LList parse(String expression) {

    List<Object> tokens = toTokens(expression);

    LList result = parse(tokens);
   
    //System.out.println("result: " + result);
   
    return result;
  }
View Full Code Here

 
  private LList parse(List<Object> tokens) {

    //System.out.println("parse " + tokens);
   
    LList list = new LList();

    while(tokens.size() > 0) {
     
      Object token = tokens.remove(0);
     
      /*
       * THOFU LANGUAGE
       */
     
      if(token.equals(";")) {

        return strip(list);
      }
      else if(token.equals("[")) {
       
        return list(tokens);
      }
      else if(token.equals("var")) {
       
        return defination(tokens);
      }
      else if(token.equals("=")) {
        
        return assignment(list, tokens);
      }
      else if(token.equals("for")) {

        return forLoop(tokens);
      }
      else if(token.equals("while")) {
       
        return whileLoop(tokens);
      }
      else if(token.equals("do")) {
       
        return doLoop(tokens);
      }
      else if(token.toString().startsWith("++")) {
       
        return crementBefore(list, token.toString(), "++", "+");
      }
      else if(token.toString().endsWith("++")) {
 
        return crementAfter(list, token.toString(), "++", "+");
      }
      else if(token.toString().startsWith("--")) {
       
        return crementBefore(list, token.toString(), "--", "-");
      }
      else if(token.toString().endsWith("--")) {
         
        return crementAfter(list, token.toString(), "--", "-");
      }
      else if(token.equals(".")) {

        return chain(list, tokens);
      }
      else if(token.equals("if")) {
       
        return ifBlock(list, tokens, token);
      }
      else if(token.equals("function")) {

        return function(tokens);
      }
      else if(token.equals("{")) {    // create new let
     
        return block(tokens);
      }     
      else if(token.equals("}")) {    // close let

        return strip(list);
      }
      else if(isBinaryOperator(token)) {    // any look up for binary operators?
                          // maybe dynamically editable?
        return binary(list, tokens, token);
      }
      else if(token.equals("(")) {

        List<LList> instructions = parenthesis(tokens);
       
        for(LList tmp : instructions) {
         
          if(tmp.size() == 1)
            list.add(tmp.get(0));
          else
            list.add(tmp);
        }
      }
     
      /*
       * JAVA API
       */
     
      else if(token.equals("new")) { 

        return constructor(list, tokens, token);
      }
      else if(token.toString().contains(".") && !token.toString().startsWith("\"")) { 

        // look ahead
        Object next = tokens.get(0);
       
        if(next.toString().equals("(")) {
         
          return method(list, tokens, token);
        }
        else {
       
          return field(list, tokens, token);
        }
      }
     
      /*
       * REST
       */
     
      else {

        list.add(type(token));
      }
     
      // close working list
      if(list.size() == 3) {
       
        tokens.add(0, list);

        list = new LList();
      }
    }

    // should never be reached!
    throw new RuntimeException("No ; found at end of statement");
View Full Code Here

   
    Object object = tokens.remove(0);

    list.add(type(object + "."));

    LList parameters = parse(tokens);
   
    if(parameters.size() == 1) {
     
      list.add(parameters.get(0));
    }
    else {
     
      for(int i = 0; i < parameters.size(); i++)
        list.add(parameters.get(i));
    }
     
    return list;
  }
View Full Code Here

//    System.out.println(list);
//    System.out.println(tokens);
//    System.out.println(token);

    LList parameters = parse(tokens);
   
    //System.out.println(parameters);
   
    String[] parts = token.toString().split("\\.");

    list.add(type("." + parts[1]));
    list.add(type(parts[0]));
   
    if(parameters.size() == 1) {
     
      list.add(parameters.get(0));
    }
    else {
     
      for(int i = 0; i < parameters.size(); i++)
        list.add(parameters.get(i));
    }

    return list;
  }
View Full Code Here

        List<Object> tmp = new ArrayList<>();
        tmp.add(obj);
        tmp.add(";");
       
        LList element = parse(tmp);
       
        list.add(element.get(0));
      }
    }
   
    tokens.add(0, list);
View Full Code Here

  private LList defination(List<Object> tokens) {

    Object name = tokens.remove(0);
            tokens.remove(0);    // =

    LList defination = new LList();
   
    defination.add(type("define"));
    defination.add(type(name));
   
    if(tokens.size() > 0)
      defination.add(parse(tokens));
    else
      defination.add(type("null"));
   
    return defination;
  }
View Full Code Here

TOP

Related Classes of de.tuhrig.thofu.types.LList

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.