File: DNFLWR.c

package info (click to toggle)
qepcad 1.74%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,828 kB
  • sloc: ansic: 27,242; cpp: 2,995; makefile: 1,285; perl: 91
file content (48 lines) | stat: -rw-r--r-- 1,631 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*======================================================================
                      DNFLWR(N,V,F)

Disjuctive Normal Form Label Write.

\Input
   \parm{N} is a non-null list of characters used as the name of the labels.
   \parm{V} is a non-null list of distinct variables.
   \parm{F} is a disjunctive normal form with variables in $V$,
            written out in labels to the output strem.
======================================================================*/
#include "qepcad.h"

void DNFLWR(Word N, Word V, Word F)
{
       Word F1,Fp,T;

Step1: /* Classify the formula F. */
       T = FIRST(F);
       if (T == OROP) goto Step3;
       if (T == ANDOP) goto Step4;
       if (T == NOTOP)   FAIL("DNFLWR","NOTOP not expected.");
       if (T == RIGHTOP) FAIL("DNFLWR","RIGHTOP not expected.");
       if (T == LEFTOP)  FAIL("DNFLWR","LEFTOP not expected.");
       if (T == EQUIOP)  FAIL("DNFLWR","EQUIPOP not expected.");

Step2: /* Atomic formula. */
       ATOMFLWR(N,V,F); goto Return;

Step3: /* Disjunction. */
       Fp = RED(F);
       if (LENGTH(Fp) == 1) { DNFLWR(N,V,FIRST(Fp)); goto Return; }
       ADV(Fp,&F1,&Fp); DNFLWR(N,V,F1);
       while (Fp != NIL)
         { ADV(Fp,&F1,&Fp); SWRITE("    "); LGOPWR(T); SWRITE("\n"); DNFLWR(N,V,F1); }
       goto Return;

Step4: /* Conjunction. */
       Fp = RED(F);
       if (LENGTH(Fp) == 1) { DNFLWR(N,V,FIRST(Fp)); goto Return; }
       ADV(Fp,&F1,&Fp); DNFLWR(N,V,F1);
       while (Fp != NIL)
         { ADV(Fp,&F1,&Fp); SWRITE(" "); LGOPWR(T); SWRITE(" "); DNFLWR(N,V,F1); }
       goto Return;

Return: /* Prepare for return. */
       return;
}