code: public static <E> Apply<E> buildAst(List<Expression<E>> rpn) {
          if (rpn.isEmpty()) {
              return null;
          }
  
          Stack<Apply<E>> stack = new Stack<Apply<E>>();
          for (Expression<E> tok : rpn) {
              if (tok instanceof Arg<?>) {
                  stack.push((Arg<E>) tok);
              } else if (tok instanceof Op<?>) {
                  try {
                      if (tok instanceof Op.Mon<?>){
                         Apply<E> sub = stack.pop();
  
                          Op.Mon<E> mon = (Op.Mon<E>) tok;
  
                          mon.sub = sub;
  
                          stack.push(mon);
                      }
                      if (tok instanceof Op.Bin<?>) {
                          Apply<E> arg2 = stack.pop();
                          Apply<E> arg1 = stack.pop();
  
                          Op.Bin<E> bin = (Op.Bin<E>) tok;
  
                          bin.left = arg1;
                          bin.right = arg2;
  
                          stack.push(bin);
                      }
                  }
                  catch (EmptyStackException e) {
                      throw new CompileLogicException(
                              "No argument for operator (stack empty): "
                              + tok.toString());
                  }
              }
          }
  
          if (stack.size() > 1) {
              throw new ApplyLogicException(
                      "Stack has multiple elements after apply: " + stack.toString());
          }
  
          if (stack.size() == 0) {
              throw new ApplyLogicException(
                      "Stack has zero elements after apply.");
          }
  
          if (!(stack.peek() instanceof Apply<?>)) {
              throw new ApplyLogicException(
                      "Stack contains non-appliable tokens after apply: " + stack.toString());
          }
  
          return (stack.pop());
      }
docs: *
  Compile a rpn list of tokens into an expression tree.
  @param rpn a list of tokens in infix form.
  @return an expression tree.