コード例 #1
0
ファイル: dictionary.c プロジェクト: Pand9/IPP-2015-1
int parse_and_print_to_stdout(const char * operation)
{
    if (NULL == operation)
    {
        skip_line(stdin);
        return -1;
    }
    if (0 == strcmp(OP_INSERT, operation))
    {
        if (0 != parse_insert(stdin, word_buffer, MAX_WORD_LEN))
            return -1;
        int word_num = trie_insert(word_buffer);
        if (word_num < 0)
            return -1;
        printf("word number: %d\n", word_num);
    }
    if (0 == strcmp(OP_PREV, operation))
    {
        int number, start, end;
        if (0 != parse_prev(stdin, &number, &start, &end))
            return -1;
        int word_num = trie_prev(number, start, end);
        if (word_num < 0)
            return -1;
        printf("word number: %d\n", word_num);
    }
    if (0 == strcmp(OP_DELETE, operation))
    {
        int number;
        if (0 != parse_delete(stdin, &number))
            return -1;
        int word_num = trie_delete(number);
        if (word_num < 0)
            return -1;
        printf("deleted: %d\n", number);
    }
    if (0 == strcmp(OP_FIND, operation))
    {
        if (0 != parse_find(stdin, word_buffer, MAX_WORD_LEN))
            return -1;
        int find_result = trie_find(word_buffer, strlen(word_buffer));
        if (find_result < 0)
            return -1;
        puts(find_result == 0 ? "YES" : "NO");
    }
    if (0 == strcmp(OP_CLEAR, operation))
    {
        if (0 != parse_clear(stdin))
            return -1;
        if (0 != trie_clear())
            return -1;
        puts("cleared");
    }
    return 0;
}
コード例 #2
0
ファイル: v7.c プロジェクト: di3online/v7
//  factor  =   number | string_literal | "(" expression ")" |
//              variable | "this" | "null" | "true" | "false" |
//              "{" object_literal "}" |
//              "[" array_literal "]" |
//              function_definition |
//              function_call
static enum v7_err parse_factor(struct v7 *v7) {
  int old_sp = v7_sp(v7);

  if (*v7->cursor == '(') {
    TRY(match(v7, '('));
    TRY(parse_expression(v7));
    TRY(match(v7, ')'));
  } else if (*v7->cursor == '\'' || *v7->cursor == '"') {
    TRY(parse_string_literal(v7));
  } else if (*v7->cursor == '{') {
    TRY(parse_object_literal(v7));
  } else if (is_alpha(*v7->cursor) || *v7->cursor == '_') {
    TRY(parse_identifier(v7));
    if (test_token(v7, "this", 4)) {
      inc_stack(v7, 1);
      v7_top(v7)[-1] = &v7->scopes[v7->current_scope];
    } else if (test_token(v7, "null", 4)) {
      TRY(v7_make_and_push(v7, V7_NULL));
    } else if (test_token(v7, "true", 4)) {
      TRY(v7_make_and_push(v7, V7_BOOL));
      v7_top(v7)[-1]->v.num = 1;
    } else if (test_token(v7, "false", 5)) {
      TRY(v7_make_and_push(v7, V7_BOOL));
      v7_top(v7)[-1]->v.num = 0;
    } else if (test_token(v7, "function", 8)) {
      TRY(parse_function_definition(v7, NULL, 0));
    } else if (test_token(v7, "delete", 6)) {
      TRY(parse_delete(v7));
    } else {
      TRY(parse_variable(v7));
    }
  } else {
    TRY(parse_num(v7));
  }

  if (*v7->cursor == '(') {
    TRY(parse_function_call(v7));
  }

  // Don't leave anything on stack if no execution flag is set
  if (v7->no_exec) {
    inc_stack(v7, old_sp - v7->sp);
  }

  return V7_OK;
}
コード例 #3
0
ファイル: intset.c プロジェクト: Comnir/synchrobench
int set_remove_l(intset_l_t *set, val_t val, int transactional)
{
	if (transactional == 2) return parse_delete(set, val);
	else return lockc_delete(set, val);
}