예제 #1
0
파일: tree_stuff.cpp 프로젝트: DavieV/judge
	void kill_tree(Node<T>* root){
		if(root == nullptr)
			return;
		kill_tree(root->left_);
		kill_tree(root->right_);
		delete root;
	}
예제 #2
0
static void
closedownLogout(Display * display, int screens)
{
	Atom        __SWM_DELETE_WINDOW = None;
	Atom        __SWM_PROTOCOLS = None;
	Atom        __SWM_STATE = None;
	int         j;

#if 0
	/* synchronize -- so I'm aware of errors immediately */
	XSynchronize(display, True);

	/* use my error handler from here on out */
	(void) XSetErrorHandler(err_handler);
#endif

	/* init atoms */
	__SWM_STATE = XInternAtom(display, "__SWM_STATE", False);
	__SWM_PROTOCOLS = XInternAtom(display, "__SWM_PROTOCOLS", False);
	__SWM_DELETE_WINDOW = XInternAtom(display, "__SWM_DELETE_WINDOW", False);

	/* start looking for windows to kill -- be nice on pass 1 */
	for (j = 0; j < screens; j++)
		recurse_tree(display, RootWindow(display, j),
			  __SWM_STATE, __SWM_PROTOCOLS, __SWM_DELETE_WINDOW);

	/* wait for things to clean themselves up */
	(void) sleep(NAP_TIME);

	/* this will forcibly kill anything that's still around --
	   this second pass may or may not be needed... */
	for (j = 0; j < screens; j++)
		kill_tree(display, RootWindow(display, j));
	(void) sleep(NAP_TIME);
}
예제 #3
0
파일: parser.c 프로젝트: Jille/splparser
static void
kill_tree(synt_tree *t, synt_tree **zombies) {
	if(t->type == 0) {
		t->next = *zombies;
		*zombies = t;
		return;
	}
	synt_tree *next, *el = t->fst_child;
	while(el != NULL) {
		next = el->next;
		kill_tree(el, zombies);
		el = next;
	}
	t->next = (void *)0xdeadc0de;
	free(t);
}
예제 #4
0
파일: parser.c 프로젝트: Jille/splparser
/**
 * Try unifying the given rulepart to the next tokens in the generator.
 * Returns 0 if unification failed and updates synt_error.
 * Returns the number of succeeded unifications returned by reference.
 */
int
ruleparser(lazyarray *gen, grammar *gram, struct attempt *a, synt_error *e)
{
#ifdef VERBOSE_PARSER_DEBUG
	printf("[att_queue] Working on %p\n", a);
#endif
	if(*a->tree != NULL) {
#ifdef VERBOSE_PARSER_DEBUG
		printf("[%p] Cleaning tree\n", a);
#endif
		// We moeten deze tree opruimen
		synt_tree *graveyard = NULL, *next;
		do {
			next = (*a->tree)->next;
#ifdef VERBOSE_PARSER_DEBUG
			show_synt_tree(*a->tree, 2, gram);
#endif
			kill_tree(*a->tree, &graveyard);
			*a->tree = next;
		} while(*a->tree != NULL);
		while(graveyard != NULL) {
			next = graveyard->next;
			// printf("Unshifted %s\n", token_to_string(graveyard->token->type));
			// generator_unshift(gen, graveyard->token);
			free(graveyard);
			graveyard = next;
		}
		*a->tree = NULL;
	}
#ifdef VERBOSE_PARSER_DEBUG
	printf("[%p] Upcoming input: \n", a);
	peek_upcoming_input(gen, a->inputidx, 50);
#endif

	while(a->branch != NULL) {
		if(a->branch->is_literal) {
			if(!lazyarray_exists(gen, a->inputidx)) {
#ifdef VERBOSE_PARSER_DEBUG
				fprintf(stderr, "Hit EOF while expecting %s\n", token_to_string(a->branch->token));
#endif
				return 0;
			}
			struct token *t = lazyarray_get(gen, a->inputidx++);
#ifdef VERBOSE_PARSER_DEBUG
			printf("Shifted %s\n", token_to_string(t->type));
#endif
			*a->tree = malloc(sizeof(synt_tree));
			(*a->tree)->type = 0;
			(*a->tree)->token = t;
			(*a->tree)->next = NULL;
			a->tree = &(*a->tree)->next;
			if(a->branch->token != t->type) {
				char *buf;
				asprintf(&buf, "parser(%d): expected literal %s, read %s\n", t->lineno, token_to_string(a->branch->token), token_to_string(t->type));
				update_synt_error(e, buf, t->lineno, 0);
				a->inputidx--;
				// printf("Unshifted %s\n", token_to_string(t->type));
				// generator_unshift(gen, t);
				return 0;
			}
		} else {
			struct rule *rule = &gram->rules[a->branch->rule];
			int i;
#ifdef VERBOSE_PARSER_DEBUG
			fprintf(stderr, "parser(): > trying to unify rule %d (%s)\n", a->branch->rule, rule->name);
#endif
			synt_tree *tree = malloc(sizeof(synt_tree));
			tree->type = 1;
			tree->next = NULL;
			tree->fst_child = NULL;
			tree->rule = a->branch->rule;
			*a->tree = tree;
			a->tree = &(*a->tree)->next;
			for(i = 0; rule->branches[i] != NULL; ++i) {
				struct attempt *new_attempt = malloc(sizeof(struct attempt));
				new_attempt->tree     = &tree->fst_child;
				new_attempt->branch   = rule->branches[i];
				new_attempt->parent   = a;
				new_attempt->parentbranch = a->branch->next;
				new_attempt->parenttree = a->tree;
				new_attempt->next     = att_head;
				new_attempt->inputidx     = a->inputidx;
				att_head = new_attempt;
#ifdef VERBOSE_PARSER_DEBUG
				printf("[%p] Queued %p (%s)\n", a, new_attempt, rule->name);
#endif
			}
			a->branch = NULL;
			return 0;
		}
		a->branch = a->branch->next;
	}

#ifdef VERBOSE_PARSER_DEBUG
	printf("[%p] Completed\n", a);
#endif

	if(a->branch == NULL) {
		if(a->parent == NULL) {
			// Wij zijn S
			if(lazyarray_exists(gen, a->inputidx)) {
#ifdef VERBOSE_PARSER_DEBUG
				puts("Complete, but not at EOF");
#endif
				return 0;
			}
#ifdef VERBOSE_PARSER_DEBUG
			puts("Great success");
#endif
			return 1;
		}
		a->parent->branch = a->parentbranch;
		a->parent->tree = a->parenttree;
		a->parent->next = att_head;
		a->parent->inputidx = a->inputidx;
		att_head = a->parent;
#ifdef VERBOSE_PARSER_DEBUG
		printf("[%p] Requeuing parent %p\n", a, a->parent);
#endif
		// TODO: only free if there are no childs
		//free(a);
	}
	return 0;
}
예제 #5
0
void PlayerMCTS::kill_tree(Node *node)
{
    for (Node *child : node->children)
        kill_tree(child);
    delete node;
}
예제 #6
0
파일: tree_stuff.cpp 프로젝트: DavieV/judge
	~search_tree(){
		kill_tree(root_);
	}