Exemplo n.º 1
0
cell_t *parse_sexpr(file_io_t * in, file_io_t * err)
{
        int c;
        if (in != NULL)
                while ((c = wrap_get(in)) != '\0') {
                        if (isspace(c))
                                continue;

                        if (isdigit(c)) {
                                wrap_ungetc(in, c);
                                return parse_number(in, err);
                        }

                        switch (c) {
                        case '(':
                                return parse_list(in, err);
                        case '"':
                                return parse_string(in, err);
                        case EOF:
                                print_error("EOF, nothing to parse", err);
                                return NULL;
                        case ')':
                                print_error("Unmatched ')'", err);
                                return NULL;
                        default:
                                wrap_ungetc(in, c);
                                return parse_symbol(in, err);
                        }

                }

        print_error("parse_expr in == NULL", err);
        return NULL;
}
Exemplo n.º 2
0
pointer parse_number_or_pair(parser* parse)
{
    char next = (*(parse->curr+1));

    pointer ret_car;
    pointer ret_cdr;

    if(is_whitespace(next))
    {
        parse->curr++;
        return parse_expr(parse);
    }
    else if(next >= '0' && next <= '9')
    {
        ret_car = parse_number(parse);
        ret_cdr = parse_expr(parse);
        return create_pair(ret_car, ret_cdr);
    }
    else
    {
        ret_car = parse_symbol(parse);
        ret_cdr = parse_expr(parse);
        return create_pair(ret_car, ret_cdr);
    }
}
Exemplo n.º 3
0
pointer parse_expr(parser* parse)
{
    eat_whitespace(parse);
    pointer ret_car;
    pointer ret_cdr;
    switch(*parse->curr)
    {
    case '(':
        parse->curr++;
        ret_car = parse_expr(parse);
        ret_cdr = parse_expr(parse);
        return create_pair(ret_car, ret_cdr);
    case '"':
        ret_car = parse_string(parse);
        ret_cdr = parse_expr(parse);
        return create_pair(ret_car, ret_cdr);
    case '\'':
        parse->curr++;
        ret_car = parse_quote(parse);
        ret_cdr = parse_expr(parse);
        return create_pair(ret_car, ret_cdr);
    case ')':
        parse->curr++;
        return NIL;
    case '+': case '-': case 'b':
        ret_car = parse_number_or_symbol(parse);
        ret_cdr = parse_expr(parse);
        return create_pair(ret_car, ret_cdr);
    case '.':
        return parse_number_or_pair(parse);
    case '\\':
        parse->curr++;
        ret_car = create_char(*(parse->curr++));
        ret_cdr = parse_expr(parse);
        return create_pair(ret_car, ret_cdr);
    case ';':
        while(!is_newline(*parse->curr) && *parse->curr != '\0')
            parse->curr++;
        return parse_expr(parse);
    case 0:
        return NIL;
    default:
        if(is_number_char(*parse->curr))
        {
            ret_car = parse_number(parse);
            ret_cdr = parse_expr(parse);
            return create_pair(ret_car, ret_cdr);
        }
        else if(is_symbol_char(*parse->curr))
        {
            ret_car = parse_symbol(parse);
            ret_cdr = parse_expr(parse);
            return create_pair(ret_car, ret_cdr);
        }
        else
            return parser_error(parse, "Unexpected char in expression.");

    }
    parse->curr++;
}
Exemplo n.º 4
0
Arquivo: parsing.c Projeto: 8l/eight
closure *parse_null(FILE *file, closure *accum)
{
    //printf("parse null\n");
    wchar_t c = fgetwc(file);
    if(iswspace(c)){
	return parse_null(file, nil());
    } else if(c == L'$'){
	return parse_character(file, nil());
    } else if(c == L'#'){
	parse_comment(file, nil());
	return parse_null(file, accum);
    } else if(c == L'\"'){
	return parse_string(file, nil());
    } else if(c == L'\''){
	wchar_t c = fgetwc(file);
	if (!iswspace(c)){
	    ungetwc(c, file);
	    closure *boo = parse_null(file, nil());
	    if (boo != NULL) return quote(boo);
	}
	return symbol(QUOTE);
    } else if(c == L'@'){
	wchar_t c = fgetwc(file);
	if (!iswspace(c)){
	    ungetwc(c, file);
	    closure *boo = parse_null(file, nil());
	    if (boo != NULL) return list(2, symbol(ATPEND), boo);
	}
	return symbol(ATPEND);
    } else if(c == L','){
	wchar_t c = fgetwc(file);
	if (!iswspace(c)){
	    ungetwc(c, file);
	    closure *boo = parse_null(file, nil());
	    if (boo != NULL) return list(2, symbol(COMMA), boo);
	}
	return symbol(COMMA);
    } else if(c == L'*'){
	wchar_t c = fgetwc(file);
	if (!iswspace(c)){
	    ungetwc(c, file);
	    closure *boo = parse_null(file, nil());
	    if (boo != NULL) return list(2, symbol(ASTERIX), boo);
	}
	return symbol(ASTERIX);
    } else if(iswdigit(c)){
	ungetwc(c, file);
	return parse_number(file, nil());
    } else if(c == L'('){
	return parse_list(file, nil());
    } else if(c == L')'){
	ungetwc(c, file);
	return NULL;
    } else if(c == WEOF || c == EOF){
	return NULL;
    } else {
	return parse_symbol(file, cons(character(c), nil()));
    }
}
Exemplo n.º 5
0
pointer parse_number_or_symbol(parser* parse)
{
    // The scheme spec doesn't explicitlly call for symbols like ++, but we're going to allow them.

    char next = (*(parse->curr+1));
    if(next >= '0' && next <= '9')
        return parse_number(parse);
    else
        return parse_symbol(parse);

}
Exemplo n.º 6
0
Atom parse_atom_aux(char *token)
{
    if (is_integer_token(token))
        return parse_integer(token);
    if (is_ratio_token(token))
        return parse_ratio(token);
    if (is_string_token(token))
        return parse_string(token);

    return parse_symbol(token, package);
}
Exemplo n.º 7
0
 change_of_basis_op::change_of_basis_op(
   std::string const& symbol,
   const char* stop_chars,
   int r_den,
   int t_den)
 :
   c_(0, 0),
   c_inv_(0, 0)
 {
   parse_string parse_symbol(symbol);
   *this = change_of_basis_op(parse_symbol, stop_chars, r_den, t_den);
 }
Exemplo n.º 8
0
static BtorNode *
parse_var (BtorBTORParser * parser, int len)
{
  BtorNode *res;

  if (!parse_symbol (parser))
    return 0;

  res = btor_var_exp (parser->btor, len, parser->symbol.start);
  BTOR_PUSH_STACK (parser->mem, parser->inputs, res);
  parser->info.start[parser->idx].var = 1;

  return res;
}
Exemplo n.º 9
0
Arquivo: parsing.c Projeto: 8l/eight
closure *parse_number(FILE *file, closure *accum)
{
    wchar_t c = fgetwc(file);
    if(iswdigit(c)){
	return parse_number(file, cons(character(c), accum));
    } else if(iswspace(c)) {
	return string_to_number(reverse(accum));
    } else if(c == L')') {
	ungetwc(c, file); 
	return string_to_number(reverse(accum));
    } else {
	ungetwc(c, file);
	return parse_symbol(file, accum);
    }
}
Exemplo n.º 10
0
pointer parse_quote(parser* parse)
{
    if(is_whitespace(*parse->curr))
        return parser_error(parse, "unexpected whitespace after quote.");

    switch(*parse->curr)
    {
    case '(':
        return create_pair(create_symbol(parse->symbols, "QUOTE"), parse_expr(parse));
    default:
        if(is_symbol_char(*parse->curr) && !is_number_char(*parse->curr))
            return create_pair(create_symbol(parse->symbols, "QUOTE"), parse_symbol(parse));
        else
            return parser_error(parse, "Unexpected token after quote.");

    }

}
Exemplo n.º 11
0
Bar::Bar(XMLNode *xml) : Widget(xml){
    float scale_x, scale_y, scale_z;
    const char *my_name;
    const char *label;
    char tmp[255];
    int i = 0;

    scale_x = xml->getAttributeValueAsFloat("scale_x", 1);
    scale_y = xml->getAttributeValueAsFloat("scale_y", 1);
    scale_z = xml->getAttributeValueAsFloat("scale_z", 1);
    SceneGraph *scene_bar = new SceneGraph();
    SceneGraph *temp_scene = new SceneGraph();
    temp_scene->loadModel("components/bar/base.wrl");
    temp_scene->setScale(scale_x, scale_y, scale_z);
    scene_bar->mergeScene(temp_scene);
    label = xml->getAttributeValue("label");
    if(label != NULL){
        my_name = label;
    }else{
        my_name = getName();
    }
    while(my_name[i] != '\0' && i < 20){
        // create new nodes
        temp_scene = new SceneGraph();
        // parse the current symbol / character
        if(my_name[i] != ' '){
            parse_symbol(tmp, my_name[i]);
            // read the component model, and move it to its destination coordinates
            temp_scene->loadModel(tmp);
            temp_scene->setTranslate(0.2+0.6*i,0.15,0);
            scene_bar->mergeScene(temp_scene);
        }
        i++;
    }
    const char *ani = xml->getAttributeValue ( "clickanimation" );
    if ( ani != NULL )
        animationName = new std::string(ani);
    else
        animationName = NULL;
    getSceneGraph()->mergeScene(scene_bar);
}
Exemplo n.º 12
0
Arquivo: parsing.c Projeto: 8l/eight
closure *parse_symbol(FILE *file, closure *accum)
{
    //printf("parse sym\n");
    wchar_t c = fgetwc(file);
    if(iswspace(c)) {
	return string_to_symbol(reverse(accum));
    } else if(c == L'\"'){
	ungetwc(c, file); 
	return string_to_symbol(reverse(accum));
    } else if(c == L'('){
	ungetwc(c, file); 
	return string_to_symbol(reverse(accum));
    } else if(c == L')') {
	ungetwc(c, file); 
	return string_to_symbol(reverse(accum));
    } else if(c == L'#'){
	ungetwc(c, file); 
	return string_to_symbol(reverse(accum));
    } else {
	return parse_symbol(file, cons(character(c), accum));
    }
}
Exemplo n.º 13
0
static const char *parse(opstack ** stack, const char *inn,
  const void *userdata)
{
  const char *b = inn;
  while (*b) {
    switch (*b) {
      case '"':
        return parse_string(stack, ++b, userdata);
        break;
      case '$':
        return parse_symbol(stack, ++b, userdata);
        break;
      default:
        if (isdigit(*(unsigned char *)b) || *b == '-' || *b == '+') {
          return parse_int(stack, b);
        } else
          ++b;
    }
  }
  log_error("could not parse \"%s\". Probably invalid message syntax.", inn);
  return NULL;
}
Exemplo n.º 14
0
static BtorNode *
parse_array (BtorBTORParser * parser, int len)
{
  BtorNode *res;
  int idx_len;

  if (parse_space (parser))
    return 0;

  if (parse_positive_int (parser, &idx_len))
    return 0;

  if (!parse_symbol (parser))
    return 0;

  res = btor_array_exp (parser->btor, len, idx_len, parser->symbol.start);
  BTOR_PUSH_STACK (parser->mem, parser->inputs, res);
  parser->info.start[parser->idx].array = 1;

  parser->found_arrays = 1;

  return res;
}
Exemplo n.º 15
0
static struct AstNode *parse_one(
        struct DomNode *dom,
        struct ParserState *state)
{
    err_reset();
    struct AstNode *node;
    if ((!err_state() && (node = parse_literal_atomic(dom, state))) ||
        (!err_state() && (node = parse_symbol(dom, state))) ||
        (!err_state() && (node = parse_special(dom, state))) ||
        (!err_state() && (node = parse_func_call(dom, state))) ||
        (!err_state() && (node = parse_literal_compound(dom, state)))) {
        if (state->acb) {
            state->acb(state->data, node, &dom->loc);
        }
        return node;

    } else {
        err_push_src(
            "PARSE",
            &dom->loc,
            "Failed parsing DOM node");
        return NULL;
    }
}
Exemplo n.º 16
0
obj_mesh* obj_load_mesh(const char* filename)
{
    char* buffer = load_entire_file(filename, "r");

    if(!buffer)
        return NULL;

    // Build size counts
    char* curr = buffer;

    unsigned int position_count = 0;
    unsigned int uv_count = 0;
    unsigned int normal_count = 0;
    unsigned int face_count = 0;

    while(*curr != '\0')
    {
        if(is_whitespace(*curr))
        {
            curr++;
            continue;
        }

        if(check_match(curr, "v"))
            position_count++;
        else if(check_match(curr, "vt"))
            uv_count++;
        else if(check_match(curr, "vn"))
            normal_count++;
        else if(check_match(curr, "f"))
            face_count++;

        skip_line(&curr);

    }


    printf("Vertices: %d, Faces: %d.\n", position_count, face_count);

    vector3* positions = new vector3[position_count];
    vector2* uvs = new vector2[uv_count];
    vector3* normals = new vector3[normal_count];
    obj_vert* verticies = new obj_vert[face_count*3];

    unsigned int pidx = 0;
    unsigned int uvidx = 0;
    unsigned int nidx = 0;
    unsigned int fidx = 0;

    // Actually parse the obj file

    material_params current_params;
    load_ssh("Default", &current_params);

    curr = buffer;

    while(*curr != '\0')
    {
        if(is_whitespace(*curr))
        {
            curr++;
            continue;
        }

        if(check_match(curr, "v"))
        {
            curr++;
            assert(pidx < position_count);
            positions[pidx].x = parse_float(&curr);
            positions[pidx].y = parse_float(&curr);
            positions[pidx].z = parse_float(&curr);
            pidx++;
            skip_line(&curr);
        }
        else if(check_match(curr, "vt"))
        {
            curr += 2;
            assert(uvidx < uv_count);
            uvs[uvidx].x = parse_float(&curr);
            uvs[uvidx].y = parse_float(&curr);
            uvidx++;
            skip_line(&curr);
        }
        else if(check_match(curr, "vn"))
        {
            curr += 2;
            assert(nidx < normal_count);

            normals[nidx].x = parse_float(&curr);
            normals[nidx].y = parse_float(&curr);
            normals[nidx].z = parse_float(&curr);
            nidx++;
            skip_line(&curr);
        }
        else if(check_match(curr, "f"))
        {
            curr++;
            assert(fidx+2 < face_count*3);

            populate_face(&curr, &verticies[fidx++], positions, uvs, normals, current_params);
            populate_face(&curr, &verticies[fidx++], positions, uvs, normals, current_params);
            populate_face(&curr, &verticies[fidx++], positions, uvs, normals, current_params);

            skip_line(&curr);
        }
        else if(check_match(curr, "usemtl"))
        {
            curr += 6;
            char* material = parse_symbol(&curr);
            if(material)
            {
                if(!load_ssh(material, &current_params))
                        load_ssh("Default", &current_params);
                delete [] material;
            }
            skip_line(&curr);
        }
        else
            skip_line(&curr);

    }

    obj_mesh* mesh = new obj_mesh();

    mesh->vertex_count = face_count*3;
    mesh->verticies = verticies;

    delete [] positions;
    delete [] uvs;
    delete [] normals;

    delete [] buffer;

    return mesh;
}
Exemplo n.º 17
0
static atom_p parse_list(parsebuf_p pb, expression_callback_t out, int indentation)
{
  int c, i, terminator;
  atom_p first, prev, curr;
  struct __operator * operator;
  parsebuf_t buf;
  DEBUG();

  // Grab the opening parenthesis, or whatever it is
  __consume_whitespace(pb);
  __parsebuf_snapshot(pb, &buf);
  if((c = __parsebuf_next(pb)) == '(') {
    terminator = ')';
  } else if(c == '[') {
    terminator = ']';
  } else if(c == '<') {
    terminator = '>';
  } else if(c == '{') {
    terminator = '}';
  } else {
    splinter_error_return(NULL, "%s invalid list opening @ %d:%d", buf.n, buf.l, buf.c);
  }

  __consume_whitespace(pb);
  if ((operator = __find_closest_token(pb, terminator)) == NULL)
    return NULL;

  __parse_out_indentation(out, indentation);
  __parse_out_char(out, c);
  __parse_out_string(out, operator->token, (int)strlen(operator->token));

  for(first = prev = curr = NULL; 1;) {
    __consume_whitespace(pb);
    i = pb->i;
    __parse_out_char(out, '\n');
    if((c = __parsebuf_next(pb)) <= 0) {
      splinter_error_set("%s missing list closing @ %d:%d", buf.n, pb->l, pb->c);
      return atom_free(first);
    } else if(c == terminator) {
      if ((curr = atom_alloc_list(operator->exec_call, first)) == NULL) {
        return atom_free(first);
      }
      __parse_out_indentation(out, indentation);
      __parse_out_char(out, terminator);
      return curr;
    } else if(c == '0' && (__parsebuf_peek(pb) == 'x' || __parsebuf_peek(pb) == 'X')) {
      __parsebuf_prev(pb);
      curr = parse_hex(pb, operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if('0' <= c && c <= '9') {
      __parsebuf_prev(pb);
      curr = (c == '0') ? parse_oct(pb, operator->mode) : parse_uint(pb, operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if(c == '-' && ('0' <= __parsebuf_peek(pb) && __parsebuf_peek(pb) <= '9')) {
      __parsebuf_prev(pb);
      curr = parse_int(pb, operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if(c == '(' || c == '[' || c == '<' || c == '{') {
      __parsebuf_prev(pb);
      curr = parse_list(pb, out, indentation + 2);
    } else if(c == '\'') {
      curr = parse_string(pb, '\'', operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if(c == '"') {
      curr = parse_string(pb, '"', operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else if (c == '$') {
      __parsebuf_prev(pb);
      curr = parse_variable(pb, terminator, operator->mode);
      if (curr != NULL) __parse_out_line(out, (char *)curr->data, strlen((char *)curr->data), indentation + 2);
    } else if (c == '@') {
      __parsebuf_prev(pb);
      curr = parse_symbol(pb, terminator, operator->mode);
      if (curr != NULL) __parse_out_line(out, pb->s + i, pb->i - i, indentation + 2);
    } else {
      curr = NULL;
    }

    if(curr == NULL) {
      return atom_free(first);
    }

    if(first == NULL) {
      first = prev = curr;
    } else {
      prev->next = curr;
      prev = curr;
    }
  }
}
Exemplo n.º 18
0
static cell_t *parse_list(file_io_t * in, file_io_t * err)
{
        cell_t *head, *child = NULL, *cell_lst = calloc(1, sizeof(cell_t));
        int c;
        head = cell_lst;
        if (cell_lst == NULL) {
                print_error("calloc() failed", err);
                return NULL;
        }
        while ((c = wrap_get(in)) != EOF) {
                if (isspace(c))
                        continue;

                if (isdigit(c)) {
                        wrap_ungetc(in, c);
                        child = parse_number(in, err);
                        if (append(head, child, err))
                                goto FAIL;
                        head = child;
                        continue;
                }

                switch (c) {
                case ')':      /*finished */
                        goto SUCCESS;
                case '(':      /*encountered a nested list */
                        child = calloc(1, sizeof(cell_t));
                        if (child == NULL)
                                goto FAIL;
                        head->cdr.cell = child;
                        child->car.cell = parse_list(in, err);
                        if (child->car.cell == NULL)
                                goto FAIL;
                        child->type = type_list;
                        head = child;
                        break;
                case '"':      /*parse string */
                        child = parse_string(in, err);
                        if (append(head, child, err))
                                goto FAIL;
                        head = child;
                        break;
                case EOF:      /*Failed */
                        print_error("EOF occured before end of list did.", err);
                        goto FAIL;
                default:       /*parse symbol */
                        wrap_ungetc(in, c);
                        child = parse_symbol(in, err);
                        if (append(head, child, err))
                                goto FAIL;
                        head = child;
                        break;
                }

        }
 SUCCESS:
        cell_lst->type = type_list;
        return cell_lst;
 FAIL:
        print_error("parsing list failed.", err);
        free(cell_lst);
        return NULL;
}
Exemplo n.º 19
0
static const char *parse_string(opstack ** stack, const char *in,
    const void *userdata)
{                               /* (char*) -> char* */
    char *c;
    char *buffer = balloc(TOKENSIZE);
    size_t size = TOKENSIZE - 1;
    const char *ic = in;
    char *oc = buffer;
    /* mode flags */
    bool f_escape = false;
    bool bDone = false;
    variant var;

    while (*ic && !bDone) {
        if (f_escape) {
            f_escape = false;
            switch (*ic) {
            case 'n':
                if (size > 0) {
                    *oc++ = '\n';
                    --size;
                }
                break;
            case 't':
                if (size > 0) {
                    *oc++ = '\t';
                    --size;
                }
                break;
            default:
                if (size > 0) {
                    *oc++ = *ic++;
                    --size;
                }
            }
        }
        else {
            int ch = (unsigned char)(*ic);
            size_t bytes;

            switch (ch) {
            case '\\':
                f_escape = true;
                ++ic;
                break;
            case '"':
                bDone = true;
                ++ic;
                break;
            case '$':
                ic = parse_symbol(stack, ++ic, userdata);
                if (ic == NULL)
                    return NULL;
                c = (char *)opop_v(stack);
                bytes = (c ? strlcpy(oc, c, size) : 0);
                if (bytes < size)
                    oc += bytes;
                else
                    oc += size;
                bfree(c);
                break;
            default:
                if (size > 0) {
                    *oc++ = *ic++;
                    --size;
                }
                else
                    ++ic;
            }
        }
    }
    *oc++ = '\0';
    bfree(oc);
    var.v = buffer;
    opush(stack, var);
    return ic;
}
Exemplo n.º 20
0
Checkbox::Checkbox(XMLNode *xml) : Widget(xml) {
    const char *my_name;
    const char *label;
    char tmp[255];
    int i = 0;
    selected = false;
    SceneGraph *scene_chkbox = new SceneGraph();
    SceneGraph *temp_scene = new SceneGraph();
    checked = new SceneGraph();

    // First, prepare the radiobox and the checked marker
    temp_scene->loadModel("components/chkbox/base.wrl");
    scene_chkbox->mergeScene(temp_scene);
    checked->loadModel("components/chkbox/checked.wrl");
    checked->setVisibility(selected);
    scene_chkbox->mergeScene(checked);
    temp_scene->loadModel("components/button/side_left.wrl");
    scene_chkbox->mergeScene(temp_scene);
    label = xml->getAttributeValue("label");
    if(label != NULL) {
        my_name = label;
    } else {
        my_name = getName();
    }
    // add the symbols / characters to the scene
    while(my_name[i] != '\0' && i < 19) {
        // create new nodes
        temp_scene = new SceneGraph();
        // parse the current symbol / character
        if(my_name[i] != ' ') {
            parse_symbol(tmp, my_name[i]);
            // read the component model, and move it to its destination coordinates
            temp_scene->loadModel(tmp);
            temp_scene->setTranslate(0.6*(i+1),0,0);
            scene_chkbox->mergeScene(temp_scene);
        }
        i++;
    }
    // add the base of the button
    temp_scene = new SceneGraph();
    temp_scene->loadModel("components/button/base.wrl");
    temp_scene->setScale(i+1,1,1);
    scene_chkbox->mergeScene(temp_scene);
    // add the right side of the button
    temp_scene = new SceneGraph();
    temp_scene->loadModel("components/button/side_right.wrl");
    temp_scene->setTranslate((0.6*(i)),0,0);
    scene_chkbox->mergeScene(temp_scene);
    getSceneGraph()->mergeScene(scene_chkbox);
    // Load the animation
    const char *ani = xml->getAttributeValue ( "clickanimation" );
    if ( ani != NULL )
        animationName = new std::string(ani);
    else
        animationName = NULL;
    // Load the callback functions
    ani = xml->getAttributeValue ( "callbackSelected" );
    if ( ani != NULL )
        callbackSelected = new std::string(ani);
    else
        callbackSelected = NULL;
    ani = xml->getAttributeValue ( "callbackDeselected" );
    if ( ani != NULL )
        callbackDeselected = new std::string(ani);
    else
        callbackDeselected = NULL;
}
Exemplo n.º 21
0
Arquivo: syntax.c Projeto: kusma/vasm
void parse(void)
{
  char *s,*line,*inst;
  char *ext[MAX_QUALIFIERS?MAX_QUALIFIERS:1];
  char *op[MAX_OPERANDS];
  int ext_len[MAX_QUALIFIERS?MAX_QUALIFIERS:1];
  int op_len[MAX_OPERANDS];
  int ext_cnt,op_cnt,inst_len;
  instruction *ip;

  while (line = read_next_line()) {

    if (!cond_state()) {
      /* skip source until ELSE or ENDIF */
      int idx = -1;

      s = skip(line);
      if (labname = parse_labeldef(&s,1)) {
        if (*s == ':')
          s++;  /* skip double-colon */
        myfree(labname);
        s = skip(s);
      }
      else {
        if (inst = skip_identifier(s)) {
          inst = skip(inst);
          idx = check_directive(&inst);
        }
      }
      if (idx < 0)
        idx = check_directive(&s);
      if (idx >= 0) {
        if (directives[idx].func == handle_if)
          cond_skipif();
        else if (directives[idx].func == handle_else)
          cond_else();
        else if (directives[idx].func == handle_endif)
          cond_endif();
      }
      continue;
    }

    s = skip(line);
again:
    if (*s=='\0' || *line=='*' || *s==commentchar)
      continue;

    if (labname = parse_labeldef(&s,1)) {
      /* we have found a valid global or local label */
      symbol *sym = new_labsym(0,labname);

      if (*s == ':') {
        /* double colon automatically declares label as exported */
        sym->flags |= EXPORT;
        s++;
      }
      add_atom(0,new_label_atom(sym));
      myfree(labname);
      s = skip(s);
    }
    else {
      /* there can still be a sym. in the 1st fld and an assignm. directive */
      inst = s;
      labname = parse_symbol(&s);
      if (labname == NULL) {
        syntax_error(10);  /* identifier expected */
        continue;
      }
      s = skip(s);

      /* Now we have labname pointing to the first field in the line
         and s pointing to the second. Find out where the directive is. */
      if (!ISEOL(s)) {
#ifdef PARSE_CPU_LABEL
        if (PARSE_CPU_LABEL(labname,&s)) {
          myfree(labname);
          continue;
        }
#endif
        if (handle_directive(s)) {
          myfree(labname);
          continue;
        }
      }

      /* directive or mnemonic must be in the first field */
      myfree(labname);
      s = inst;
    }

    if (!strnicmp(s,".iif",4) || !(strnicmp(s,"iif",3))) {
      /* immediate conditional assembly: parse line after ',' when true */
      s = skip(*s=='.'?s+4:s+3);
      if (do_cond(&s)) {
        s = skip(s);
        if (*s == ',') {
          s = skip(s+1);
          goto again;
        }
        else
          syntax_error(0);  /* malformed immediate-if */
      }
      continue;
    }

    /* check for directives */
    s = parse_cpu_special(s);
    if (ISEOL(s))
      continue;

    if (handle_directive(s))
      continue;

    /* read mnemonic name */
    inst = s;
    ext_cnt = 0;
    if (!ISIDSTART(*s)) {
      syntax_error(10);  /* identifier expected */
      continue;
    }
#if MAX_QUALIFIERS==0
    while (*s && !isspace((unsigned char)*s))
      s++;
    inst_len = s - inst;
#else
    s = parse_instruction(s,&inst_len,ext,ext_len,&ext_cnt);
#endif
    if (!isspace((unsigned char)*s) && *s!='\0')
      syntax_error(2);  /* no space before operands */
    s = skip(s);

    if (execute_macro(inst,inst_len,ext,ext_len,ext_cnt,s))
      continue;

    /* read operands, terminated by comma or blank (unless in parentheses) */
    op_cnt = 0;
    while (!ISEOL(s) && op_cnt<MAX_OPERANDS) {
      op[op_cnt] = s;
      s = skip_operand(s);
      op_len[op_cnt] = oplen(s,op[op_cnt]);
#if !ALLOW_EMPTY_OPS
      if (op_len[op_cnt] <= 0)
        syntax_error(5);  /* missing operand */
      else
#endif
        op_cnt++;
      s = skip(s);
      if (*s != ',')
        break;
      else
        s = skip(s+1);
    }
    eol(s);

    ip = new_inst(inst,inst_len,op_cnt,op,op_len);

#if MAX_QUALIFIERS>0
    if (ip) {
      int i;

      for (i=0; i<ext_cnt; i++)
        ip->qualifiers[i] = cnvstr(ext[i],ext_len[i]);
      for(; i<MAX_QUALIFIERS; i++)
        ip->qualifiers[i] = NULL;
    }
#endif

    if (ip)
      add_atom(0,new_inst_atom(ip));
  }

  cond_check();  /* check for open conditional blocks */
}
Exemplo n.º 22
0
token_t *tokenize(char *buf)
{
	token_t *tokens = (token_t *)malloc(sizeof(token_t) * TOKENSIZE);
	token_t *head = tokens;

	while (*buf != '\n') {
		buf = skip_space(buf);
		char c = *buf;

		switch (c) {
		case '(' :
			*tokens = parse_begin(buf);
			tokens++;
			break;

		case ')' :
			*tokens = parse_end(buf);
			tokens++;
			break;

		case '+' :
		case '-' :
			if(isalnum(*(buf+1)))
				goto number;

		case '*' :
		case '/' :
		case '=' :
		case '<' :
		case '>' :
			*tokens = parse_operater(buf);
			tokens++;
			break;

		case '0' :
		case '1' :
		case '2' :
		case '3' :
		case '4' :
		case '5' :
		case '6' :
		case '7' :
		case '8' :
		case '9' :
number:     *tokens = parse_number(buf);
			tokens++;
			while(isalnum(*buf)){
				buf++;
			}
			buf-=1;
			break;

		default:
			*tokens = parse_symbol(buf);
			tokens++;
			while(isalpha(*buf)){
				buf++;
			}
			buf-=1;
			break;
		}
		buf++;
	}
	return head;
}
Exemplo n.º 23
0
static int parse_fields (char *msg)
{
	char stemp[MAX_MSG_LEN+1];
	char *e;
	char *save;

	strcpy (stemp, msg);
	e = strtok_r (stemp, "*#", &save);
	while (e != NULL) {

	  switch (*e) {

	    case 'A': 
	      
	      switch (e[1]) {
	        case 'A':
	          parse_object_name (e);
	          break;
	        case 'B':
	          parse_symbol (e);
	          break;
	        case 'C':
	          /*
	           * New in 1.2: test for 10 digit callsign.
	           */
	          if (tt_call10_to_text(e+2,1,stemp) == 0) {
	             strcpy(m_callsign, stemp);
	          }
	          break;
	        default:
	          parse_callsign (e);
	          break;
	      }
	      break;

	    case 'B': 
	      parse_location (e);
	      break;

	    case 'C': 
	      parse_comment (e);
	      break;

	    case '0': 
	    case '1': 
	    case '2': 
	    case '3': 
	    case '4': 
	    case '5': 
	    case '6': 
	    case '7': 
	    case '8': 
	    case '9': 
	      expand_macro (e);
	      break;

	    case '\0':
	      /* Empty field.  Just ignore it. */
	      /* This would happen if someone uses a leading *. */
	      break;

	    default:

	      text_color_set(DW_COLOR_ERROR);
	      dw_printf ("Entry does not start with A, B, C, or digit: \"%s\"\n", msg);
	      return (TT_ERROR_D_MSG);

	  }
	
	  e = strtok_r (NULL, "*#", &save);
	}

	return (0);

} /* end parse_fields */