-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnify.h
82 lines (50 loc) · 2.02 KB
/
Unify.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef TP_UNIFY_H
#define TP_UNIFY_H
/******** dereference a variable ********/
#define DEREFERENCE(t, c) { int i; \
while (c && t->symbol >= 0 && c->terms[i = t->symbol]) \
{ t = c->terms[i]; c = c->contexts[i]; } }
/******** bind a variable, record binding in a trail ********/
#define BIND_TR(i, c1, t2, c2, trp) { struct trail *tr; \
c1->terms[i] = t2; c1->contexts[i] = c2; \
tr = get_trail(); tr->varnum = i; tr->context = c1; \
tr->next = *trp; *trp = tr; }
/******** context -- substitution table ********/
struct context {
struct term *terms[MAX_VARS];
struct context *contexts[MAX_VARS];
int multiplier; /* needed for apply, not for unify or match */
struct term *partial_term; /* for ac matching */
};
typedef struct context *Context_ptr;
/******** trail -- to record binding, so that it can be undone ********/
struct trail {
struct trail *next;
struct context *context;
int varnum;
};
typedef struct trail *Trail_ptr;
/* function prototypes from unify.c */
Context_ptr get_context(void);
void free_context(Context_ptr p);
Trail_ptr get_trail(void);
void free_trail(Trail_ptr p);
void print_unify_mem(FILE *fp, int heading);
void p_unify_mem();
int unify(Term_ptr t1, Context_ptr c1,
Term_ptr t2, Context_ptr c2, Trail_ptr *trp);
int occur_check(int vn, Context_ptr vc, Term_ptr t, Context_ptr c);
int match(Term_ptr t1, Context_ptr c1, Term_ptr t2, Trail_ptr *trp);
Term_ptr apply(Term_ptr t, Context_ptr c);
Term_ptr apply_substitute(Term_ptr beta, Context_ptr c_from, Term_ptr t,
Term_ptr into_term, Context_ptr c_into);
Term_ptr apply_basic(Term_ptr t, Context_ptr c);
Term_ptr apply_substitute_basic(Term_ptr beta, Context_ptr c_from, Term_ptr t,
Term_ptr into_term, Context_ptr c_into);
void clear_subst_2(Trail_ptr t1, Trail_ptr t2);
void clear_subst_1(Trail_ptr t1);
void print_context(FILE *fp, Context_ptr c);
void p_context(Context_ptr c);
void print_trail(FILE *fp, Trail_ptr t);
void p_trail(Trail_ptr t);
#endif /* ! TP_UNIFY_H */