-
Notifications
You must be signed in to change notification settings - Fork 1
/
lspinf.pas
169 lines (138 loc) · 4.29 KB
/
lspinf.pas
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
(*----------------------------------------------------------------------------*)
(* Funktionen, die den Inferenzmechanismus betreffen *)
(*----------------------------------------------------------------------------*)
(* Author: Joachim Pimiskern, 1994-2004 *)
(*----------------------------------------------------------------------------*)
unit lspinf;
{$O+,F+}
interface
uses
lspglobl;
function LLspIsVariable(Args,Umgebung: pNode): pNode;
function LspIsVariable(p: pNode): boolean;
function LspMatch(Instance,Pattern,Restrictions: pNode): pNode;
function LspEvaluated(Ausdruck,Bindungen: pNode): pNode;
function LspGetVariables(Ausdruck,Bisher: pNode): pNode;
implementation
uses
lsppredi, lspmain, lspexpct, lspstrng, lspbasic, lspinit, lsplists,
lspcreat;
function LLspIsVariable(Args,Umgebung: pNode): pNode;
var e : pNode;
begin
result := nil;
e := evaluated(Args,Umgebung);
e := LspCar(e);
if (e = nil) or (e^.Typ <> cLspSymbol) then
exit;
result := BoolToNode(e^.SymbolVal^[1] = '?');
end;
function LspIsVariable(p: pNode): boolean;
begin
result := false;
if ((p = nil) or (p^.Typ <> cLspSymbol)) then
exit;
result := p^.SymbolVal^[1] = '?';
end;
function LspMatch(Instance,Pattern,Restrictions: pNode): pNode;
var temp: pNode;
begin
if ((Instance = nil) and (Pattern = nil)) then
begin
LspMatch := Restrictions;
exit;
end;
if ((Instance <> nil) and
LspIsVariable(Pattern)) then
begin
temp := LspAssoc(Pattern,Restrictions);
if (temp = nil) then
LspMatch := LspCons(LspList2(Pattern,Instance),Restrictions)
else
if (LspEqual(Instance,LspCadr(temp))) then
LspMatch := Restrictions
else
LspMatch := cLspError;
exit;
end;
if (LspAtom(Instance)) then
begin
if (not LspAtom(Pattern)) then
LspMatch := cLspError
else
if (LspIsVariable(Pattern)) then
begin
temp := LspAssoc(Pattern,Restrictions);
if (temp = nil) then
LspMatch := LspCons(LspList2(Pattern,Instance),Restrictions)
else
if LspEqual(Instance,LspCadr(temp)) then
LspMatch := Restrictions
else
LspMatch := cLspError;
end
else
begin
if LspEqual(Instance,Pattern) then
LspMatch := Restrictions
else
LspMatch := cLspError;
end;
exit;
end;
if (not LspConsp(Pattern)) then
LspMatch := cLspError
else
begin
temp := LspMatch(LspCar(Instance),LspCar(Pattern),Restrictions);
if ((temp <> nil) and (temp^.Typ = cLspSymbol)) then
LspMatch := cLspError
else
LspMatch := LspMatch(LspCdr(Instance),LspCdr(Pattern),temp);
end;
end;
function LspEvaluated(Ausdruck,Bindungen: pNode): pNode;
var temp: pNode;
begin
if (Ausdruck = nil) then
LspEvaluated := nil
else
if (LspListp(Ausdruck)) then
LspEvaluated := LspCons(LspEvaluated(LspCar(Ausdruck),Bindungen),
LspEvaluated(LspCdr(Ausdruck),Bindungen))
else
begin
temp := LspAssoc(Ausdruck,Bindungen);
if (temp <> nil) then
LspEvaluated := LspCadr(temp)
else
LspEvaluated := Ausdruck;
end;
end;
(*----------------------------------------------------------------------------*)
(* Aus einem Lisp-Ausdruck alle Variablen eindeutig liefern *)
(*----------------------------------------------------------------------------*)
function LspGetVariables(Ausdruck,Bisher: pNode): pNode;
var temp: pNode;
begin
if (Ausdruck = nil) then
result := bisher
else
if (LspIsVariable(Ausdruck)) then
begin
if (LspMember(Ausdruck,Bisher) = nil) then
result := LspCons(Ausdruck,Bisher)
else
result := Bisher;
end
else
if (LspAtom(Ausdruck)) then
result := bisher
else
begin
temp := LspGetVariables(LspCar(Ausdruck),Bisher);
result := LspGetVariables(LspCdr(Ausdruck),temp);
end;
end;
end.