Exemple #1
0
void reduce(LTerm *tree) {
	for(int i = 0; i < tree->size(); i++) {
			tree->set(i, simplify((*tree)[i]));
	}
	Term *f = tree->flatten();
	if(!f->isTerminal()) {
		LTerm *t = dynamic_cast<LTerm*>(f);
		*tree = *t;
	}
}
Exemple #2
0
Term* simplify(Term *t) {
	if(t->isTerminal()) {
		return t;
	}
	
	LTerm *cur = dynamic_cast<LTerm*> (t);
	Term* c = cur->flatten();
	
	if(c->isTerminal()) {
		return c;
	}
	
	LTerm *cur1 = dynamic_cast<LTerm*> (c);
	reduce(cur1);
	return cur1;
}