
int read_dot_token() {
  int temp;
  int token;
  token = get_token();
  if (token_type == OPAR_TOK) {
    temp = read_list(); 
    token = get_token();
    return temp;
  }
  else
  if ((token_type != ATOM_TOK) && (token_type != STRING_TOK)) {
    exit_bad_sexpr();
    return 0;
  }
  else {
    temp = get_token();
    if (token_type != CPAR_TOK) {
      exit_bad_sexpr();
      return 0;
    }
    else
      return token;
  }
}

int read_list() {
  int temp;
  int token;
  int lst;
  int new_list;
  int tail;
  int done;
  lst = 0;
  tail = 0;
  token = get_token();
  done = 0;
  while ((!done) && (token_type != CPAR_TOK)) {
    if (token_type == OPAR_TOK)
      new_list = kons(read_list(), 0);
    else if (token_type == DOT_TOK) {
      temp = rplacd(tail, read_dot_token());
      done = 1;
    }
    else if (token_type == EOF_TOK) {
      exit_bad_sexpr();
      lst = 0;
      done = 1;
    }
    else if (token_type == TIC_TOK)
      new_list = kons(kons(quoteatom, kons(readin(), 0)), 0);
    else if (token_type == VECTOR_TOK)
      new_list = kons(read_vector(), 0);
    else
      new_list = kons(token, 0);
    if (!done) {
      if (lst != 0)
        tail = kdr(rplacd(tail, new_list));
      else {
        lst = new_list;
        tail = new_list;
      }
      token = get_token();
    }
  }
  return lst;
}

int read_vector() {
  int temp;
  temp = get_token();
  if (token_type == OPAR_TOK)
    return list_to_vector(read_list());
  else {
    exit_bad_sexpr();
    return 0;
  }
}

int readin() {
  int token;
  token = get_token();
  if (token_type == OPAR_TOK)
    return read_list();
  else if (token_type == TIC_TOK)
    return kons(quoteatom, kons(readin(), 0));
  else if (token_type == VECTOR_TOK)
    return read_vector();
  else if (token_type == CPAR_TOK) {
    exit_bad_sexpr();
    return 0;
  }
  else
    return token;
}

//int read_input() {
//  return readin();
//}
