예제 #1
0
static void parse_DIMACS_main(B& in, Solver& S) {
    vec<Lit> lits;
    for (;;){
        skipWhitespace(in);
        if (*in == EOF)
            break;
        else if (*in == 'c' || *in == 'p')
            skipLine(in);
        else
            readClause(in, S, lits),
            S.addClause(lits);
    }
}
예제 #2
0
파일: Dimacs.cpp 프로젝트: jjkaile/MiniSat
lbool Dimacs::parse_DIMACS_main(char* in, Solver* s) {
    for (;;){
        skipWhitespace(&in);
        if (*in == 0)
            break;
        else if (*in == 'c' || *in == 'p')
            skipLine(&in);
        else{
            vector<lit> lits = vector<lit>();
            readClause(&in, s, lits);
            Clause* c = NULL;
            if(!Clause::Clause_new(s, lits, false, c))
                return l_False;
            if(c != NULL) s->constrs.push_back(c);
        }
    }
    return s->simplifyDB();
}
예제 #3
0
static bool parse_DIMACS_main(char* in, Solver& S) {
    vec<Lit>    lits;
    for (;;){
        skipWhitespace(in);
        if (*in == 0)
            break;
        else if (*in == 'c' || *in == 'p')
            skipLine(in);
        else{
            readClause(in, S, lits);
            S.addClause(lits);
            if (!S.okay())
                return false;
        }
    }
    S.simplifyDB();
    return S.okay();
}
예제 #4
0
파일: Main.C 프로젝트: pmatos/maxsatzilla
static void parse_DIMACS_main(B& in, Solver& S) {
    vec<Lit> lits;
    for (;;){
        skipWhitespace(in);
        if (*in == EOF)
            break;
        else if (*in == 'p'){
            if (match(in, "p cnf")){
                int vars    = parseInt(in);
                int clauses = parseInt(in);
                reportf("|  Number of variables:  %-12d                                         |\n", vars);
                reportf("|  Number of clauses:    %-12d                                         |\n", clauses);
            }else{
                reportf("PARSE ERROR! Unexpected char: %c\n", *in), exit(3);
            }
        } else if (*in == 'c' || *in == 'p')
            skipLine(in);
        else
            readClause(in, S, lits),
            S.addClause(lits);
    }
}
예제 #5
0
bool PrologLoader :: LOAD (char * file_name) {
	bool ret;
	AREA command;
	ri = NULL;
	fi = NULL;
	drop_instructions ();
	if (root -> resource_loader != NULL) ri = root -> resource_loader -> load (file_name);
	if (ri == NULL) {
		fi = fopen (file_name, "rb");
		PrologString * root_directory = root -> search_directories;
		while (root_directory != NULL && fi == NULL) {
			sprintf (command, "%s%s", root_directory -> text, file_name);
			fi = fopen (command, "rb");
			root_directory = root_directory -> next;
		}
		if (fi == NULL) {
			ri = load_plugin_module (file_name);
			if (ri == 0) {message_v ("File not found: ", file_name); return false;}
		}
	}
	get_symbol ();
	PrologDirectory * import;
	clear_context ();
//	if (root != NULL) search_context = root -> root;
	PrologDirectory * user_directory = NULL;
	if (root != NULL) user_directory = root -> root;
	while (symbol_control == 11 && strcmp (root -> import_caption, symbol) == 0) {
		get_symbol ();
		switch (symbol_control) {
		case 8: if (root -> searchDirectoryNotFound (symbol)) root -> addSearchDirectory (symbol); break;
		case 11:
			import = root -> searchDirectory (symbol);
			if (import == NULL) {
				PrologLoader * loader = new PrologLoader (root);
				area_cat (command, 0, symbol);
				area_cat (command, ".prc");
				ret = loader -> load (command);
				delete loader;
				if (! ret) {message_v ("Module not loaded: ", command); close (); return false;}
				import = root -> searchDirectory (symbol);
			}
			if (import != NULL) search_context = import -> duplicate (search_context);
			break;
		default: message ("Syntax error: import module or search path expected."); close (); return false;
		}
		get_symbol ();
	}
	while (symbol_control == 31) {
		if (strcmp (symbol, "uap32") == 0) root -> set_uap32_captions ();
		if (strcmp (symbol, "standard") == 0) root -> set_standard_captions ();
		if (strcmp (symbol, "edinburg") == 0) root -> set_edinburg_captions ();
		if (strcmp (symbol, "marseille") == 0) root -> set_marseille_captions ();
		if (strcmp (symbol, "functional") == 0) root -> set_functional_captions ();
		get_symbol ();
	}
	if (symbol_control != 11 || strcmp (root -> program_caption, symbol) != 0) {message ("Syntax error: program header expected."); close (); return false;}
	get_symbol ();
	if (symbol_control != 11) {message ("Syntax error: program name expected."); close (); return false;}
	PROLOG_STRING program_name;
	prolog_string_copy (program_name, symbol);
	PrologServiceClass * service_class = NULL;
	if (reload) root -> drop (program_name);
	else if (root -> searchDirectory (program_name) != NULL) {close (); return true;}
	get_symbol ();
	PrologDirectory * directory;
	if (symbol_control == 11 && strcmp (root -> machine_caption, symbol) == 0) {
		get_symbol ();
		if (symbol_control != 11 || strcmp (root -> if_atom_caption, symbol) != 0) {
			message ("Syntax error: machine assignment expected in program header.");
			close ();
			return false;
		}
		get_symbol ();
		if (symbol_control != 8) {message ("Syntax error: service class name expected."); close (); return false;}
		service_class = root -> loadServiceClass (symbol);
		if (service_class == NULL) {message_v ("Service class crashed or not found: ", symbol); close (); return false;}
		get_symbol ();
		directory = root -> createDirectory (program_name, service_class);
	} else directory = root -> createDirectory (program_name);
	root -> auto_atoms = false;
	switch (symbol_control) {
	case 11:
		if (strcmp (root -> auto_atoms_caption, symbol) != 0) {
			message ("Syntax error: auto expected.");
			root -> drop ();
			close ();
			return false;
		}
		root -> auto_atoms = true;
		get_symbol ();
		break;
	case 6: get_symbol (); break;
	case 1:
		get_symbol ();
		while (symbol_control != 2) {
			switch (symbol_control) {
			case 11: root -> createAtom (symbol); break;
			case 21: root -> createAtom (symbol); break;
			default:
				message ("Syntax error: atom expected.");
				root -> drop ();
				close ();
				return false;
				break;
			}
			get_symbol ();
			if (strlen (root -> separator_caption) > 0) {
				if (symbol_control != 23 && symbol_control != 2) {
					message ("Syntax error: separator missing.");
					root -> drop ();
					close ();
					return false;
				}
				if (symbol_control == 23) get_symbol ();
			}
		}
		get_symbol ();
		break;
	default: message ("Syntax error: atome list expected."); root -> drop (); close (); return false;
	}
	//
	if (service_class != 0) service_class -> init (root, directory);
	if (directory != NULL) search_context = directory -> duplicate (search_context);
	PrologDirectory * dt = search_context;
	if (dt != NULL) {
		while (dt -> next != NULL) dt = dt -> next;
		dt -> next = user_directory;
	}
//	message (file_name);
//	dt = search_context;
//	while (dt != NULL) {message (dt -> directoryName); dt = dt -> next;}
//	message ("===");
//	dt = root -> root;
//	while (dt != NULL) {message (dt -> directoryName); dt = dt -> next;}
//	message ("");
	//
	PrologElement * clause = NULL;
	PrologAtom * atom = NULL;
	PrologNativeCode * native_code = NULL;
	PrologResolution * resolution = NULL;
	PrologAtom * preprocessor = NULL;
	PrologDirectory * preprocessor_directory;
	while (true) {
		switch (symbol_control) {
		case 11:
			if (strcmp (root -> machine_caption, symbol) == 0) {
				get_symbol ();
				if (symbol_control != 11) {
					message ("Syntax error: atom expected.");
					root -> drop ();
					close ();
					return false;
				}
				atom = searchAtomC (symbol); //root -> search (symbol);
				if (atom == NULL) {
					message_v ("Unknown atom: ", symbol);
					root -> drop ();
					close ();
					return false;
				}
				if (atom -> getMachine () != 0) {
					message_v ("Atom has already machine code attached: ", symbol);
					root -> drop ();
					close ();
					return false;
				}
				get_symbol ();
				if (symbol_control != 11 || strcmp (root -> if_atom_caption, symbol) != 0) {
					message ("Syntax error: machine assignment expected.");
					root -> drop ();
					close ();
					return false;
				}
				get_symbol ();
				if (symbol_control != 8) {
					message ("Syntax error: machine name expected.");
					root -> drop ();
					close ();
					return false;
				}
				if (service_class == NULL) {
					message ("Service class missing.");
					root -> drop ();
					close ();
					return false;
				}
				native_code = service_class -> getNativeCode (symbol);
				if (native_code == NULL) {
					message_v ("Unknown native class: ", symbol);
					root -> drop ();
					close ();
					return false;
				}
				atom -> setMachine (native_code);
				get_symbol ();
				break;
			}
//		case 11:
			if (strcmp (root -> end_caption, symbol) == 0) {
				get_symbol ();
				clause = NULL;
				if (symbol_control == 11 && strcmp (root -> if_atom_caption, symbol) == 0) {
					clause = readElement ();
					if (clause == NULL) {
						// suspiciouse drop 1
						root -> drop ();
						close ();
						return false;
					}
					get_symbol ();
				}
				if (symbol_control == 21) {
					if (echo) message ("");
					root -> close ();
					if (clause != 0) instructions = clause;
					close ();
					return true;
				}
				message ("Syntax error: dot expected.");
				root -> drop ();
				close ();
				return false;
			}
			if (strcmp (root -> protect_caption, symbol) == 0) {
				get_symbol ();
				if (symbol_control == 6) {get_symbol (); break;}
				if (symbol_control != 1) {
					message ("Syntax error: atome list expected.");
					root -> drop ();
					close ();
					return false;
				}
				get_symbol ();
				while (symbol_control != 2) {
					if (symbol_control != 11) {
						message ("Syntax error: atom expected.");
						root -> drop ();
						close ();
						return false;
					}
					if (! root -> Protect (symbol)) {
						root -> message ("Can not protect unknown atom:", symbol);
						root -> drop ();
						close ();
						return false;
					}
					get_symbol ();
					if (strlen (root -> separator_caption) > 0) {
						if (symbol_control != 23 && symbol_control != 2) {
							message ("Syntax error: separator missing.");
							root -> drop ();
							close ();
							return false;
						}
						if (symbol_control == 23) get_symbol ();
					}
				}
				get_symbol ();
				break;
			}
			if (strcmp (root -> private_caption, symbol) == 0) {
				get_symbol ();
				if (symbol_control == 6) {get_symbol (); break;}
				if (symbol_control != 1) {
					message ("Syntax error: atome list expected.");
					root -> drop ();
					close ();
					return false;
				}
				get_symbol ();
				while (symbol_control != 2) {
					if (symbol_control != 11) {
						message ("Syntax error: atom expected.");
						root -> drop ();
						close ();
						return false;
					}
					if (! root -> Private (symbol)) {
						root -> message ("Can not lock unknown atom as private:", symbol);
						root -> drop ();
						close ();
						return false;
					}
					get_symbol ();
					if (strlen (root -> separator_caption) > 0) {
						if (symbol_control != 23 && symbol_control != 2) {
							message ("Syntax error: separator missing.");
							root -> drop ();
							close ();
							return false;
						}
						if (symbol_control == 23) get_symbol ();
					}
				}
				get_symbol ();
				break;
			}
			if (strcmp (root -> preprocessor_caption, symbol) == 0) {
				get_symbol ();
				if (symbol_control != 11 && strcmp (root -> if_atom_caption, symbol) != 0) {
					message ("Syntax error: preprocessor assignment expected.");
					root -> drop ();
					close ();
					return false;
				}
				get_symbol ();
				if (symbol_control == 6) {
//					directory -> setPreprocessor (NULL);
					preprocessor = NULL;
					get_symbol ();
					break;
				}
				if (symbol_control != 11) {
					if (symbol_control == 22) {
						get_symbol ();
						if (symbol_control != 11) {
							message ("Syntax error: directory name expected in qualified preprocessor name.");
							root -> drop ();
							close ();
							return false;
						}
						preprocessor_directory = root -> searchDirectory (symbol);
						if (preprocessor_directory == NULL) {
							message_v ("Directory not found in qualified preprocessor name:", symbol);
							root -> drop ();
							close ();
							return false;
						}
						get_symbol ();
						if (symbol_control != 21) {
							message ("Syntax error: dot expected in qualified preprocessor name.");
							root -> drop ();
							close ();
							return false;
						}
						get_symbol ();
						if (symbol_control != 11) {
							message ("Syntax error: qualified preprocessor name expected.");
							root -> drop ();
							close ();
							return false;
						}
						atom = preprocessor_directory -> searchAtom (symbol);
					} else {
						message ("Syntax error: atom expected.");
						root -> drop ();
						close ();
						return false;
					}
				} else {
					atom = searchAtom (symbol); //root -> search (symbol);
				}
				if (atom == NULL) {
					message_v ("Unknown atom: ", symbol);
					root -> drop ();
					close ();
					return false;
				}
//				directory -> setPreprocessor (atom);
				preprocessor = atom;
				get_symbol ();
				break;
			}
			if (strcmp (root -> auto_caption, symbol) == 0) {
				get_symbol ();
				if (symbol_control != 11 && strcmp (root -> if_atom_caption, symbol) != 0) {
					message ("Syntax error: auto assignment expected.");
					root -> drop ();
					close ();
					return false;
				}
				clause = readElement ();
				// suspicious drop 2
				if (clause == NULL) {root -> drop (); close (); return false;}
				clause = root -> pair (root -> head (NULL), clause);
				//root -> resolution (clause);
				resolution = new PrologResolution (root);
				resolution -> resolution (clause);
				delete resolution;
				delete clause;
				get_symbol ();
				break;
			}
		case 1:
//			atom = root -> getPreprocessor ();
			if (preprocessor != NULL) {
				clause = readElement ();
				if (clause == NULL) {root -> drop (); close (); return false;}
				clause = readRightSide (clause, false);
				if (clause == NULL) {root -> drop (); close (); return false;}
				get_symbol ();
				clause = root -> pair (root -> var (0), root -> pair (root -> pair (root -> atom (preprocessor), root -> pair (clause, root -> earth ())), root -> earth ()));
				resolution = new PrologResolution (root);
				resolution -> resolution (clause);
				delete resolution;
				delete clause;
				break;
			}
			clause = readClause ();
			get_symbol ();
			// suspicious drop 3
			if (clause == NULL) {root -> drop (); close (); return false;}
			if (root -> attachClause (clause) == 0) break;
			// suspicious drop 4
			root -> drop ();
			close ();
			return false;
		default: message ("Syntax error: at least clause expected."); root -> drop (); close (); return false;
		}
	}
}