コード例 #1
0
ファイル: datatype_decl_plugin.cpp プロジェクト: CHolmes3/z3
sort * datatype_decl_plugin::mk_sort(decl_kind k, unsigned num_parameters, parameter const * parameters) {
    try {
        if (k != DATATYPE_SORT) {
            throw invalid_datatype();
        }
        buffer<bool, false, 256> found;
        unsigned num_types = read_int(num_parameters, parameters, 0, found);
        if (num_types == 0) {
            throw invalid_datatype();
        }
        unsigned tid       = read_int(num_parameters, parameters, 1, found);
        for (unsigned j = 0; j < num_types; j++) {
            read_symbol(num_parameters, parameters, 2 + 2*j, found); // type name
            unsigned       o          = read_int(num_parameters, parameters, 2 + 2*j + 1, found);
            unsigned num_constructors = read_int(num_parameters, parameters, o, found);
            if (num_constructors == 0) {
                throw invalid_datatype();
            }
            for (unsigned s = 1; s <= num_constructors; s++) {
                unsigned k_i            = read_int(num_parameters, parameters, o + s, found);
                read_symbol(num_parameters, parameters, k_i, found);      // constructor name
                read_symbol(num_parameters, parameters, k_i + 1, found);  // recognizer name
                unsigned num_accessors  = read_int(num_parameters, parameters, k_i + 2, found); 
                unsigned first_accessor = k_i+3;
                for (unsigned r = 0; r < num_accessors; r++) {
                    read_symbol(num_parameters, parameters, first_accessor + 2*r, found); // accessor name
                    parameter const & a_type = read(num_parameters, parameters, first_accessor + 2*r + 1, found); // accessort type
                    if (!a_type.is_int() && !a_type.is_ast()) {
                        throw invalid_datatype();
                        if (a_type.is_ast() && !is_sort(a_type.get_ast())) {
                            throw invalid_datatype();
                        }
                    }
                }
            }
        }
        // check if there is no garbage
        if (found.size() != num_parameters || std::find(found.begin(), found.end(), false) != found.end()) {
            throw invalid_datatype();
        }

        if (!is_well_founded(parameters)) {
            m_manager->raise_exception("datatype is not well-founded");
            return 0;
        }
        
        // compute datatype size
        sort_size ts = get_datatype_size(parameters);
        symbol const & tname = parameters[2+2*tid].get_symbol();
        return m_manager->mk_sort(tname,
                                  sort_info(m_family_id, k, ts, num_parameters, parameters, true));
    }
    catch (invalid_datatype) {
        m_manager->raise_exception("invalid datatype");
        return 0;
    }
}
コード例 #2
0
ファイル: dpp.c プロジェクト: ageneau/ecl-mirror
char *
read_token(void)
{
        int c;
        int left_paren = 0;
        char *p;

        p = poolp;
        c = readc();
        while (isspace(c))
                c = readc();
        do {
                if (c == '(') {
                        left_paren++;
                        pushc(c);
                } else if (c == ')') {
                        if (left_paren == 0) {
                                break;
                        } else {
                                left_paren--;
                                pushc(c);
                        }
                } else if (isspace(c) && left_paren == 0) {
                        do
                                c = readc();
                        while (isspace(c));
                        break;
                } else if (c == '@') {
                        c = readc();
                        if (c == '\'') {
                                (void)read_symbol(0);
                                poolp--;
                        } else if (c == '[') {
                                (void)read_symbol(1);
                                poolp--;
                        } else if (c == '@') {
                                pushc(c);
                        } else {
                                char *name;
                                unreadc(c);
                                poolp = name = read_function();
                                (void)translate_function(poolp);
                        }
                } else {
                        pushc(c);
                }
                c = readc();
        } while (1);
        unreadc(c);
        pushc('\0');
        return(p);
}
コード例 #3
0
void unpack_block(FILE *f, scan_desc_t *scan_desc, uint32_t index, 
		  int32_t T[_BSIZE])
{
	printdecod("Start unpack_block #%u (index = %u)\n",calls_count,index);
	assert(feof(f) == 0);
	huff_table_t *DC = scan_desc->table[0][index];
	huff_table_t *AC = scan_desc->table[1][index];
	if (DC == NULL || AC == NULL) {
		printf("\n** ERREUR: Table de Huffman absente **\n");
	}
	assert(DC != NULL);
	assert(AC != NULL);
	/* decodage du coefficient DC */
	uint8_t magnitude = read_symbol(f,scan_desc,DC);
	int32_t offset = read_value(f,scan_desc,magnitude);
	T[0] = scan_desc->pred[index] + offset;
	scan_desc->pred[index] = T[0];
	/* decodage des coefficients AC */
	uint8_t symbol;
	uint8_t nb_zero;
	uint32_t i = 1;
	while (i < 64) {
		symbol = read_symbol(f,scan_desc,AC);
		if (symbol == 0xf0) {        /* ZRL */
			for (uint32_t j = 0; j < 16; j++) {
				T[i] = 0;
				i++;
			}	
		} else if (symbol == 0x00) { /* EOB */
			while (i < 64) {
				T[i] = 0;
				i++;
			}
		} else {                     /* symbole normal */
			magnitude = symbol % 16;
			nb_zero = symbol >> 4;
			printdecod("=> sym: %u   mag: %u  nb_zero: %u\n",symbol,
			   magnitude,nb_zero);
			for (uint32_t j = 0; j < nb_zero; j++) {
				T[i] = 0;
				i++;
			}
			T[i] = read_value(f,scan_desc,magnitude);
			i++;
		}
	}
	printdecod("\n");
	printblock(T);
	calls_count++;
}
コード例 #4
0
ファイル: minilisp.c プロジェクト: cgbystrom/scriptorium
static Obj *read_expr(void *root) {
    for (;;) {
        int c = getchar();
        if (c == ' ' || c == '\n' || c == '\r' || c == '\t')
            continue;
        if (c == EOF)
            return NULL;
        if (c == ';') {
            skip_line();
            continue;
        }
        if (c == '(')
            return read_list(root);
        if (c == ')')
            return Cparen;
        if (c == '.')
            return Dot;
        if (c == '\'')
            return read_quote(root);
        if (isdigit(c))
            return make_int(root, read_number(c - '0'));
        if (c == '-' && isdigit(peek()))
            return make_int(root, -read_number(0));
        if (isalpha(c) || strchr(symbol_chars, c))
            return read_symbol(root, c);
        error("Don't know how to handle %c", c);
    }
}
コード例 #5
0
ファイル: glpmpl2.c プロジェクト: ChrisMoreton/Test3
MEMBER *read_value
(     MPL *mpl,
      PARAMETER *par,         /* not changed */
      TUPLE *tuple            /* destroyed */
)
{     MEMBER *memb;
      insist(par != NULL);
      insist(is_symbol(mpl));
      /* there must be no member with the same n-tuple */
      if (find_member(mpl, par->array, tuple) != NULL)
         error(mpl, "%s%s already defined",
            par->name, format_tuple(mpl, '[', tuple));
      /* create new parameter member with given n-tuple */
      memb = add_member(mpl, par->array, tuple);
      /* read value and assigns it to the new parameter member */
      switch (par->type)
      {  case A_NUMERIC:
         case A_INTEGER:
         case A_BINARY:
            if (!is_number(mpl))
               error(mpl, "%s requires numeric data", par->name);
            memb->value.num = read_number(mpl);
            break;
         case A_SYMBOLIC:
            memb->value.sym = read_symbol(mpl);
            break;
         default:
            insist(par != par);
      }
      return memb;
}
コード例 #6
0
ファイル: add_phone.c プロジェクト: RomanGrekov/I7_RTOS
void add_phone(void){
	button *btn;
	uint8_t btn_val;
	uint8_t symbol;

	keyboard my_kb =
			{CURSOR_BLINK,
			12,
			3,
			{{'0', 0 , 0 , 0 , 0 ,' '},
			{'1','_', 0 , 0 , 0 , 0 },
			{'2','a','b','c', 0 , 0 },
			{'3','d','e','f', 0 , 0 },
			{'4','g','h','i', 0 , 0 },
			{'5','j','k','l', 0 , 0 },
			{'6','m','n','o', 0 , 0 },
			{'7','p','q','r','s', 0 },
			{'8','t','u','v', 0 , 0 },
			{'9','w','x','y','z', 0 },
			{'<', 0 , 0 , 0 , 0 ,'#'},
			{'*','+', 0 , 0 , 0 ,'^'}},
			"Type text",
			"012345678"};

	text_editor_init(&my_kb);
	do{
		btn = get_btn();
		btn_val = btn->button;
		if(btn_val){
			key_controller(btn_val, btn->duration);
		}
		symbol = read_tmp_symbol();
		if(symbol){
			lcd_putc(symbol);
		}
		symbol = read_symbol();
		if(symbol){
			cursor_shift(RIGHT);
		}

/*
		switch (btn_val){
		case '2':

			break;
		case '1':

			break;
		case '3':

			break;
		case '*':

		}
*/
	}while (btn_val != '2');
	text_editor_close();
}
コード例 #7
0
ファイル: git-auth.c プロジェクト: LowH/git-auth
static void rule_read (s_rule *r, const char *buf)
{
  const char *b = buf;
  t_sym s;
  while ((s = read_symbol(&b)) && (*s != '#')) {
    syslog(LOG_DEBUG, "SYMBOL %s", s);
    rule_add(r, s);
  }
}
コード例 #8
0
ファイル: test-dlopen.c プロジェクト: FengYang/libguestfs
int
main (int argc, char *argv[])
{
  void *lib;
  guestfs_create_t guestfs_create;
  guestfs_get_program_t guestfs_get_program;
  guestfs_close_t guestfs_close;
  guestfs_h *g;

  if (access (LIBRARY, X_OK) == -1) {
    fprintf (stderr, "test skipped because %s cannot be accessed: %m\n",
             LIBRARY);
    exit (77);
  }

  lib = dlopen (LIBRARY, RTLD_LAZY);
  if (lib == NULL) {
    fprintf (stderr, "could not open %s: %s\n", LIBRARY, dlerror ());
    exit (EXIT_FAILURE);
  }

  guestfs_create = read_symbol (lib, "guestfs_create");
  guestfs_get_program = read_symbol (lib, "guestfs_get_program");
  guestfs_close = read_symbol (lib, "guestfs_close");

  g = guestfs_create ();
  if (g == NULL) {
    fprintf (stderr, "failed to create handle\n");
    exit (EXIT_FAILURE);
  }
  printf ("program = %s\n", guestfs_get_program (g));

  guestfs_close (g);

  if (dlclose (lib) != 0) {
    fprintf (stderr, "could not close %s: %s\n", LIBRARY, dlerror ());
    exit (EXIT_FAILURE);
  }

  exit (EXIT_SUCCESS);
}
コード例 #9
0
ファイル: automata.c プロジェクト: mrLite/C-ohjelmointi
// Ex. 13
// Reads symbol_c number of lines from a file pointed by fptr and constructs the symbol table.
s_table_element* read_symbols(int symbol_c, FILE* fptr) {
	s_table_element* symbol_table;
	
	if((symbol_table = malloc(sizeof(s_table_element)*symbol_c)) == NULL) {
		puts("Couldn't allocate symbol table!");
		return NULL;
	}
		
	for(int i = 0; i < symbol_c; ++i) {
		symbol_table[i] = read_symbol(fptr);
	}
	return symbol_table;
}
コード例 #10
0
ファイル: glpmpl2.c プロジェクト: ChrisMoreton/Test3
void simple_format
(     MPL *mpl,
      SET *set,               /* not changed */
      MEMBER *memb,           /* modified */
      SLICE *slice            /* not changed */
)
{     TUPLE *tuple;
      SLICE *temp;
      SYMBOL *sym, *with = NULL;
      insist(set != NULL);
      insist(memb != NULL);
      insist(slice != NULL);
      insist(set->dimen == slice_dimen(mpl, slice));
      insist(memb->value.set->dim == set->dimen);
      if (slice_arity(mpl, slice) > 0) insist(is_symbol(mpl));
      /* read symbols and construct complete n-tuple */
      tuple = create_tuple(mpl);
      for (temp = slice; temp != NULL; temp = temp->next)
      {  if (temp->sym == NULL)
         {  /* substitution is needed; read symbol */
            if (!is_symbol(mpl))
            {  int lack = slice_arity(mpl, temp);
               /* with cannot be null due to assertion above */
               insist(with != NULL);
               if (lack == 1)
                  error(mpl, "one item missing in data group beginning "
                     "with %s", format_symbol(mpl, with));
               else
                  error(mpl, "%d items missing in data group beginning "
                     "with %s", lack, format_symbol(mpl, with));
            }
            sym = read_symbol(mpl);
            if (with == NULL) with = sym;
         }
         else
         {  /* copy symbol from the slice */
            sym = copy_symbol(mpl, temp->sym);
         }
         /* append the symbol to the n-tuple */
         tuple = expand_tuple(mpl, tuple, sym);
         /* skip optional comma *between* <symbols> */
         if (temp->next != NULL && mpl->token == T_COMMA)
            get_token(mpl /* , */);
      }
      /* add constructed n-tuple to elemental set */
      check_then_add(mpl, memb->value.set, tuple);
      return;
}
コード例 #11
0
ファイル: kallsyms.c プロジェクト: kinhoom/linux
static void read_map(FILE *in)
{
	while (!feof(in)) {
		if (table_cnt >= table_size) {
			table_size += 10000;
			table = realloc(table, sizeof(*table) * table_size);
			if (!table) {
				fprintf(stderr, "out of memory\n");
				exit (1);
			}
		}
		if (read_symbol(in, &table[table_cnt]) == 0) {
			table[table_cnt].start_pos = table_cnt;
			table_cnt++;
		}
	}
}
コード例 #12
0
ファイル: weather-owm.c プロジェクト: UIKit0/libgweather
static inline void
read_child_node (GWeatherInfo *info,
		 xmlNodePtr    node)
{
    if (strcmp ((char*) node->name, "symbol") == 0)
	read_symbol (info, node);
    else if (strcmp ((char*) node->name, "windDirection") == 0)
	read_wind_direction (info, node);
    else if (strcmp ((char*) node->name, "windSpeed") == 0)
	read_wind_speed (info, node);
    else if (strcmp ((char*) node->name, "temperature") == 0)
	read_temperature (info, node);
    else if (strcmp ((char*) node->name, "pressure") == 0)
	read_pressure (info, node);
    else if (strcmp ((char*) node->name, "humidity") == 0)
        read_humidity (info, node);
}
コード例 #13
0
ファイル: glpmpl2.c プロジェクト: ChrisMoreton/Test3
void plain_format
(     MPL *mpl,
      PARAMETER *par,         /* not changed */
      SLICE *slice            /* not changed */
)
{     TUPLE *tuple;
      SLICE *temp;
      SYMBOL *sym, *with = NULL;
      insist(par != NULL);
      insist(par->dim == slice_dimen(mpl, slice));
      insist(is_symbol(mpl));
      /* read symbols and construct complete subscript list */
      tuple = create_tuple(mpl);
      for (temp = slice; temp != NULL; temp = temp->next)
      {  if (temp->sym == NULL)
         {  /* substitution is needed; read symbol */
            if (!is_symbol(mpl))
            {  int lack = slice_arity(mpl, temp) + 1;
               insist(with != NULL);
               insist(lack > 1);
               error(mpl, "%d items missing in data group beginning wit"
                  "h %s", lack, format_symbol(mpl, with));
            }
            sym = read_symbol(mpl);
            if (with == NULL) with = sym;
         }
         else
         {  /* copy symbol from the slice */
            sym = copy_symbol(mpl, temp->sym);
         }
         /* append the symbol to the subscript list */
         tuple = expand_tuple(mpl, tuple, sym);
         /* skip optional comma */
         if (mpl->token == T_COMMA) get_token(mpl /* , */);
      }
      /* read value and assign it to new parameter member */
      if (!is_symbol(mpl))
      {  insist(with != NULL);
         error(mpl, "one item missing in data group beginning with %s",
            format_symbol(mpl, with));
      }
      read_value(mpl, par, tuple);
      return;
}
コード例 #14
0
ファイル: lisp.c プロジェクト: minopret/welisp
alloc_t *read(FILE *f) {
    alloc_t *x;
    char c;

    c = next_token_char(f);
    if (c == '\'') {
        x = read_quote(f);
    } else if (c == '(') {
        x = read_list(f);
    } else if (c == ')') {
        longjmp(fatal, ERROR_RIGHT_PAREN);
    } else if (c != EOF) {
        c = ungetc(c, f);
        if (c == EOF) {
            longjmp(fatal, ERROR_PUSHBACK);
        }
        x = read_symbol(f);
    }
    return x;
}
コード例 #15
0
ファイル: clj.c プロジェクト: wildthink/planck
static clj_Result read_form(clj_Reader *r) {
  clj_Result result;
  form_reader macro_reader;
  wint_t c;
  while (WEOF != (c = pop_char(r))) {
    if (is_clj_whitespace(c)) {
      continue;
    } else if ((macro_reader = get_macro_reader(c))) {
      return macro_reader(r, c);
    } else if (at_number(r, c)) {
      return read_number(r, c);
    } else {
      return read_symbol(r, c);
    }
  }
  if (r->depth > 0) {
    reader_error(r, CLJ_UNEXPECTED_EOF);
  }
  return CLJ_EOF;
};
コード例 #16
0
ファイル: read.c プロジェクト: troter/thesis
/* <simple datum> -> <boolean> | <number> | <character> | <string> | <symbol>
 */
static SCM read_simple_datum(FILE *file, int previous)
{
    int c;
    c = previous == 0 ? skip_comment_and_space(file) : previous;

    if (SCM_INITIAL_CHARACTERS_P(c)) { /* <symbol> */
        return read_symbol(file, c);
    }
    if (isdigit(c)) { /* <number> */
        return read_number(file, c);
    }
    if (SCM_PECULIAR_IDENTIFIER_P(c)) { /* <number> or <symbol> */
        return read_number_or_peculiar(file, c);
    }

    switch (c) {
    case EOF:
        return SCM_EOF;
    case '#': /* <boolean> or <character> or <number prefix> */
        c = fgetc(file);
        switch (c) {
        case EOF:
            scheme_error("syntax error");
            /* <boolean> */
        case 't':    return SCM_TRUE;
        case 'f':    return SCM_FALSE;

            /* <character> */
        case '\\':
            return read_character(file);

            /* <number prefix> */
        default:
            scheme_error("unsupport number prefix");
        }
    case '"': /* <string> */
        return read_string(file);
    default:
        scheme_error("unsupport character");
    }
}
コード例 #17
0
ファイル: minilisp.c プロジェクト: yanoh/minilisp
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);
    }
}
コード例 #18
0
ファイル: symtab.c プロジェクト: waltervn/scis
int
add_symbol(struct symtab_struct *symtab, char *symbol, int value, char *file, int line, int type)
{
	symtab_entry_t *e;

	if (!symtab->dup)
		if (!read_symbol(symtab, symbol, NULL, NULL, NULL, NULL))
			return 1; /* Already defined */

	if (symtab->entries_used + 1 == symtab->table_size) {
		symtab->table_size <<= 1;
		symtab->table = realloc(symtab->table,
					sizeof(symtab_entry_t) * symtab->table_size);
	}

	e = (symtab->table) + (symtab->entries_used)++;

	e->name = xstrdup(symbol);
	e->file = file;
	e->line = line;
	e->value = value;
	e->type = type;
	return 0;
}
コード例 #19
0
ファイル: t_vobj.c プロジェクト: deplinenoise/vlink
static void vobj_read(struct GlobalVars *gv,struct LinkFile *lf,uint8_t *data)
{
  struct ObjectUnit *u;
  int bpb,bpt,nsecs,nsyms,i;
  struct vobj_symbol *vsymbols = NULL;

  if (lf->type == ID_LIBARCH) {  /* check ar-member for correct format */
    vobj_check_ar_type(fff[lf->format],lf->pathname,data);
  }
  p = data + 5;  /* skip ID and endianess */
  bpb = (int)read_number();  /* bits per byte */
  if (bpb != 8) {
    /* bits per byte are not supported */
    error(113,lf->pathname,fff[lf->format]->tname,bpb);
  }
  bpt = (int)read_number();  /* bytes per taddr */
  if (bpt > sizeof(taddr)) {
    /* n bytes per target-address are not supported */
    error(114,lf->pathname,fff[lf->format]->tname,bpt);
  }
  skip_string();  /* skip cpu-string */

  u = create_objunit(gv,lf,lf->objname);
  nsecs = (int)read_number();  /* number of sections */
  nsyms = (int)read_number();  /* number of symbols */

  if (nsyms) {
    vsymbols = alloc(nsyms * sizeof(struct vobj_symbol));
    for (i=0; i<nsyms; i++)
      read_symbol(&vsymbols[i]);
  }

  for (i=1; i<=nsecs; i++)
    read_section(gv,u,(uint32_t)i,vsymbols,nsyms);

  /* add relocatable and absolute symbols, ignore unknown symbol-refs */
  for (i=0; i<nsyms; i++) {
    struct vobj_symbol *vs = &vsymbols[i];
    struct Section *s = NULL;
    uint8_t type,bind,info;

    if (vs->flags & WEAK)
      bind = SYMB_WEAK;
    else if (vs->flags & EXPORT)
      bind = SYMB_GLOBAL;
    else
      bind = SYMB_LOCAL;

    if (vs->flags & COMMON) {
      type = SYM_COMMON;
      s = common_section(gv,u);
    }
    else if (vs->type == EXPRESSION) {
      type = SYM_ABS;
      s = abs_section(u);
    }
    else if (vs->type == LABSYM) {
      type = SYM_RELOC;
      if (!(s = find_sect_id(u,vs->sec))) {
        /* a section with this index doesn't exist! */
        error(53,lf->pathname,vs->name,lf->objname,vs->sec);
      }
    }
    else if (vs->type == IMPORT) {
      type = 0;  /* ignore unknown symbols */
    }
    else {
      /* illegal symbol type */
      error(116,getobjname(u),fff[lf->format]->tname,
            vs->type,vs->name,lf->objname);
      type = 0;
    }

    switch (TYPE(vs)) {
      case TYPE_UNKNOWN: info = SYMI_NOTYPE; break;
      case TYPE_OBJECT: info = SYMI_OBJECT; break;
      case TYPE_FUNCTION: info = SYMI_FUNC; break;
      case TYPE_SECTION: type = 0; break;  /* ignore SECTION symbols */
      case TYPE_FILE: info = SYMI_FILE; break;
      default:
        error(54,lf->pathname,TYPE(vs),vs->name,lf->objname);
        type = 0;
        break;
    }

    if (type) {
      if (bind == SYMB_LOCAL)
        addlocsymbol(gv,s,vs->name,NULL,(lword)vs->val,type,0,info,vs->size);
      else
        addsymbol(gv,s,vs->name,NULL,(lword)vs->val,
                  type,0,info,bind,vs->size,TRUE);
    }
  }
  if (nsyms)
    free(vsymbols);

  add_objunit(gv,u,TRUE);  /* add object unit and fix relocations */
}
コード例 #20
0
ファイル: lex.c プロジェクト: mushrom/nscheme
scm_value_t read_next_token( parse_state_t *state ){
	scm_value_t ret = 0;
	int c;
	
	for (;;) {
		c = fgetc( state->fp );

		if ( feof( state->fp )){
			return tag_parse_val( PARSE_TYPE_EOF );

		} else if ( c == '\n' ){
			state->linenum++;
			state->charpos = 0;

		} else if ( c == ';' ){
			while ( c != '\n' && !feof( state->fp )){
				c = fgetc( state->fp );
			}

			ungetc( c, state->fp );

		} else if ( c == '(' ){
			return tag_parse_val( PARSE_TYPE_LEFT_PAREN );

		} else if ( c == ')' ){
			return tag_parse_val( PARSE_TYPE_RIGHT_PAREN );

		} else if ( c == '.' ){
			return tag_parse_val( PARSE_TYPE_PERIOD );

		} else if ( c == '\'' ){
			return tag_parse_val( PARSE_TYPE_APOSTROPHE );

		} else if ( matches( c, WHITESPACE )){
			state->charpos++;

		} else if ( matches( c, DIGITS )){
			ungetc( c, state->fp );
			return read_number( state );

		} else if ( matches( c, ALPHABET SYMBOLS)){
			ungetc( c, state->fp );
			return read_symbol( state );

		} else if ( c == '#' ){
			int next = fgetc( state->fp );

			if ( next == 't' || next == 'f' ){
				return tag_boolean( next == 't' );

			} else if ( next == '\\' ){
				next = fgetc( state->fp );
				return tag_character( next );

			} else {
				ungetc( c, state->fp );
				return tag_parse_val( PARSE_TYPE_OCTOTHORPE );
			}

		} else {
			puts( "error!" );
			// TODO: error out here
		}
	}

	return ret;
}
コード例 #21
0
ファイル: scanner.cpp プロジェクト: AleksandarZeljic/z3
scanner::token scanner::read_id(char first_char) {
    char ch;
    m_string.reset();
    m_params.reset();
    m_string.push_back(first_char);

    bool is_arith = (m_normalized[(unsigned char) first_char] == '+');
    bool is_alpha = (m_normalized[(unsigned char) first_char] == 'a');
    
    ch = read_char();        
    // In SMT2 "-20" is an identifier.
    if (!m_smt2 && state_ok() && first_char == '-' && m_normalized[(unsigned char) ch] == '0') {
        return read_number(ch, false);
    }

    if (state_ok() && first_char == '|') {
        return read_symbol(ch);
    }
    
    while (state_ok()) {                        
        switch(m_normalized[(unsigned char) ch]) {
        case '+':
            if (is_arith) {
                m_string.push_back(ch);
                break;
            }
            // strings can have hyphens.
            if (!is_alpha || ch != '-') {
                goto bail_out;  
            }
        case 'a':
        case ':':
        case '.':
        case '0':
            if (is_arith) {
                goto bail_out;
            }
            m_string.push_back(ch);
            break;
        case '[':                
            m_string.push_back(0);
            m_id = m_string.begin();
            if (read_params()) {
                return ID_TOKEN;
            }
            else {
                return m_state;
            }
        default:
            goto bail_out;
        }
        ch = read_char();
    }
    return m_state;

 bail_out:
    m_string.push_back(0);
    m_id = m_string.begin();
    unread_char();
    return ID_TOKEN;
}
コード例 #22
0
ファイル: glpmpl2.c プロジェクト: ChrisMoreton/Test3
void tabular_format
(     MPL *mpl,
      PARAMETER *par,         /* not changed */
      SLICE *slice,           /* not changed */
      int tr
)
{     SLICE *list, *col, *temp;
      TUPLE *tuple;
      SYMBOL *row;
      insist(par != NULL);
      insist(par->dim == slice_dimen(mpl, slice));
      insist(slice_arity(mpl, slice) == 2);
      /* read the table heading that contains column symbols (the table
         may have no columns) */
      list = create_slice(mpl);
      while (mpl->token != T_ASSIGN)
      {  /* read column symbol and append it to the column list */
         if (!is_symbol(mpl))
            error(mpl, "number, symbol, or := missing where expected");
         list = expand_slice(mpl, list, read_symbol(mpl));
      }
      get_token(mpl /* := */);
      /* read zero or more rows that contain tabular data */
      while (is_symbol(mpl))
      {  /* read row symbol (if the table has no columns, these symbols
            are just ignored) */
         row = read_symbol(mpl);
         /* read values accordingly to the column list */
         for (col = list; col != NULL; col = col->next)
         {  int which = 0;
            /* if the token is single point, no value is provided */
            if (is_literal(mpl, "."))
            {  get_token(mpl /* . */);
               continue;
            }
            /* construct complete subscript list */
            tuple = create_tuple(mpl);
            for (temp = slice; temp != NULL; temp = temp->next)
            {  if (temp->sym == NULL)
               {  /* substitution is needed */
                  switch (++which)
                  {  case 1:
                        /* substitute in the first null position */
                        tuple = expand_tuple(mpl, tuple,
                           copy_symbol(mpl, tr ? col->sym : row));
                        break;
                     case 2:
                        /* substitute in the second null position */
                        tuple = expand_tuple(mpl, tuple,
                           copy_symbol(mpl, tr ? row : col->sym));
                        break;
                     default:
                        insist(which != which);
                  }
               }
               else
               {  /* copy symbol from the slice */
                  tuple = expand_tuple(mpl, tuple, copy_symbol(mpl,
                     temp->sym));
               }
            }
            insist(which == 2);
            /* read value and assign it to new parameter member */
            if (!is_symbol(mpl))
            {  int lack = slice_dimen(mpl, col);
               if (lack == 1)
                  error(mpl, "one item missing in data group beginning "
                     "with %s", format_symbol(mpl, row));
               else
                  error(mpl, "%d items missing in data group beginning "
                     "with %s", lack, format_symbol(mpl, row));
            }
            read_value(mpl, par, tuple);
         }
         /* delete the row symbol */
         delete_symbol(mpl, row);
      }
      /* delete the column list */
      delete_slice(mpl, list);
      return;
}
コード例 #23
0
ファイル: glpmpl2.c プロジェクト: ChrisMoreton/Test3
void tabbing_format
(     MPL *mpl,
      SYMBOL *altval          /* not changed */
)
{     SET *set = NULL;
      PARAMETER *par;
      SLICE *list, *col;
      TUPLE *tuple;
      int next_token, j, dim = 0;
      char *last_name = NULL;
      /* read the optional <prefix> */
      if (is_symbol(mpl))
      {  get_token(mpl /* <symbol> */);
         next_token = mpl->token;
         unget_token(mpl /* <symbol> */);
         if (next_token == T_COLON)
         {  /* select the set to saturate it with data */
            set = select_set(mpl, mpl->image);
            /* the set must be simple (i.e. not set of sets) */
            if (set->dim != 0)
               error(mpl, "%s must be a simple set", set->name);
            /* and must not be defined yet */
            if (set->array->head != NULL)
               error(mpl, "%s already defined", set->name);
            /* add new (the only) member to the set and assign it empty
               elemental set */
            add_member(mpl, set->array, NULL)->value.set =
               create_elemset(mpl, set->dimen);
            last_name = set->name, dim = set->dimen;
            get_token(mpl /* <symbol> */);
            insist(mpl->token == T_COLON);
            get_token(mpl /* : */);
         }
      }
      /* read the table heading that contains parameter names */
      list = create_slice(mpl);
      while (mpl->token != T_ASSIGN)
      {  /* there must be symbolic name of parameter */
         if (!is_symbol(mpl))
            error(mpl, "parameter name or := missing where expected");
         /* select the parameter to saturate it with data */
         par = select_parameter(mpl, mpl->image);
         /* the parameter must be subscripted */
         if (par->dim == 0)
            error(mpl, "%s not a subscripted parameter", mpl->image);
         /* the set (if specified) and all the parameters in the data
            block must have identical dimension */
         if (dim != 0 && par->dim != dim)
         {  insist(last_name != NULL);
            error(mpl, "%s has dimension %d while %s has dimension %d",
               last_name, dim, par->name, par->dim);
         }
         /* set default value for the parameter (if specified) */
         if (altval != NULL)
            set_default(mpl, par, copy_symbol(mpl, altval));
         /* append the parameter to the column list */
         list = expand_slice(mpl, list, (SYMBOL *)par);
         last_name = par->name, dim = par->dim;
         get_token(mpl /* <symbol> */);
         /* skip optional comma */
         if (mpl->token == T_COMMA) get_token(mpl /* , */);
      }
      if (slice_dimen(mpl, list) == 0)
         error(mpl, "at least one parameter name required");
      get_token(mpl /* := */);
      /* skip optional comma */
      if (mpl->token == T_COMMA) get_token(mpl /* , */);
      /* read rows that contain tabbing data */
      while (is_symbol(mpl))
      {  /* read subscript list */
         tuple = create_tuple(mpl);
         for (j = 1; j <= dim; j++)
         {  /* read j-th subscript */
            if (!is_symbol(mpl))
            {  int lack = slice_dimen(mpl, list) + dim - j + 1;
               insist(tuple != NULL);
               insist(lack > 1);
               error(mpl, "%d items missing in data group beginning wit"
                  "h %s", lack, format_symbol(mpl, tuple->sym));
            }
            /* read and append j-th subscript to the n-tuple */
            tuple = expand_tuple(mpl, tuple, read_symbol(mpl));
            /* skip optional comma *between* <symbols> */
            if (j < dim && mpl->token == T_COMMA)
               get_token(mpl /* , */);
         }
         /* if the set is specified, add to it new n-tuple, which is a
            copy of the subscript list just read */
         if (set != NULL)
            check_then_add(mpl, set->array->head->value.set,
               copy_tuple(mpl, tuple));
         /* skip optional comma between <symbol> and <value> */
         if (mpl->token == T_COMMA) get_token(mpl /* , */);
         /* read values accordingly to the column list */
         for (col = list; col != NULL; col = col->next)
         {  /* if the token is single point, no value is provided */
            if (is_literal(mpl, "."))
            {  get_token(mpl /* . */);
               continue;
            }
            /* read value and assign it to new parameter member */
            if (!is_symbol(mpl))
            {  int lack = slice_dimen(mpl, col);
               insist(tuple != NULL);
               if (lack == 1)
                  error(mpl, "one item missing in data group beginning "
                     "with %s", format_symbol(mpl, tuple->sym));
               else
                  error(mpl, "%d items missing in data group beginning "
                     "with %s", lack, format_symbol(mpl, tuple->sym));
            }
            read_value(mpl, (PARAMETER *)col->sym, copy_tuple(mpl,
               tuple));
            /* skip optional comma preceding the next value */
            if (col->next != NULL && mpl->token == T_COMMA)
               get_token(mpl /* , */);
         }
         /* delete the original subscript list */
         delete_tuple(mpl, tuple);
         /* skip optional comma (only if there is next data group) */
         if (mpl->token == T_COMMA)
         {  get_token(mpl /* , */);
            if (!is_symbol(mpl)) unget_token(mpl /* , */);
         }
      }
      /* delete the column list (it contains parameters, not symbols,
         so nullify it before) */
      for (col = list; col != NULL; col = col->next) col->sym = NULL;
      delete_slice(mpl, list);
      return;
}
コード例 #24
0
/*
 * Read next token and return its type tk
 * - set lex->token to tk
 * - set lex->tk_pos, etc.
 * - if token is TK_STRING, TK_NUM_RATIONAL, TK_NUM_FLOAT, TK_BV_CONSTANT, TK_SYMBOL, TK_ERROR,
 *   the token value is stored in lex->buffer (as a string).
 */
yices_token_t next_yices_token(lexer_t *lex) {
  yices_token_t tk;
  reader_t *rd;
  string_buffer_t *buffer;
  int c;

  rd = &lex->reader;
  c = reader_current_char(rd);
  buffer = lex->buffer;
  string_buffer_reset(buffer);

  // skip spaces and comments
  for (;;) {
    while (isspace(c)) c = reader_next_char(rd);
    if (c != ';') break;
    do { // read to end-of-line or eof
      c = reader_next_char(rd);
    } while (c != '\n' && c != EOF);
  }

  // record token position (start of token)
  lex->tk_pos = rd->pos;
  lex->tk_line = rd->line;
  lex->tk_column = rd->column;

  switch (c) {
  case '(':
    tk = TK_LP;
    goto next_then_return;
  case ')':
    tk = TK_RP;
    goto next_then_return;
  case EOF:
    tk = TK_EOS;
    goto done;
  case ':':
    c = reader_next_char(rd);
    if (c == ':') {
      tk = TK_COLON_COLON;
      goto next_then_return;
    } else {
      // store ':' in the buffer since that may be used for reporting errors
      string_buffer_append_char(buffer, ':');
      string_buffer_close(buffer);
      tk = TK_ERROR;
      goto done;
    }
  case '"':
    tk = read_string(lex);
    goto done;
  case '+':
  case '-':
    string_buffer_append_char(buffer, c);
    c = reader_next_char(rd);
    if (isdigit(c)) {
      string_buffer_append_char(buffer, c);
      reader_next_char(rd);
      tk = read_number(lex);
    } else {
      tk = read_symbol(lex);
    }
    goto done;

  case '0':
    string_buffer_append_char(buffer, c);
    c = reader_next_char(rd);
    if (c == 'b') {
      tk = read_bv_constant(lex);
    } else if (c == 'x') {
      tk = read_hex_constant(lex);
    } else {
      tk = read_number(lex);
    }
    goto done;

  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
    string_buffer_append_char(buffer, c);
    reader_next_char(rd);
    tk = read_number(lex);
    goto done;

  default: // symbol or keyword
    string_buffer_append_char(buffer, c);
    reader_next_char(rd);
    tk = read_symbol(lex);
    goto done;
  }

  /*
   * read next character and exit
   */
 next_then_return:
  reader_next_char(rd);


 done:
  lex->token = tk;
  return tk;
}
コード例 #25
0
ファイル: glpmpl2.c プロジェクト: ChrisMoreton/Test3
void parameter_data(MPL *mpl)
{     PARAMETER *par;
      SYMBOL *altval = NULL;
      SLICE *slice;
      int tr = 0;
      insist(is_literal(mpl, "param"));
      get_token(mpl /* param */);
      /* read optional default value */
      if (is_literal(mpl, "default"))
      {  get_token(mpl /* default */);
         if (!is_symbol(mpl))
            error(mpl, "default value missing where expected");
         altval = read_symbol(mpl);
         /* if the default value follows the keyword 'param', the next
            token must be only the colon */
         if (mpl->token != T_COLON)
            error(mpl, "colon missing where expected");
      }
      /* being used after the keyword 'param' or the optional default
         value the colon begins data in the tabbing format */
      if (mpl->token == T_COLON)
      {  get_token(mpl /* : */);
         /* skip optional comma */
         if (mpl->token == T_COMMA) get_token(mpl /* , */);
         /* read parameter data in the tabbing format */
         tabbing_format(mpl, altval);
         /* on reading data in the tabbing format the default value is
            always copied, so delete the original symbol */
         if (altval != NULL) delete_symbol(mpl, altval);
         /* the next token must be only semicolon */
         if (mpl->token != T_SEMICOLON)
            error(mpl, "symbol, number, or semicolon missing where expe"
               "cted");
         get_token(mpl /* ; */);
         goto done;
      }
      /* in other cases there must be symbolic name of parameter, which
         follows the keyword 'param' */
      if (!is_symbol(mpl))
         error(mpl, "parameter name missing where expected");
      /* select the parameter to saturate it with data */
      par = select_parameter(mpl, mpl->image);
      get_token(mpl /* <symbol> */);
      /* read optional default value */
      if (is_literal(mpl, "default"))
      {  get_token(mpl /* default */);
         if (!is_symbol(mpl))
            error(mpl, "default value missing where expected");
         altval = read_symbol(mpl);
         /* set default value for the parameter */
         set_default(mpl, par, altval);
      }
      /* create initial fake slice of all asterisks */
      slice = fake_slice(mpl, par->dim);
      /* read zero or more data assignments */
      for (;;)
      {  /* skip optional comma */
         if (mpl->token == T_COMMA) get_token(mpl /* , */);
         /* process current assignment */
         if (mpl->token == T_ASSIGN)
         {  /* assignment ligature is non-significant element */
            get_token(mpl /* := */);
         }
         else if (mpl->token == T_LBRACKET)
         {  /* left bracket begins new slice; delete the current slice
               and read new one */
            delete_slice(mpl, slice);
            slice = read_slice(mpl, par->name, par->dim);
            /* each new slice resets the "transpose" indicator */
            tr = 0;
         }
         else if (is_symbol(mpl))
         {  /* number or symbol begins data in the plain format */
            plain_format(mpl, par, slice);
         }
         else if (mpl->token == T_COLON)
         {  /* colon begins data in the tabular format */
            if (par->dim == 0)
err1:          error(mpl, "%s not a subscripted parameter",
                  par->name);
            if (slice_arity(mpl, slice) != 2)
err2:          error(mpl, "slice currently used must specify 2 asterisk"
                  "s, not %d", slice_arity(mpl, slice));
            get_token(mpl /* : */);
            /* read parameter data in the tabular format */
            tabular_format(mpl, par, slice, tr);
         }
         else if (mpl->token == T_LEFT)
         {  /* left parenthesis begins the "transpose" indicator, which
               is followed by data in the tabular format */
            get_token(mpl /* ( */);
            if (!is_literal(mpl, "tr"))
err3:          error(mpl, "transpose indicator (tr) incomplete");
            if (par->dim == 0) goto err1;
            if (slice_arity(mpl, slice) != 2) goto err2;
            get_token(mpl /* tr */);
            if (mpl->token != T_RIGHT) goto err3;
            get_token(mpl /* ) */);
            /* in this case the colon is optional */
            if (mpl->token == T_COLON) get_token(mpl /* : */);
            /* set the "transpose" indicator */
            tr = 1;
            /* read parameter data in the tabular format */
            tabular_format(mpl, par, slice, tr);
         }
         else if (mpl->token == T_SEMICOLON)
         {  /* semicolon terminates the data block */
            get_token(mpl /* ; */);
            break;
         }
         else
            error(mpl, "syntax error in parameter data block");
      }
      /* delete the current slice */
      delete_slice(mpl, slice);
done: return;
}
コード例 #26
0
ファイル: glpmpl2.c プロジェクト: ChrisMoreton/Test3
void set_data(MPL *mpl)
{     SET *set;
      TUPLE *tuple;
      MEMBER *memb;
      SLICE *slice;
      int tr = 0;
      insist(is_literal(mpl, "set"));
      get_token(mpl /* set */);
      /* symbolic name of set must follows the keyword 'set' */
      if (!is_symbol(mpl))
         error(mpl, "set name missing where expected");
      /* select the set to saturate it with data */
      set = select_set(mpl, mpl->image);
      get_token(mpl /* <symbolic name> */);
      /* read optional subscript list, which identifies member of the
         set to be read */
      tuple = create_tuple(mpl);
      if (mpl->token == T_LBRACKET)
      {  /* subscript list is specified */
         if (set->dim == 0)
            error(mpl, "%s cannot be subscripted", set->name);
         get_token(mpl /* [ */);
         /* read symbols and construct subscript list */
         for (;;)
         {  if (!is_symbol(mpl))
               error(mpl, "number or symbol missing where expected");
            tuple = expand_tuple(mpl, tuple, read_symbol(mpl));
            if (mpl->token == T_COMMA)
               get_token(mpl /* , */);
            else if (mpl->token == T_RBRACKET)
               break;
            else
               error(mpl, "syntax error in subscript list");
         }
         if (set->dim != tuple_dimen(mpl, tuple))
            error(mpl, "%s must have %d subscript%s rather than %d",
               set->name, set->dim, set->dim == 1 ? "" : "s",
               tuple_dimen(mpl, tuple));
         get_token(mpl /* ] */);
      }
      else
      {  /* subscript list is not specified */
         if (set->dim != 0)
            error(mpl, "%s must be subscripted", set->name);
      }
      /* there must be no member with the same subscript list */
      if (find_member(mpl, set->array, tuple) != NULL)
         error(mpl, "%s%s already defined",
            set->name, format_tuple(mpl, '[', tuple));
      /* add new member to the set and assign it empty elemental set */
      memb = add_member(mpl, set->array, tuple);
      memb->value.set = create_elemset(mpl, set->dimen);
      /* create an initial fake slice of all asterisks */
      slice = fake_slice(mpl, set->dimen);
      /* read zero or more data assignments */
      for (;;)
      {  /* skip optional comma */
         if (mpl->token == T_COMMA) get_token(mpl /* , */);
         /* process assignment element */
         if (mpl->token == T_ASSIGN)
         {  /* assignment ligature is non-significant element */
            get_token(mpl /* := */);
         }
         else if (mpl->token == T_LEFT)
         {  /* left parenthesis begins either new slice or "transpose"
               indicator */
            int is_tr;
            get_token(mpl /* ( */);
            is_tr = is_literal(mpl, "tr");
            unget_token(mpl /* ( */);
            if (is_tr) goto left;
            /* delete the current slice and read new one */
            delete_slice(mpl, slice);
            slice = read_slice(mpl, set->name, set->dimen);
            /* each new slice resets the "transpose" indicator */
            tr = 0;
            /* if the new slice is 0-ary, formally there is one 0-tuple
               (in the simple format) that follows it */
            if (slice_arity(mpl, slice) == 0)
               simple_format(mpl, set, memb, slice);
         }
         else if (is_symbol(mpl))
         {  /* number or symbol begins data in the simple format */
            simple_format(mpl, set, memb, slice);
         }
         else if (mpl->token == T_COLON)
         {  /* colon begins data in the matrix format */
            if (slice_arity(mpl, slice) != 2)
err1:          error(mpl, "slice currently used must specify 2 asterisk"
                  "s, not %d", slice_arity(mpl, slice));
            get_token(mpl /* : */);
            /* read elemental set data in the matrix format */
            matrix_format(mpl, set, memb, slice, tr);
         }
         else if (mpl->token == T_LEFT)
left:    {  /* left parenthesis begins the "transpose" indicator, which
               is followed by data in the matrix format */
            get_token(mpl /* ( */);
            if (!is_literal(mpl, "tr"))
err2:          error(mpl, "transpose indicator (tr) incomplete");
            if (slice_arity(mpl, slice) != 2) goto err1;
            get_token(mpl /* tr */);
            if (mpl->token != T_RIGHT) goto err2;
            get_token(mpl /* ) */);
            /* in this case the colon is optional */
            if (mpl->token == T_COLON) get_token(mpl /* : */);
            /* set the "transpose" indicator */
            tr = 1;
            /* read elemental set data in the matrix format */
            matrix_format(mpl, set, memb, slice, tr);
         }
         else if (mpl->token == T_SEMICOLON)
         {  /* semicolon terminates the data block */
            get_token(mpl /* ; */);
            break;
         }
         else
            error(mpl, "syntax error in set data block");
      }
      /* delete the current slice */
      delete_slice(mpl, slice);
      return;
}
コード例 #27
0
ファイル: read.c プロジェクト: lukesandberg/bootstrap-scheme
scheme_object* read(vm* context, FILE* in)
{
	int c;
	eat_whitespace(in);
	c = getc(in);
	
	if(isdigit(c) || (c == '-' && (isdigit(peek(in)))))
	{
		short sign = 1;//positive
		long num = 0;
		//read a number
		if(c == '-')
		{
			sign = -1;
		}
		else
		{
			ungetc(c, in);
		}
		while(isdigit(c = getc(in)))
		{
			num = num *10 + (c -'0');
		}
		num *= sign;
		if(is_delimiter(c))
		{
			ungetc(c, in);
			return make_number(context, num);
		}
		
		//its not followed by a delimiter
		fprintf(stderr, "Number not followed by a delimiter!\n");
		exit(1);
	}
	else if(c == '#')
	{//character or boolean
		c = getc(in);

		switch(c)
		{
			case 't':
				return (scheme_object*) true;
			case 'f':
				return (scheme_object*) false;
			case '\\':
				return read_character(context, in);
			default:
				fprintf(stderr, "unknown boolean or character literal\n");
				exit(1);
		}
	}
	else if(c =='"')
	{
		return read_string(context, in);
	}
	else if(c == '(')
	{
		return read_pair(context, in);
	}
	else if(is_initial(c) || ((c == '+' || c == '-') && is_delimiter(peek(in))))
	{
		ungetc(c, in);
		return read_symbol(context, in);
	}
	else if(c == '\'')
	{
		return cons(context, (scheme_object*) quote_symbol, cons(context, read(context, in), the_empty_list));
	}
	else if(c == EOF)
	{
		return NULL;
	}
	else
	{
		fprintf(stderr, "Unexpected input: '%c'\n", c);
		exit(1);
	}
	fprintf(stderr, "read: illegal state\n");
	exit(1);
}
コード例 #28
0
ファイル: vobjdump.c プロジェクト: kusma/vasm
static int vobjdump(void)
{
  p = vobj;

  if (vlen>4 && p[0]==0x56 && p[1]==0x4f && p[2]==0x42 && p[3]==0x4a) {
    int endian,nsecs,nsyms,i;
    const char *cpu_name;
    struct vobj_symbol *vsymbols = NULL;
    struct vobj_section *vsect = NULL;

    p += 4;	/* skip ID */
    endian = (int)*p++;  /* endianess */
    if (endian<1 || endian>2) {
      fprintf(stderr,"Wrong endianess: %d\n",endian);
      return 1;
    }

    bpb = (int)read_number(0);  /* bits per byte */
    if (bpb != 8) {
      fprintf(stderr,"%d bits per byte not supported!\n",bpb);
      return 1;
    }

    bpt = (int)read_number(0);  /* bytes per taddr */
    if (bpt > sizeof(taddr)) {
      fprintf(stderr,"%d bytes per taddr not supported!\n",bpt);
      return 1;
    }
    bptmask = makemask(bpt*bpb);

    cpu_name = p;
    skip_string();  /* skip cpu-string */
    nsecs = (int)read_number(0);  /* number of sections */
    nsyms = (int)read_number(0);  /* number of symbols */

    /* print header */
    print_sep();
    printf("VOBJ %s (%s endian), %d bits per byte, %d bytes per word.\n"
           "%d symbol%s.\n%d section%s.\n",
           cpu_name,endian_name[endian-1],bpb,bpt,
           nsyms,nsyms==1?emptystr:sstr,nsecs,nsecs==1?emptystr:sstr);

    /* read symbols */
    if (nsyms) {
      if (vsymbols = malloc(nsyms * sizeof(struct vobj_symbol))) {
        for (i=0; i<nsyms; i++)
          read_symbol(&vsymbols[i]);
      }
      else {
        fprintf(stderr,"Cannot allocate %ld bytes for symbols!\n",
                (long)(nsyms * sizeof(struct vobj_symbol)));
        return 1;
      }
    }

    /* read and print sections */
    if (vsect = malloc(nsecs * sizeof(struct vobj_section))) {
      for (i=0; i<nsecs; i++)
        read_section(&vsect[i],vsymbols,nsyms);
    }
    else {
      fprintf(stderr,"Cannot allocate %ld bytes for sections!\n",
              (long)(nsecs * sizeof(struct vobj_section)));
      return 1;
    }

    /* print symbols */
    for (i=0; i<nsyms; i++) {
      struct vobj_symbol *vs = &vsymbols[i];

      if (i == 0) {
        printf("\n");
        print_sep();
        printf("SYMBOL TABLE\n"
               "file offs bind size     type def      value    name\n");
      }
      if (!strncmp(vs->name," *current pc",12))
        continue;
      printf("%08llx: %-4s %08x %-4s %8.8s %8llx %s\n",
             BPTMASK(vs->offs),bind_name(vs->flags),(unsigned)vs->size,
             type_name[TYPE(vs)],def_name(vs,vsect,nsecs),
             BPTMASK(vs->val),vs->name);
    }
  }
  else {
    fprintf(stderr,"Not a VOBJ file!\n");
    return 1;
  }

  return 0;
}
コード例 #29
0
ファイル: glpmpl2.c プロジェクト: ChrisMoreton/Test3
SLICE *read_slice
(     MPL *mpl,
      char *name,             /* not changed */
      int dim
)
{     SLICE *slice;
      int close;
      insist(name != NULL);
      switch (mpl->token)
      {  case T_LBRACKET:
            close = T_RBRACKET;
            break;
         case T_LEFT:
            insist(dim > 0);
            close = T_RIGHT;
            break;
         default:
            insist(mpl != mpl);
      }
      if (dim == 0)
         error(mpl, "%s cannot be subscripted", name);
      get_token(mpl /* ( | [ */);
      /* read slice components */
      slice = create_slice(mpl);
      for (;;)
      {  /* the current token must be a symbol or asterisk */
         if (is_symbol(mpl))
            slice = expand_slice(mpl, slice, read_symbol(mpl));
         else if (mpl->token == T_ASTERISK)
         {  slice = expand_slice(mpl, slice, NULL);
            get_token(mpl /* * */);
         }
         else
            error(mpl, "number, symbol, or asterisk missing where expec"
               "ted");
         /* check a token that follows the symbol */
         if (mpl->token == T_COMMA)
            get_token(mpl /* , */);
         else if (mpl->token == close)
            break;
         else
            error(mpl, "syntax error in slice");
      }
      /* number of slice components must be the same as the appropriate
         dimension */
      if (slice_dimen(mpl, slice) != dim)
      {  switch (close)
         {  case T_RBRACKET:
               error(mpl, "%s must have %d subscript%s, not %d", name,
                  dim, dim == 1 ? "" : "s", slice_dimen(mpl, slice));
               break;
            case T_RIGHT:
               error(mpl, "%s has dimension %d, not %d", name, dim,
                  slice_dimen(mpl, slice));
               break;
            default:
               insist(close != close);
         }
      }
      get_token(mpl /* ) | ] */);
      return slice;
}
コード例 #30
0
ファイル: glpmpl2.c プロジェクト: ChrisMoreton/Test3
void matrix_format
(     MPL *mpl,
      SET *set,               /* not changed */
      MEMBER *memb,           /* modified */
      SLICE *slice,           /* not changed */
      int tr
)
{     SLICE *list, *col, *temp;
      TUPLE *tuple;
      SYMBOL *row;
      insist(set != NULL);
      insist(memb != NULL);
      insist(slice != NULL);
      insist(set->dimen == slice_dimen(mpl, slice));
      insist(memb->value.set->dim == set->dimen);
      insist(slice_arity(mpl, slice) == 2);
      /* read the matrix heading that contains column symbols (there
         may be no columns at all) */
      list = create_slice(mpl);
      while (mpl->token != T_ASSIGN)
      {  /* read column symbol and append it to the column list */
         if (!is_symbol(mpl))
            error(mpl, "number, symbol, or := missing where expected");
         list = expand_slice(mpl, list, read_symbol(mpl));
      }
      get_token(mpl /* := */);
      /* read zero or more rows that contain matrix data */
      while (is_symbol(mpl))
      {  /* read row symbol (if the matrix has no columns, row symbols
            are just ignored) */
         row = read_symbol(mpl);
         /* read the matrix row accordingly to the column list */
         for (col = list; col != NULL; col = col->next)
         {  int which = 0;
            /* check indicator */
            if (is_literal(mpl, "+"))
               ;
            else if (is_literal(mpl, "-"))
            {  get_token(mpl /* - */);
               continue;
            }
            else
            {  int lack = slice_dimen(mpl, col);
               if (lack == 1)
                  error(mpl, "one item missing in data group beginning "
                     "with %s", format_symbol(mpl, row));
               else
                  error(mpl, "%d items missing in data group beginning "
                     "with %s", lack, format_symbol(mpl, row));
            }
            /* construct complete n-tuple */
            tuple = create_tuple(mpl);
            for (temp = slice; temp != NULL; temp = temp->next)
            {  if (temp->sym == NULL)
               {  /* substitution is needed */
                  switch (++which)
                  {  case 1:
                        /* substitute in the first null position */
                        tuple = expand_tuple(mpl, tuple,
                           copy_symbol(mpl, tr ? col->sym : row));
                        break;
                     case 2:
                        /* substitute in the second null position */
                        tuple = expand_tuple(mpl, tuple,
                           copy_symbol(mpl, tr ? row : col->sym));
                        break;
                     default:
                        insist(which != which);
                  }
               }
               else
               {  /* copy symbol from the slice */
                  tuple = expand_tuple(mpl, tuple, copy_symbol(mpl,
                     temp->sym));
               }
            }
            insist(which == 2);
            /* add constructed n-tuple to elemental set */
            check_then_add(mpl, memb->value.set, tuple);
            get_token(mpl /* + */);
         }
         /* delete the row symbol */
         delete_symbol(mpl, row);
      }
      /* delete the column list */
      delete_slice(mpl, list);
      return;
}