-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoal.h
127 lines (109 loc) · 3.26 KB
/
goal.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* Copyright 2023 Slawomir Maludzinski
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef __GOAL_H__
#define __GOAL_H__
#include "var.h"
#include "term.h"
typedef struct clause clause;
typedef struct symtab symtab;
typedef struct expr expr;
typedef enum goal_type {
GOAL_TYPE_UNKNOW,
GOAL_TYPE_LITERAL,
GOAL_TYPE_UNIFICATION,
GOAL_TYPE_IS,
GOAL_TYPE_CUT,
GOAL_TYPE_FAIL,
GOAL_TYPE_BUILTIN,
GOAL_TYPE_LT,
GOAL_TYPE_GT
} goal_type;
typedef enum goal_search {
GOAL_SEARCH_NO,
GOAL_SEARCH_YES,
GOAL_SEARCH_LAST
} goal_search;
typedef struct goal_literal {
char is_last;
char * name;
term_list * terms;
clause * predicate_ref;
} goal_literal;
typedef struct goal_unification {
var * variable;
term * term_value;
} goal_unification;
typedef struct goal_is {
var * var_value;
expr * expr_value;
} goal_is;
typedef struct goal_lt {
expr * left_value;
expr * right_value;
} goal_lt;
typedef struct goal_gt {
expr * left_value;
expr * right_value;
} goal_gt;
typedef struct goal_cut {
} goal_cut;
typedef struct goal_fail {
char * name;
} goal_fail;
typedef struct goal_builtin {
unsigned int id;
} goal_builtin;
typedef struct goal {
goal_type type;
union {
goal_literal literal;
goal_unification unification;
goal_is is;
goal_cut cut;
goal_fail fail;
goal_builtin builtin;
goal_lt lt;
goal_gt gt;
};
unsigned int line_no;
struct goal * next;
} goal;
typedef struct goal_list {
goal * head;
goal ** tail;
} goal_list;
goal * goal_new_literal(char * name, term_list * terms);
goal * goal_new_unification(var * variable, term * term_value);
goal * goal_new_is(var * var_value, expr * expr_value);
goal * goal_new_cut();
goal * goal_new_fail(char * name);
goal * goal_new_builtin(unsigned int id);
goal * goal_new_lt(expr * expr_left, expr * expr_right);
goal * goal_new_gt(expr * expr_left, expr * expr_right);
void goal_delete(goal * value);
char goal_is_last(goal * value);
void goal_print(goal * value);
goal_list * goal_list_new();
void goal_list_delete(goal_list * list);
void goal_list_add_end(goal_list * list, goal * value);
void goal_list_print(goal_list * list);
#endif /* __GOAL_H__ */