|
15 | 15 | * - if type is variable : val is the variable litteral as int value in ascii table. Exemple: x variable is 120 (btw 120=='x')
|
16 | 16 | * - if type is operator : the operator enum value
|
17 | 17 | * left : the left child if exists
|
18 |
| - * right : the right child if exists |
| 18 | + * right : the right child if exists, unused for NOT node |
19 | 19 | */
|
20 | 20 | struct _FunctionNode {
|
21 | 21 | NodeType type;
|
@@ -210,39 +210,31 @@ TruthTable* ftree_toTruthTable(FunctionTree* ftree, char* vars) {
|
210 | 210 | return table;
|
211 | 211 | }
|
212 | 212 |
|
213 |
| -FunctionTree* ftree_simplify(FunctionTree* ftree) { |
214 |
| - // TODO |
215 |
| - |
216 |
| - return ftree; |
217 |
| -} |
218 |
| - |
219 | 213 |
|
220 | 214 | /**
|
221 | 215 | * id = 1 at first call
|
222 | 216 | */
|
223 |
| -static void rec_ftree_printDot(FunctionNode* node, FILE* out, int id) { |
224 |
| - int lid, rid; |
| 217 | +static void rec_ftree_printDot(FunctionNode* node, FILE* out) { |
225 | 218 | if(node==0) return;
|
226 | 219 | if(node->type==NodeType_VALUE) {
|
227 |
| - fprintf(out, " n%d [label=\"%d\"]\n", id, node->val); |
| 220 | + fprintf(out, " n%p [label=\"%d\"]\n", node, node->val); |
228 | 221 | }
|
229 | 222 | else if(node->type==NodeType_VARIABLE) {
|
230 |
| - fprintf(out, " n%d [label=\"%c\"]\n", id, (char)node->val); |
| 223 | + fprintf(out, " n%p [label=\"%c\"]\n", node, (char)node->val); |
231 | 224 | }
|
232 | 225 | else if(node->type==NodeType_OPERATOR) {
|
233 |
| - lid = 2*id; |
234 |
| - rid = 2*id+1; |
235 |
| - fprintf(out, " n%d [label=\"%c\"]\n", id, ftree_operatorToChar(node->val)); |
236 |
| - fprintf(out, " n%d -- n%d\n", id, lid); |
237 |
| - fprintf(out, " n%d -- n%d\n", id, rid); |
238 |
| - rec_ftree_printDot(node->left, out, lid); |
239 |
| - rec_ftree_printDot(node->right, out, rid); |
| 226 | + fprintf(out, " n%p [label=\"%c\"]\n", node, ftree_operatorToChar(node->val)); |
| 227 | + fprintf(out, " n%p -- n%p\n", node, node->left); |
| 228 | + if(node->val != Op_NOT) |
| 229 | + fprintf(out, " n%p -- n%p\n", node, node->right); |
| 230 | + rec_ftree_printDot(node->left, out); |
| 231 | + rec_ftree_printDot(node->right, out); |
240 | 232 | }
|
241 | 233 | }
|
242 | 234 |
|
243 | 235 | void ftree_printDot(FunctionTree* ftree, FILE* out) {
|
244 | 236 | fprintf(out, "## Generated by Boolean Functions v%g\n", VERSION);
|
245 | 237 | fprintf(out, "graph {\n");
|
246 |
| - rec_ftree_printDot(ftree->root, out, 1); |
| 238 | + rec_ftree_printDot(ftree->root, out); |
247 | 239 | fprintf(out, "}\n");
|
248 | 240 | }
|
0 commit comments