Beispiel #1
0
object_t primitive_read(object_t argl) {
  object_t r = parse_sexp(read_sexp(stdin));
  if(r == NULL)
    return obj_new_symbol("_empty_");
  else
    return r;
}
Beispiel #2
0
object_t read_file(char *filename) {
  FILE *f = fopen(filename, "r");
  char *input;
  object_t seq = cons(obj_new_symbol("begin"), NIL);
  while((input = read_sexp(f)) != NULL) {
    object_t exp = parse_sexp(input);
    storage_append(exp, seq);
  }
  return seq;
}
Beispiel #3
0
Datei: lisp.c Projekt: qyqx/wisp
object_t *lisp_read_string (object_t * lst)
{
  DOC ("Parse a string into a sexp or list object.");
  REQ (lst, 1, c_sym ("eval-string"));
  object_t *stro = CAR (lst);
  if (!STRINGP (stro))
    THROW (wrong_type, UPREF (stro));
  char *str = OSTR (stro);
  reader_t *r = reader_create (NULL, str, "eval-string", 0);
  object_t *sexp = read_sexp (r);
  reader_destroy (r);
  if (sexp == err_symbol)
    THROW (c_sym ("parse-error"), UPREF (stro));
  return sexp;
}
Beispiel #4
0
int main(int argc, char **argv) {
  while(1) {
    printf("> ");
    struct node *lines = read_sexp(stdin);
    object_t sexp = parse_sexp(lines);
    
    if(*(char*)lines->data == 'q') {
      auxfor_each(lines, &free_node_and_string);
      return 0;
    }
    print_object(sexp);
    printf("\n");

    auxfor_each(lines, &free_node_and_string);
  }
}
Beispiel #5
0
static Obj *read(Env *env, Obj *root, char **p) {
    for (;;) {
        char c = **p;
        (*p)++;
        if (c == '\0')
            return NULL;
        if (c == ' ' || c == '\n' || c == '\r' || c == '\t')
            continue;
        if (c == '(')
            return read_sexp(env, root, p);
        if (c == ')')
            error("unclosed open parenthesis");
        if (c == '\'')
            return read_quote(env, root, p);
        if (isdigit(c))
            return read_number(env, root, p, c - '0');
        if (isalpha(c) || strchr("+=!@#$%^&*", c))
            return read_symbol(env, root, p, c);
        error("don't know how to handle %c", c);
    }
}
Beispiel #6
0
void driver_loop(void)
{
	initial();
	printf("initialed.\n");
	while (1){
		if (setjmp(jump_buffer) == 0){
			printf("\n%s\n", input_prompt);
			reg = read_sexp();
			//eval the expression with tail_context is a_false
			args_push(a_false);
			args_push(reg);
			reg = eval();
			printf("\n%s\n", output_prompt);
			write(reg);
			newline();
		}else {
			//error handler, initial some variables
			vars_init();
		}
	}
}
Beispiel #7
0
/* Use the core functions above to eval each sexp in a file. */
int load_file (FILE * fid, char *filename, int interactive)
{
  if (fid == NULL)
    {
      fid = fopen (filename, "r");
      if (fid == NULL)
	return 0;
    }
  reader_t *r = reader_create (fid, NULL, filename, interactive);
  while (!r->eof)
    {
      object_t *sexp = read_sexp (r);
      if (sexp != err_symbol)
	{
	  object_t *ret = top_eval (sexp);
	  if (r->interactive && ret != err_symbol)
	    obj_print (ret, 1);
	  obj_destroy (sexp);
	  obj_destroy (ret);
	}
    }
  reader_destroy (r);
  return 1;
}
Beispiel #8
0
object_t read_stream(FILE *stream) {
  input = read_sexp(stream);
  return parse_sexp(input);  
}