Пример #1
0
int main(int argc, char *argv[])
{
	struct zz_tree tree;
	struct zz_node *n1, *n2, *n3, *n4, *n5, *n6;

	zz_tree_init(&tree, sizeof(struct node_with_location));

	n1 = zz_node(&tree, TOK_FOO, zz_null);
	set_location(n1, 1);
	n2 = zz_node(&tree, TOK_BAR, zz_int(-314));
	set_location(n2, 2);
	n3 = zz_node(&tree, TOK_BAZ, zz_uint(314));
	set_location(n3, 3);
	n4 = zz_node(&tree, TOK_FOO, zz_double(0.5));
	set_location(n4, 5);
	n5 = zz_node(&tree, TOK_BAR, zz_string("314"));
	set_location(n5, 8);
	n6 = zz_node(&tree, TOK_BAZ, zz_pointer(&tree));
	set_location(n6, 13);

	assert(get_location(n1) == 1);
	assert(get_location(n2) == 2);
	assert(get_location(n3) == 3);
	assert(get_location(n4) == 5);
	assert(get_location(n5) == 8);
	assert(get_location(n6) == 13);

	exit(EXIT_SUCCESS);
}
Пример #2
0
struct zz_node * zz_copy(struct zz_tree * tree, struct zz_node * node)
{
	switch (node->type) {
	case ZZ_NULL:
		return zz_null(tree, node->token);
	case ZZ_INT:
		return zz_int(tree, node->token, node->data.int_val);
	case ZZ_UINT:
		return zz_uint(tree, node->token, node->data.uint_val);
	case ZZ_DOUBLE:
		return zz_double(tree, node->token, node->data.double_val);
	case ZZ_STRING:
		return zz_string(tree, node->token, node->data.str_val);
	case ZZ_POINTER:
		return zz_pointer(tree, node->token, node->data.ptr_val);
	}
	return NULL;
}