Repository navigation
Expand file tree
/
Copy pathparser.pas
More file actions
5115 lines (4749 loc) · 130 KB
/
Copy pathparser.pas
File metadata and controls
5115 lines (4749 loc) · 130 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{$optimize 7}
{------------------------------------------------------------}
{ }
{ ORCA/Pascal 2 }
{ }
{ A native code compiler for the Apple IIGS. }
{ }
{ By Mike Westerfield }
{ }
{ Copyright March 1988 }
{ By the Byte Works, Inc. }
{ }
{------------------------------------------------------------}
unit parser;
interface
{$segment 'pascal'}
{$LibPrefix '0/obj/'}
uses PCommon, Scanner, CGI, Symbols, Call;
var
{structured constants:}
{---------------------}
blockbegsys: setofsys; {symbols that can start a block}
statbegsys: setofsys;
{------------------------------------------------------------}
procedure DoConstant (fsys: setofsys; var fsp: stp; var fvalu: valu);
{ compile a constant term }
{ }
{ parameters: }
{ fsys - following symbols }
{ fsp - (output) constant type }
{ fvalu - (output) constant value }
procedure Expression(fsys: setofsys; fprocp: ctp);
{compile an expression}
procedure InitScalars;
{Initialize global scalars}
procedure InitSets;
{initialize structured set constants}
procedure Selector (fsys: setofsys; fcp,fprocp: ctp; var isMethod: boolean);
{ handle indexing arrays, field selection, dereferencing of }
{ pointers, windowing files }
{ }
{ parameters: }
{ fsys - }
{ fcp - }
{ fprocp - identifier for program or program-level }
{ subroutine contining this statement }
{ isMethod - (returned) Did the selection resolve to a }
{ method call? If so, take no further action. }
procedure Programme(fsys:setofsys);
{Compile a program}
{------------------------------------------------------------}
implementation
const
digmax = 255; {maxcnt-1}
workspace = 16; {# bytes of work space on stack frame}
{-------------------------------------------------------------------------}
type
{case statement}
{--------------}
cip = ^caseinfo;
caseinfo = packed record
next: cip;
csstart: unsigned;
cslab: integer;
end;
var
{counters:}
{---------}
lastline: integer; {last line seen by gen}
firstlab: integer; {value for intlabel at start of segment}
{switches:}
{---------}
inseg: boolean; {tells if a segment is active}
inUses: boolean; {tells if a uses is being compiled}
doingCast: boolean; {casting a type?}
{pointers:}
{---------}
fextfilep: extfilep; {head of chain for external files}
thisType: pStringPtr; {pointer to name of current type}
{msc}
{---}
namFound: boolean; {has nam been found? {i.e., should line
#'s be generated?}
{objects}
{-------}
isMethod: boolean; {are we compiling a method?}
objectcp: ctp; {last procedure or function identifier}
objectName: pString; {object name (for methods)}
objectType: stp; {type of method's object}
objptr: ctp; {linked list of objects}
{structured constants:}
{---------------------}
constbegsys,simptypebegsys,typebegsys,selectsys,facbegsys,
typedels: setofsys;
inputid,outputid,erroroutputid: pString; {commonly compared identifiers}
{----Parser and Semantic Analysis-----------------------------------------}
procedure DoConstant {fsys: setofsys; var fsp: stp; var fvalu: valu};
{ compile a constant term }
{ }
{ parameters: }
{ fsys - following symbols }
{ fsp - (output) constant type }
{ fvalu - (output) constant value }
var
lsp: stp;
lcp: ctp;
sign: (none,pos,neg);
lvp: csp;
begin {DoConstant}
lsp := nil;
fvalu.ival := 0;
if not(sy in constbegsys) then begin
Error(22);
Skip(fsys+constbegsys)
end; {if}
if sy in constbegsys then begin
if sy = stringconst then begin
if (sy = addop) and (op in [plus,minus]) then begin
Error(34);
InSymbol;
end; {if}
if lgth = 1 then
lsp := charptr
else begin
lsp := pointer(Malloc(sizeof(structure)));
with lsp^ do begin
aeltype := charptr;
inxtype := nil;
ispacked := pkpacked;
hasSFile := false;
size := lgth*packedcharsize;
form := arrays;
end; {with}
end; {else}
fvalu := val;
InSymbol;
end
else begin
sign := none;
if (sy = addop) and (op in [plus,minus]) then begin
if op = plus then sign := pos else sign := neg;
InSymbol;
end; {if}
if sy = ident then begin
searchid([konst],lcp);
if lcp <> nil then
with lcp^ do begin
lsp := idtype;
fvalu := values;
end {with}
else begin
fvalu.ival := 0;
lsp := intptr;
end; {else}
if sign = neg then
if (lsp = intptr) or (lsp = byteptr) then
fvalu.ival := -fvalu.ival
else if lsp = longptr then begin
lvp := pointer(Malloc(constantRec_longC));
lvp^.cclass := longC;
lvp^.lval := -fvalu.valp^.lval;
fvalu.valp := lvp;
end {else if}
else if IsReal(lsp) then begin
lvp := pointer(Malloc(constantRec_reel));
lvp^.cclass := reel;
lvp^.rval := -fvalu.valp^.rval;
fvalu.valp := lvp;
end; {else if}
if sign <> none then
if (lsp <> intptr) and (not IsReal(lsp)) and
(lsp <> byteptr) and (lsp <> longptr) then
Error(34);
InSymbol;
end {if}
else if sy = intconst then begin
if sign = neg then
val.ival := -val.ival;
lsp := intptr;
fvalu := val;
InSymbol;
end {else if}
else if sy = realconst then begin
if sign = neg then
val.valp^.rval := -val.valp^.rval;
lsp := realptr;
fvalu := val;
InSymbol;
end {else if}
else if sy = longintconst then begin
if sign = neg then
val.valp^.lval := -val.valp^.lval;
lsp := longptr;
fvalu := val;
InSymbol;
end {else if}
else begin
Error(35);
Skip(fsys);
end {else if}
end; {else}
if not (sy in fsys) then begin
Error(6);
Skip(fsys);
end; {if}
end; {if}
fsp := lsp;
end; {DoConstant}
procedure CheckUses(var id: pString; sym: symbol);
{make sure this name has not been used from another level}
label 1;
var
p: lptr; {work pointer for traversing list}
lcp: ctp; {work pointer for checking fwd ptrs}
begin {CheckUses}
p := display[top].labsused;
while p <> nil do begin
if CompNames(p^.name^,id) = 0 then begin
Error(18);
goto 1;
end;
p := p^.next;
end;
if sym <> typesy then begin
lcp := fwptr;
while lcp <> nil do begin
if CompNames(lcp^.name^,id) = 0 then begin
Error(18);
goto 1;
end;
lcp := lcp^.next;
end;
end;
1:
end; {CheckUses}
procedure ExportUses;
{uses from more than one level back are exported to the previous level}
label 1;
var
p,q,r: lPtr; {for moveing used id list up}
begin {ExportUses}
p := display[top].labsused; {check all labels in curent list}
while p <> nil do begin
if p^.disx < top-1 then begin {if they are from more than one level }
q := display[top-1].labsused; { back, they must be in the last list }
while q <> nil do begin {skip if the label is already in the }
if q^.name = p^.name then { last list }
goto 1;
q := q^.next;
end; {while}
new(r); {insert in the last list}
r^.next := display[top-1].labsused;
display[top-1].labsused := r;
r^.name := p^.name;
r^.disx := p^.disx;
end; {if}
p := p^.next;
end; {while}
1:
end; {ExportUses}
procedure ProcDeclaration (fsy: symbol; fsys: setofsys;
isObject, compilebody: boolean; var foundbody: boolean); forward;
{ Procedure/function declaration }
procedure Typ (fsys: setofsys; var fsp: stp; var fsize: addrrange;
isType: boolean);
{ compile a type definition }
{ }
{ parameters: }
{ fsys - follow symbols }
{ fsp - }
{ fsize - }
{ isType - is this the root level of a type declaration? }
var
lsp,lsp1,lsp2: stp;
oldtop: disprange; {display level on entry}
ttop: disprange; {temp display level}
lcp, lcp2: ctp;
lsize,disp1: addrrange;
lmin,lmax: longint;
ispacked: packedkinds;
test: boolean;
lvalu: valu;
len: integer; {string length}
l1,l2,l3: longint; {used to compute array size}
lval: record {used to convert between types}
case boolean of
true : (long: longint);
false: (lsw: integer; msw: integer);
end;
procedure Duplicate (var ncp: ctp; ocp: ctp);
{ Duplicate a field list }
{ }
{ parameters: }
{ ncp - (output) new (copied) identifier }
{ ocp - identifier to copy }
begin {Duplicate}
if ocp <> nil then begin
ncp := pointer(Malloc(sizeof(identifier)));
ncp^ := ocp^;
Duplicate(ncp^.llink, ocp^.llink);
Duplicate(ncp^.rlink, ocp^.rlink);
end; {if}
end; {Duplicate}
procedure SimpleType (fsys:setofsys; var fsp:stp; var fsize:addrrange);
{ Compile a simple type }
{ }
{ parameters: }
{ fsys - }
{ fsp - }
{ fsize - }
var
lsp,lsp1: stp;
lcp,lcp1: ctp;
ttop: disprange;
lcnt: integer;
lvalu: valu;
len: integer; {string length}
begin {SimpleType}
fsize := 1;
if not (sy in simptypebegsys) then begin
Error(1);
Skip(fsys + simptypebegsys);
end; {if}
if sy in simptypebegsys then begin
{enumerations}
if sy = lparent then begin
ttop := top; {decl. consts local to innermost block}
while display[top].occur <> blck do
top := top - 1;
lsp := pointer(Malloc(sizeof(structure)));
with lsp^ do begin
size := intsize;
form := scalar;
hasSFile := false;
scalkind := declared;
end; {with}
lcp1 := nil;
lcnt := 0;
repeat
InSymbol;
if sy = ident then begin
lcp := pointer(Malloc(sizeof(identifier)));
with lcp^ do begin
len := ord(id[0])+2;
name := pointer(Malloc(len));
CopyString(name^,id,len);
idtype := lsp;
next := lcp1;
values.ival := lcnt;
klass := konst;
hasIFile := idtype^.hasSFile;
end;
CheckUses(lcp^.name^,constsy);
EnterId(lcp);
lcnt := lcnt + 1;
lcp1 := lcp; InSymbol
end
else Error(2);
if not (sy in fsys + [comma,rparent]) then begin
Error(6);
Skip(fsys + [comma,rparent]);
end;
until sy <> comma;
lsp^.fconst := lcp1;
top := ttop;
Match(rparent,4);
end
{named types, subranges}
else begin
if sy = ident then begin
SearchID([types,konst],lcp);
if lcp^.name = thisType then
Error(10);
InSymbol;
if lcp^.klass = konst then begin
lsp := pointer(Malloc(sizeof(structure)));
with lsp^, lcp^ do begin
rangetype := idtype;
form := subrange;
hasSFile := false;
if rangetype = longptr then begin
min := values.valp^.lval;
size := longsize;
end {if}
else begin
min := values.ival;
size := intsize;
end; {else}
end;
Match(dotdot,83);
DoConstant(fsys,lsp1,lvalu);
if lsp1 = longptr then
lsp^.max := lvalu.valp^.lval
else
lsp^.max := lvalu.ival;
if lsp^.rangetype <> lsp1 then
if (lsp^.rangetype = intptr) and (lsp1 = longptr) then begin
lsp^.rangetype := longptr;
lsp^.size := longsize;
end {if}
else if (lsp^.rangetype <> longptr) or (lsp1 <> intptr) then
Error(36);
end
else begin
lsp := lcp^.idtype;
if lsp <> nil then fsize := lsp^.size;
if iso then
if (lsp = longptr) or (lsp = byteptr) then Error(112);
end
end {sy = ident}
else begin
lsp := pointer(Malloc(sizeof(structure)));
DoConstant(fsys + [dotdot],lsp1,lvalu);
with lsp^ do begin
form := subrange;
hasSFile := false;
rangetype:=lsp1;
if rangetype = longptr then begin
min := lvalu.valp^.lval;
size := longsize;
end {if}
else begin
min := lvalu.ival;
size := intsize;
end; {else}
end;
Match(dotdot,83);
DoConstant(fsys,lsp1,lvalu);
if lsp1 = longptr then
lsp^.max := lvalu.valp^.lval
else
lsp^.max := lvalu.ival;
if lsp^.rangetype <> lsp1 then
if (lsp^.rangetype = intptr) and (lsp1 = longptr) then begin
lsp^.rangetype := longptr;
lsp^.size := longsize;
end {if}
else if (lsp^.rangetype <> longptr) or (lsp1 <> intptr) then
Error(36);
end;
if lsp <> nil then
with lsp^ do
if form = subrange then
if rangetype <> nil then
if IsReal(rangetype) or IsString(rangetype) then
Error(73)
else if min > max then
Error(31)
end;
fsp := lsp;
if not (sy in fsys) then begin
Error(6);
Skip(fsys)
end; {if}
end
else fsp := nil
end; {SimpleType}
procedure FieldList (fsys: setofsys; var frecvar: stp; var hasFile: boolean;
isObject: boolean);
{ compile a field list }
{ }
{ parameters: }
{ fsys - following symbols }
{ frecvar - }
{ hasFile - }
{ isObject - is this an object? (or a record) }
label 1;
var
lcp,lcp1,nxt,nxt1,inst: ctp;
lsp,lsp1,lsp2,lsp3,lsp4: stp;
minsize,maxsize,lsize: addrrange;
lvalu: valu;
numcase: longint;
max,min: longint;
tHasFile: boolean; {tracks files in the field list}
len: integer; {length of a string}
hasId: boolean; {does the case have an attached id?}
begin {FieldList}
lsp := nil;
hasFile := false;
if not (sy in fsys+[ident,casesy]) then begin
Error(19);
Skip(fsys + [ident,casesy]);
end;
while sy = ident do begin
nxt := nil;
nxt1 := nil;
repeat
if sy = ident then begin
lcp := pointer(Malloc(sizeof(identifier)));
with lcp^ do begin
len := ord(id[0])+2;
name := pointer(Malloc(len));
CopyString(name^,id,len);
idtype := nil;
next := nil;
klass := field;
fldvar := false;
hasIFile := false;
end;
if nxt1 <> nil then
nxt1^.next := lcp;
nxt1 := lcp;
if nxt = nil then
nxt := lcp;
EnterId(lcp);
InSymbol;
end
else Error(2);
if not (sy in [comma,colon]) then begin
Error(6);
Skip(fsys + [comma,colon,semicolon,casesy])
end; {if}
test := sy <> comma;
if not test then InSymbol;
until test;
Match(colon,5);
Typ(fsys + [casesy,semicolon], lsp, lsize, false);
hasFile := hasFile or lsp^.hasSFile;
while nxt <> nil do
with nxt^ do begin
idtype := lsp;
fldaddr := disp1;
nxt := next;
disp1 := disp1 + lsize;
end;
while sy = semicolon do begin
InSymbol;
if not (sy in fsys + [ident,casesy,semicolon]) then begin
Error(19);
Skip(fsys + [ident,casesy]);
end;
end;
end; {while sy = ident}
if sy = casesy then begin
if isObject then
Error(123);
hasId := false;
lsp := pointer(Malloc(sizeof(structure)));
with lsp^ do begin
tagfieldp := nil;
fstvar := nil;
form := tagfld;
hasSFile := false;
end;
frecvar := lsp;
InSymbol;
if sy = ident then begin
lcp := pointer(Malloc(sizeof(identifier)));
with lcp^ do begin
len := ord(id[0])+2;
name := pointer(Malloc(len));
CopyString(name^,id,len);
idtype := nil;
klass:=field;
next := nil;
fldaddr := disp1;
fldvar := true;
hasIFile := false;
end;
InSymbol;
if sy = colon then begin
InSymbol;
hasId := true;
if sy <> ident then begin
Error(2);
Skip(fsys + [ofsy,lparent]);
goto 1;
end; {if sy <> ident}
EnterId(lcp);
end
else begin
id := lcp^.name^;
if sy <> ofsy then Error(8);
end;
SearchID([types], lcp1);
lsp1 := lcp1^.idtype;
if lsp1 <> nil then begin
lcp^.fldaddr := disp1;
if hasId then
disp1 := disp1+lsp1^.size;
if lsp1^.form <= subrange then begin
if IsReal(lsp1) then
Error(39)
else if (lsp1 = intptr) or (lsp1 = longptr) then begin
Error(111);
numcase := maxint;
end
else begin
GetBounds(lsp1,min,max);
if (max >= 0) and (min <= 0) then
if max < (maxint+min) then
numcase := max-min+1
else begin
Error(111);
numcase := maxint;
end
else
numcase := max-min+1
end;
lcp^.idtype := lsp1;
lsp^.tagfieldp := lcp;
end
else
Error(39);
end;
if sy = ident then InSymbol;
end
else begin
Error(2);
Skip(fsys + [ofsy,lparent]);
end;
1: lsp^.size := disp1;
Match(ofsy,8);
lsp1 := nil;
minsize := disp1;
maxsize := disp1;
repeat
lsp2 := nil;
if not (sy in fsys + [semicolon]) then begin
repeat
DoConstant(fsys + [comma,colon,lparent],lsp3,lvalu);
if lsp^.tagfieldp <> nil then
if not CompTypes(lsp^.tagfieldp^.idtype,lsp3) then
Error(40);
lsp3 := pointer(Malloc(sizeof(structure)));
numcase := numcase-1;
with lsp3^ do begin
nxtvar := lsp1;
subvar := lsp2;
varval := lvalu.ival;
form := variant;
hasSFile := false;
end;
lsp4 := lsp1;
while lsp4 <> nil do
with lsp4^ do begin
if varval = lvalu.ival then Error(94);
lsp4 := nxtvar;
end;
lsp1 := lsp3;
lsp2 := lsp3;
test := sy <> comma;
if not test then InSymbol;
until test;
Match(colon,5);
Match(lparent,9);
FieldList(fsys + [rparent, semicolon], lsp2, tHasFile, false);
hasFile := hasFile or tHasFile;
if disp1 > maxsize then maxsize := disp1;
while lsp3 <> nil do begin
lsp4 := lsp3^.subvar;
lsp3^.subvar := lsp2;
lsp3^.size := disp1;
lsp3 := lsp4;
end;
Match(rparent,4);
if not (sy in fsys + [semicolon]) then begin
Error(6);
Skip(fsys + [semicolon]);
end;
end;
test := sy <> semicolon;
if not test then begin
disp1 := minsize;
InSymbol;
end;
until test;
if numcase <> 0 then Error(98);
disp1 := maxsize;
lsp^.fstvar := lsp1;
frecVar^.hasSFile := hasFile;
end
else
frecvar := nil;
end; {FieldList}
procedure ProcList (fsys: setofsys);
{ compile a field list }
{ }
{ parameters: }
{ fsys - following symbols }
var
foundBody: boolean; {dummy var for ProcDeclaration}
lsy: symbol; {for recording type of subroutine}
begin {ProcList}
{make sure the initial symbol is valid}
if not (sy in fsys+[procsy,funcsy]) then begin
Error(19);
Skip(fsys + [procsy,funcsy]);
end; {if}
{process all procedures and functions}
while sy in [procsy,funcsy] do begin
nextLocalLabel := 1;
lsy := sy;
InSymbol;
nextLocalLabel := 1;
ProcDeclaration(lsy, fsys+[procsy,funcsy], true, true, foundbody);
if objectcp^.pfdirective = droverride then
objectcp^.pfdirective := drforw
else begin
objectcp^.pfaddr := disp1;
disp1 := disp1 + ptrsize;
end; {else}
while sy = semicolon do begin
InSymbol;
if not (sy in fsys + [procsy,funcsy,semicolon]) then begin
Error(19);
Skip(fsys + [procsy,funcsy]);
end; {if}
end; {while}
end; {while}
end; {ProcList}
begin {Typ}
if not (sy in typebegsys) then begin
Error(10);
Skip(fsys+typebegsys);
end;
if sy in typebegsys then begin
if sy in simptypebegsys then
SimpleType(fsys,fsp,fsize)
{^} else if sy = arrow then begin
lsp := pointer(Malloc(sizeof(structure)));
fsp := lsp;
with lsp^ do begin
eltype := nil;
size := ptrsize;
form := pointerStruct;
hasSFile := false;
end; {with}
InSymbol;
if sy = ident then begin
SearchSection(display[top].fname,lcp);
if lcp <> nil then
if lcp^.klass <> types then
lcp := nil;
if lcp = nil then begin
{forward reference type id}
lcp := pointer(Malloc(sizeof(identifier)));
with lcp^ do begin
len := ord(id[0])+2;
name := pointer(Malloc(len));
CopyString(name^,id,len);
idtype := lsp;
next := fwptr;
klass := types;
hasIFile := lsp^.hasSFile;
end; {with}
fwptr := lcp;
end {if}
else
with lcp^,lsp^ do begin
if {lcp^.}idtype <> nil then begin
{lsp^.}eltype := {lcp^.}idtype;
{lsp^.}hasSFile := {lcp^.}hasIFile;
end; {if}
if {lcp^.}name = thisType then
Error(10);
end; {with}
InSymbol;
end {if}
else Error(2);
end {else if}
else begin
if sy = packedsy then begin
InSymbol;
ispacked := pkpacked;
if not (sy in (typedels + [objectsy])) then begin
Error(10);
Skip(fsys + (typedels + [objectsy]));
end {if}
end {if}
else ispacked := pkunpacked;
{array}
if sy = arraysy then begin
InSymbol;
Match(lbrack,11);
lsp1 := nil;
repeat
lsp := pointer(Malloc(sizeof(structure)));
with lsp^ do begin
aeltype := lsp1;
inxtype := nil;
form := arrays;
hasSFile := lsp1^.hasSFile;
end;
lsp^.ispacked := ispacked;
lsp1 := lsp;
SimpleType(fsys + [comma,rbrack,ofsy],lsp2,lsize);
lsp1^.size := lsize;
if lsp2 <> nil then
if lsp2^.form <= subrange then begin
if IsReal(lsp2) then begin
Error(38);
lsp2 := nil;
end
else if lsp2 = longptr then begin
Error(74);
lsp2 := nil;
end; {else if}
lsp^.inxtype := lsp2
end {if}
else begin
Error(41);
lsp2 := nil;
end; {else}
test := sy <> comma;
if test then Match(rbrack,12) else InSymbol;
until test;
Match(ofsy,8);
Typ(fsys, lsp, lsize, false);
if lsp1^.ispacked = pkpacked then
if CompTypes(lsp,charptr) or CompTypes(lsp,boolptr) then
lsize := packedcharsize;
repeat
with lsp1^ do begin
lsp2 := aeltype;
aeltype := lsp;
hasSFile := lsp^.hasSFile;
if inxtype <> nil then begin
GetBounds(inxtype,lmin,lmax);
lsize := (lmax-lmin+1)*lsize;
size := lsize;
end; {if}
end; {with}
lsp := lsp1; lsp1 := lsp2;
until lsp1 = nil;
if lsize > $010000 then
if SmallMemoryModel then
Error(122);
end
{stringsy}
else if sy = stringsy then begin
InSymbol;
lmin := 80; {default string length is 80}
if sy = lbrack then begin
InSymbol;
DoConstant(fsys+[rbrack],lsp1,lvalu);
if lsp1 = intptr then
lmin := lvalu.ival
else
Error(15);
Match(rbrack,12);
end;
lsp1 := pointer(Malloc(sizeof(structure)));
with lsp1^ do begin
size := 2;
form := subrange;
hasSFile := false;
rangetype := intptr;
min := 0;
if lmin > 255 then
min := 1;
max := lmin;
end;
lsp := pointer(Malloc(sizeof(structure)));
with lsp^ do begin
aeltype := charptr;
inxtype := lsp1;
form := arrays;
hasSFile := false;
size := (lmin-lsp1^.min+1)*packedcharsize;
ispacked := pkpacked;
end;
end
{record}
else if sy = recordsy then begin
InSymbol;
oldtop := top;
if top < displimit then begin
top := top+1;
with display[top] do begin
fname := nil;
flabel := nil;
labsused := nil;
occur := rec;
end
end
else
Error(107);
disp1 := 0;
lsp := pointer(Malloc(sizeof(structure)));
FieldList(fsys-[semicolon]+[endsy], lsp1, lsp^.hasSFile, false);
if disp1 > $010000 then
if SmallMemoryModel then
Error(122);
with lsp^ do begin
fstfld := display[top].fname;
recvar := lsp1;
size := disp1;
form := records;
end; {with}
lsp^.ispacked := ispacked;
ExportUses;
top := oldtop;
Match(endsy,13);
end
{object}
else if sy = objectsy then begin
InSymbol;
{make sure we are declaring a type}
if not isType then
Error(127);
{ check for previous foward declaration }
lsp := nil;
lcp := objptr;
while (lcp <> nil) and (CompNames(objectName, lcp^.name^) <> 0)
do lcp := lcp^.next;
if lcp <> nil then lsp := lcp^.idtype;
if (sy <> semicolon) and (lsp <> nil) and (lsp^.objdef) then lsp := nil;
if lsp = nil then begin
{set up the type}
lsp := pointer(Malloc(sizeof(structure)));
with lsp^ do begin
form := objects;
objname := nil;
objsize := 6;
objlevel := 1;
objparent := nil;