#include <clause.hpp>
Public Methods | |
| Clause () | |
| Clause (const char *str0) | |
| virtual | ~Clause () |
| Clause (clause_t src) | |
| const Clause & | operator= (const Clause &src) |
| Clause (const Clause &src) | |
| const Clause & | Clause::operator= (clause_t src) |
| void | print () |
| void | assign (const char *str0) |
| void | decompose () |
| void | compose () |
| clause_t | compare (const Clause &src) |
Private Attributes | |
| clause_t | data |
|
|
Definition at line 6 of file clause.cpp. 00007 {
00008 memset( &data, 0, sizeof( clause_t ) );
00009 }
|
|
|
Definition at line 33 of file clause.cpp. |
|
|
Definition at line 63 of file clause.cpp. 00064 {
00065 }
|
|
|
Definition at line 11 of file clause.cpp. 00012 {
00013 memcpy( &data, &src, sizeof( clause_t ) );
00014 }
|
|
|
Definition at line 16 of file clause.cpp. |
|
|
|
|
|
Definition at line 50 of file clause.cpp. Referenced by Clause(), and compose().
|
|
|
Definition at line 176 of file clause.cpp. Referenced by main().
00177 {
00178 clause_t temp;
00179
00180 memset( &temp, 0, sizeof( clause_t ) );
00181
00182 register int i = 0;
00183 register int opposite = 0;
00184
00185 for( ; i < 26; i++ )
00186 {
00187 register char ch = (char)( i + 'A' );
00188 // Same letter
00189 if ( data.logic.letters[ i ] == src.data.logic.letters[ i ] && data.logic.letters[ i ] > 0 )
00190 {
00191 // Different by sign P vs ~P
00192 if ( data.logic.negated[ i ] != src.data.logic.negated[ i ] )
00193 {
00194 printf( "Same [%c] but different sign \n", ch );
00195 opposite++;
00196 }
00197 else
00198 {
00199 printf( "Same [%c] with same sign \n", ch );
00200 temp.logic.letters[ i ] = data.logic.letters[ i ];
00201 temp.logic.negated[ i ] = data.logic.negated[ i ];
00202 temp.logic.variables[ temp.logic.nbVariables++ ] = ch;
00203 }
00204 }
00205 else if ( ( data.logic.letters[ i ] | src.data.logic.letters[ i ] ) > 0 )
00206 {
00207 printf( "Different letter [%c] \n", ch );
00208 temp.logic.letters[ i ] = 1; // Different so one of them exist
00209 temp.logic.negated[ i ] = data.logic.negated[ i ] | src.data.logic.negated[ i ];
00210 temp.logic.variables[ temp.logic.nbVariables++ ] = ch;
00211 }
00212
00213 // Different by at least two letters
00214 if ( opposite > 1 )
00215 {
00216 memset( &temp, 0, sizeof( clause_t ) );
00217 temp.status = C_invalid;
00218 printf( "Opposite by more than 1 \n" );
00219 return temp;
00220 }
00221 }
00222
00223 // Different by exactly one letter
00224 if ( opposite == 1 )
00225 {
00226 // Undefined but valid.
00227 printf( "Opposite by 1 \n" );
00228 return temp;
00229 }
00230 else
00231 {
00232 printf( "Opposite not by 1 \n" );
00233 memset( &temp, 0, sizeof( clause_t ) );
00234 temp.status = C_invalid;
00235 return temp;
00236 }
00237 }
|
|
|
Definition at line 122 of file clause.cpp. Referenced by print().
00123 {
00124 if ( data.status != C_undefined )
00125 {
00126 if ( data.status == C_true )
00127 {
00128 printf( "True" );
00129 assign( "True" );
00130 return;
00131 }
00132 else if ( data.status == C_false )
00133 {
00134 printf( "False" );
00135 assign( "False" );
00136 return;
00137 }
00138 else if ( data.status == C_nil )
00139 {
00140 printf( "Nil" );
00141 assign( "Nil" );
00142 return;
00143 }
00144 }
00145
00146 char buffer[ 160 ];
00147 memset( buffer, 0, 160 );
00148
00149 register int pos = 0;
00150 register int i = 0;
00151
00152 printf( "compose \n" );
00153
00154 for( ; i < data.logic.nbVariables; i++ )
00155 {
00156 if ( pos > 0 )
00157 {
00158 buffer[ pos++ ] = ' ';
00159 buffer[ pos++ ] = 'v';
00160 buffer[ pos++ ] = ' ';
00161 }
00162
00163 register char ch = data.logic.variables[ i ];
00164 if ( data.logic.negated[ ch - 'A' ] == 1 )
00165 {
00166 buffer[ pos++ ] = '~';
00167 }
00168 buffer[ pos++ ] = ch;
00169 }
00170
00171 buffer[ pos++ ] = '\0';
00172
00173 assign( buffer );
00174 }
|
|
|
Definition at line 67 of file clause.cpp. Referenced by Clause().
00068 {
00069 if ( data.string == NULL ) return;
00070
00071 // Clear logic buffer
00072 memset( &data.logic, 0, sizeof( logic_t ) );
00073
00074 register size_t i = 0;
00075 register char neg = 0;
00076 for( ; i < data.len; i++ )
00077 {
00078 register char ch = data.string[ i ];
00079
00080 if ( ch == 'v' )
00081 {
00082 neg = 0;
00083 continue;
00084 }
00085
00086 if ( ch == '~' )
00087 {
00088 neg = 1 - neg; // Negate the neg variable
00089 continue;
00090 }
00091
00092 if ( ch >= 'a' && ch <= 'z' ) // to Upper Case
00093 {
00094 ch = ch - 'a' + 'A';
00095 }
00096
00097 if ( ch >= 'A' && ch <= 'Z' ) // store
00098 {
00099 register char index = ch - 'A';
00100
00101 if ( data.logic.letters[ index ] > 0 ) // Variable already parsed.
00102 {
00103 if ( data.logic.negated[ index ] != neg )
00104 {
00105 data.status = C_true; // P v ~P = TRUE
00106 break;
00107 }
00108 else // P v P = P Noop
00109 {
00110 }
00111 }
00112 else
00113 {
00114 data.logic.letters[ index ] = 1;
00115 data.logic.negated[ index ] = neg;
00116 data.logic.variables[ data.logic.nbVariables++ ] = ch;
00117 }
00118 }
00119 }
00120 }
|
|
|
Definition at line 21 of file clause.cpp. |
|
|
Definition at line 42 of file clause.cpp. Referenced by main().
|
|
|
Definition at line 42 of file clause.hpp. Referenced by Clause(), compare(), and operator=().
|
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001