Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

parser-classes.hpp

Go to the documentation of this file.
00001 #ifndef PROLOG_CLASSS_H
00002 #define PROLOG_CLASSS_H
00003 
00004 #include <vector>
00005 #include <string>
00006 #include <set>
00007 
00008 #include "stringsholder.hpp"
00009 #include "unify.hpp"
00010 #include "constraint.hpp"
00011 
00012 // T_VARIABLE should always have the lowest value
00013 
00017 enum { T_VARIABLE = 1, T_FUNCTOR = 2, T_LIST = 3 };
00018 
00022 class c_base
00023 {
00024 public:
00025 
00029    c_base();
00030 
00037    static void set_safety(const bool safe);
00038 
00042    static void delete_us();
00043 
00048    virtual void deep_delete() = 0;
00049 
00053    virtual ~c_base();
00054 
00055 private:
00056 
00060    static std::vector<c_base*> c_elements;
00061 
00065    static bool safety;
00066 };
00067 
00073 class c_term: public c_base
00074 {
00075 public:
00076 
00080    c_term();
00081 
00085    ~c_term();
00086 
00092    virtual void deep_delete();
00093 
00099    void deep_copy(c_term *copy, bool reindex = false) const;
00100       
00105    void get_variables(std::set<std::string> &vars) const;
00106 
00114    void insert_list(const std::vector<c_term*> &list,
00115                     const c_term *rest = 0,
00116                     const size_t start_index = 0);
00117 
00122    void sort_before(const c_term *t) const;
00123 
00128    void sort_same(const c_term *t) const;
00129 
00133    static int count;
00134 
00138    std::string name;
00139 
00143    std::vector<c_term*> arglist; 
00144 
00148    bool negated;
00149 
00153    c_term *list_head; 
00154 
00158    c_term *list_tail;
00159 
00163    bool list_empty;
00164 
00169    bool match_rest; 
00170 
00174    int type;
00175 
00179    mutable std::map<const c_term*, int> sorted_terms;
00180 };
00181 
00185 class n_base
00186 {
00187 public:
00188 
00192    n_base();
00193 
00197    static int count;
00198 
00202    ~n_base();
00203 
00207    static void delete_us();
00208 
00212    static std::vector<n_base*> nodes;
00213 };
00214 
00218 class n_arg: public n_base
00219 {
00220 public:
00221 
00225    n_arg();
00226 
00230    c_term *term;
00231 };
00232 
00236 class n_arglist: public n_base
00237 {
00238 public:
00239 
00243    n_arglist(const n_arg*, const n_arglist*);
00244 
00248    std::vector<c_term*> terms;
00249 };
00250 
00254 class n_functor: public n_arg
00255 {
00256 public:
00257 
00261    n_functor(const std::string, const n_arglist*);
00262 
00266    void negate();
00267 };
00268 
00272 class n_variable: public n_arg
00273 {
00274 public:
00275 
00279    n_variable(const std::string);
00280 };
00281 
00285 class n_list: public n_arg
00286 {
00287 public:
00288 
00292    n_list(const n_arglist*);
00293       
00297    n_list(const n_arglist*, const n_arg*);
00298 
00302    n_list();
00303 };
00304 
00309 class c_rule: public c_base
00310 {
00311 public:
00312 
00316    c_rule();
00317             
00321    ~c_rule();
00322 
00328    void deep_delete();
00329 
00335    void deep_copy(c_rule *copy, bool reindex = false) const;
00336 
00341    void project_constraint() const;
00342 
00347    void get_variables(std::set<std::string> &vars) const;
00348 
00353    void sort_before(const c_rule *r) const;
00354 
00359    void sort_same(const c_rule *r) const;
00360 
00365    static int global_variable_index; 
00366 
00370    static int count;
00371 
00375    c_term *head;
00376 
00381    std::vector<c_term*> body;
00382       
00386    mutable std::map<const c_rule*, int> sorted_rules;
00387 
00391    mutable con_type constraint;
00392 };
00393 
00397 class n_body: public n_base
00398 {
00399 public:
00400 
00404    n_body(const n_functor*, const n_body*);
00405 
00409    std::vector<c_term*> functors;
00410 
00415    static con_type constraint;
00416 };
00417 
00421 class n_rule: public n_base
00422 {
00423 public:
00424 
00428    n_rule(const n_functor*, const n_body*);
00429 
00433    n_rule(const n_functor*);
00434       
00438    c_rule *rule;
00439 };
00440 
00444 class n_rules: public n_base
00445 {
00446 public:
00447 
00451    n_rules(const n_rule*, const n_rules*);
00452 
00456    std::vector<c_rule*> rules;
00457 };
00458 
00462 class prolog_program
00463 { 
00464 public:
00465 
00470    prolog_program(const std::vector<c_rule*> &rs);
00471 
00475    std::vector<c_rule*> rules;
00476 };
00477 
00481 class c_sorter
00482 {
00483 public:
00484 
00496    static bool c_rule_lt(const c_rule *c1, const c_rule *c2);
00497 
00508    static bool c_term_lt(const c_term *c1, const c_term *c2);
00509 
00510 private:
00511 
00528    static int c_term_order(const c_term *c1, const c_term *c2);
00529 
00544    static int c_rule_order(const c_rule *c1, const c_rule *c2);
00545 };
00546 
00552 std::ostream &operator<<(std::ostream &os, const prolog_program *p);
00553 
00559 std::ostream &operator<<(std::ostream &os, const c_rule *r);
00560 
00566 std::ostream &operator<<(std::ostream &os, const c_term *t);
00567 
00568 
00569 #endif // PARSER_CLASSES

Generated on Mon Mar 21 00:07:37 2005 for Fixpoint Engine by  doxygen 1.3.9.1