-
Notifications
You must be signed in to change notification settings - Fork 1
/
lsppars.pas
218 lines (204 loc) · 8.47 KB
/
lsppars.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
(*----------------------------------------------------------------------------*)
(* Author: Joachim Pimiskern, 1994-2004 *)
(*----------------------------------------------------------------------------*)
unit lsppars;
{$O+,F+}
interface
uses
lspglobl, lsplex;
function getExpression(pLex: pLex_obj): pNode;
implementation
uses
lspbasic, lspcreat, lsplists, lsperr, lspinout, lsparray, lspinit;
function getExpression(pLex: pLex_obj): pNode;
var CollectList,h,tempArray,laeufer,letzterKnoten,temp: pNode;
i,count: longint;
Abbruch: boolean;
begin
case pLex^.Lookahead.Token of
(********************************************************************)
cLspNilToken:
begin
getExpression := nil;
pLex^.consume(pLex^.Lookahead);
end;
(********************************************************************)
cLspSymbolToken:
begin
getExpression := LspMakeSymbol(pLex^.Lookahead.TokenValString);
pLex^.consume(pLex^.Lookahead);
end;
(********************************************************************)
cLspStringToken:
begin
getExpression := LspMakeString(pLex^.Lookahead.TokenValString);
pLex^.consume(pLex^.Lookahead);
end;
(********************************************************************)
cLspIntegerToken:
begin
getExpression := LspMakeInteger(pLex^.Lookahead.TokenValLongint);
pLex^.consume(pLex^.Lookahead);
end;
(********************************************************************)
cLspFloatToken:
begin
getExpression := LspMakeFloat(pLex^.Lookahead.TokenValDouble);
pLex^.consume(pLex^.Lookahead);
end;
(********************************************************************)
cLspKlammerZuToken:
begin
getExpression := cLspKlammerZu;
pLex^.consume(pLex^.Lookahead);
end;
(********************************************************************)
cLspEndOfFileToken:
begin
getExpression := cLspEndOfFile;
pLex^.consume(pLex^.Lookahead);
end;
(********************************************************************)
(*
cLspEndOfLineToken:
begin
getExpression := cLspEndOfLine;
pLex^.consume(pLex^.Lookahead);
end;
*)
(********************************************************************)
cLspKlammerAufToken:
begin
pLex^.consume(pLex^.Lookahead); { '(' konsumieren }
(*--- In Collectlist wird die nun kommende Liste gesammelt ---*)
CollectList := nil;
LetzterKnoten := nil;
Abbruch := false;
(*--- Solange sammeln, bis Abschluss mittels Klammer kommt ---*)
while ((not Abbruch) and
(pLex^.Lookahead.Token <> cLspKlammerZuToken)) do
begin
(*--- Punktpaar ? ---*)
if (pLex^.Lookahead.Token = cLspPunktToken) then
begin
(*--- Wurde Punkt zu frueh eingegeben ? ---*)
if (CollectList = nil) then
raise ELispException.Create('ErrWrongDottedPair','')
else
begin
pLex^.consume(pLex^.Lookahead);
LspRplacd(LetzterKnoten,getExpression(pLex));
end;
end
else
begin
temp := getExpression(pLex);
h := LspCons(temp,nil);
if ((temp = cLspKlammerZu) or
(temp = cLspEndOfFile)) then
Abbruch := true
else
if (temp <> cLspEndOfLine) then
begin
if (CollectList = nil) then
CollectList := h
else
LspRplacd(letzterKnoten,h);
letzterKnoten := h;
end;
end;
end;
if (not Abbruch) then
pLex^.consume(pLex^.Lookahead);
getExpression := CollectList;
end;
(********************************************************************)
cLspArrayToken:
begin
pLex^.consume(pLex^.Lookahead); { '#(' konsumieren }
(*--- In Collectlist wird die nun kommende Liste gesammelt ---*)
CollectList := nil;
LetzterKnoten := nil;
(*--- Solange sammeln, bis Abschluss mittels Klammer kommt ---*)
Count := 0;
while (pLex^.Lookahead.Token <> cLspKlammerZuToken) do
begin
(*--- Punktpaar ? ---*)
if (pLex^.Lookahead.Token = cLspPunktToken) then
begin
(*--- Wurde Punkt zu frueh eingegeben ? ---*)
if (CollectList = nil) then
raise ELispException.Create('ErrWrongDottedPair','')
else
begin
pLex^.consume(pLex^.Lookahead);
LspRplacd(LetzterKnoten,getExpression(pLex));
end;
end
else
begin
inc(Count);
h := LspCons(getExpression(pLex),nil);
if (CollectList = nil) then
CollectList := h
else
LspRplacd(LetzterKnoten,h);
letzterKnoten := h;
end;
end;
pLex^.consume(pLex^.Lookahead);
(*----------------------------*)
(* Liste nun in Array wandeln *)
(*----------------------------*)
tempArray := LspMakeArray(LspLength(CollectList));
laeufer := CollectList;
for i := 0 to Count - 1 do
begin
writeln('Fehler');
(*
tLispArray(tempArray^.ArrayVal^)[i] := LspCar(laeufer);
*)
laeufer := LspCdr(laeufer);
end;
getExpression := tempArray;
end;
(********************************************************************)
cLspQuoteToken:
begin
pLex^.consume(pLex^.Lookahead);
getExpression := LspCons(LspMakeSymbol('quote'),LspCons(getExpression(pLex),nil));
end;
(********************************************************************)
cLspBackQuoteToken:
begin
pLex^.consume(pLex^.Lookahead);
getExpression := LspCons(LspMakeSymbol('backquote'),LspCons(getExpression(pLex),nil));
end;
(********************************************************************)
cLspCommaToken:
begin
pLex^.consume(pLex^.Lookahead);
getExpression := LspCons(LspMakeSymbol('comma'),LspCons(getExpression(pLex),nil));
end;
(********************************************************************)
cLspCommaAtToken:
begin
pLex^.consume(pLex^.Lookahead);
getExpression := LspCons(LspMakeSymbol('comma-at'),LspCons(getExpression(pLex),nil));
end;
(********************************************************************)
cLspEndOfLineToken:
begin
pLex^.consume(pLex^.Lookahead);
getExpression := getExpression(pLex); (*--- rekursives Weiterlesen ---*)
end;
(********************************************************************)
else
begin
pLex^.consume(pLex^.Lookahead);
raise ELispException.Create('ErrUnexpectedToken','')
end;
end;
end;
end.