Esempio n. 1
0
static struct oplist *parse(int fd)
{
	struct oplist *ops = readops(fd);

	/* handle (...) constructions first */

	matchrep(ops);
	cleanrep(ops);
	checkrep(ops);

	/* handle [...] constructions now that rep/inner levels are known */

	matchloop(ops);

	return ops;
}
Esempio n. 2
0
int apply_rules_and_optimize(exp_tree_t** rules, int rc, exp_tree_t *tree)
{
	int success = 0;
	while (1) {
		if (matchloop(rules, rc, tree)) {
			/*
			 * Reduction algorithm
			 * suceeded, print reduced tree
			 */
			#ifdef DEBUG_2
				printout_tree(*tree);
				printf("\n");
			#endif
			#ifdef DEBUG
				printout_tree_infix(*tree);
				printf("\n");
			#endif
			success = 1;
		}

		/*
		 * If optimization succeeds in
		 * modifying the tree, try
		 * reducing the new optimized
		 * tree.
		 */
		if (optimize(tree)) {
			#ifdef DEBUG
				printf("[optimize] \n");
				#ifdef DEBUG_2
					printout_tree(*tree);
					printf("\n");
				#endif
				printout_tree_infix(*tree);
				printf("\n");
			#endif
			success = 1;
			continue;
		}
		break;
	}
	return success;
}