示例#1
0
//parser
cellpoint read_parse(char *ibuf, char **pscan)
{
	current_state = STATE_INIT;
    stack_init(&parser_stack);
    stack_init(&state_stack);

    while (*pscan == NULL || **pscan == '\0'){
        *pscan = reload_ibuffer(ibuf);
    }

    while (1){
        if (current_state == STATE_INIT && !stack_is_empty(&parser_stack)){
            //parses a object
            return stack_pop(&parser_stack);
        }

		if (current_state == STATE_INIT){
            do_state_init(ibuf, pscan);
		}else if (current_state == STATE_SHARP){
            do_state_sharp(ibuf, pscan);
		}else if (current_state == STATE_DOT){
            do_state_dot(pscan);
		}else if (current_state == STATE_ADD){
            do_state_add(pscan);
		}else if (current_state == STATE_SUB){
            do_state_sub(pscan);
		}else if (current_state == STATE_NUM){
			//parses number object
            parse_num(pscan);
		}else if (current_state == STATE_CHAR){
            //parses character object
            parse_char(pscan);
		}else if (current_state == STATE_STR){
            //parses string object
            parse_string(ibuf, pscan);
		}else if (current_state == STATE_SYM){
			//parses symbol object
            parse_sym(pscan);
		}else if (current_state == STATE_LIST){
			//parses list object
            parse_list(ibuf, pscan);
		}else if (current_state == STATE_VEC){
			//parses vector object
            parse_vector(ibuf, pscan);
		}else {
            perror("Error: Bad state. -- READ\n");
			error_handler();
            return NIL;
        }
    }
}
示例#2
0
object_t *parse_sexp(FILE *fp){
  char buf;
  buf=skip_space_getchar(fp);

  ungetc(buf,fp);

  if(isalpha(buf) || buf=='+' || buf=='*' || buf=='-'){
    return parse_sym(fp);
  }
  else if(isdigit(buf)){
    return parse_num(fp);
  }
  else if(buf=='('){
    return parse_list(fp);
  }
  return (object_t*)NULL;
}
示例#3
0
文件: elf32.c 项目: IRNAS/mspdebug
static int syms_load_syms(struct elf32_info *info, FILE *in,
			  Elf32_Shdr *s)
{
	int len = s->sh_size / 16;
	int i;

	if (fseek(in, s->sh_offset, SEEK_SET) < 0) {
		pr_error("elf32: can't seek to symbols");
		return -1;
	}

	for (i = 0; i < len; i++) {
		Elf32_Sym y;
		int st;
		const char *name;

		if (parse_sym(&y, in) < 0) {
			pr_error("elf32: error reading symbols");
			return -1;
		}

		st = ELF32_ST_TYPE(y.st_info);
		name = info->string_tab + y.st_name;

		if (y.st_name > info->string_len) {
			printc_err("elf32: symbol out of bounds\n");
			return -1;
		}

		if (name[0] &&
		    (st == STT_OBJECT || st == STT_FUNC ||
		     st == STT_SECTION || st == STT_COMMON ||
		     st == STT_TLS) &&
		    stab_set(info->string_tab + y.st_name,
			     y.st_value) < 0)
			return -1;
	}

	return 0;
}