-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfpcross_cleaned_01.pas
2522 lines (2332 loc) · 92 KB
/
fpcross_cleaned_01.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
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
PROGRAM cleaned_fpcross(input, output) ;
(*$N+ ***********
PCROSS is a cross-referencing program for PASCAL source files,
useful also to reformat programs (indentation, upper-lower case)
and to find omitted or excessive BEGINS and ENDS.
comments, gripes and bugs to A.ARMANDO
subtopics:
INPUT AND OUTPUT
HOW TO USE IT
SWITCHES
READING THE OUTPUT
<INPUT AND OUTPUT>
INPUT:
-----
through the file OLDSOURCE, a PASCAL source program file.
OUTPUT:
------
through NEWSOURCE:
a copy of your input file, unnumbered, prettyprinted
(proper indentation according to the statement nesting,
newline on standard places in the program, management of upper
and lower case according to the list of reserved words, etc.)
and trough CROSSLIST:
(a) a prettyprinted version of the program, showing in the left
margin the relations between BEGIN..END pairs,THEN..ELSE
pairs, etc.
(b) a cross reference of all the identifiers
(c) a report of procedure and function declaration nesting.
By default, PCROSS will change all reserved words and strings to upper
case, comments and everything else to lower case. There are switches
available to change this condition.
<HOW TO USE IT>
You can:
(a) use the /CREF switch when @EXECUTEing your program
or calling @PASCAL, or
(b) call it directly by typing @PCROSS.
In the first case, PCROSS will be called immediately after compilation;
You will have to type the file names, though. We are working to fix
that detail soon. Two sample calls are:
@pcross AND @exec myprog/cref
OLDSOURCE= myprog.pas/nocross (*COMPILER STUFF HERE*)
NEWSOURCE= myprog.pas OLDSOURCE= myprog.pas
CROSSLIST= NEWSOURCE=
CROSSLIST=
The left one calls it directly. The effect is the prettyprinting of the
program file itself. The right one is a call through the compiler, which
will use the default options.
The program parameters all have dafault values, but they can be modified
if desired, by the use of switches. See the subtopic SWITCHES.
See the subtopic SWITCHES.
<SWITCHES>
Brackets indicate optional.
<n> stands for an integer number.
<L> stands for a letter.
Switch Meaning Default.
FILES.
<n> is the sum of:
1 source program listing
2 listing of identifiers
4 listing of proc-func
declaration nesting.
8 listing of proc-func call nesting.
PAGE AND LINE FORMAT
margin every fifth line on
STATEMENT FORMAT
begin..end block is indented n spaces further.
if it is there, the block will not be indented,
but the begin and end statements will be
exdented n spaces. 0
after begin, end, then, else, repeat, etc.) off
comment from old standards to
'('-'*' and '*'-')' on
UPPER AND LOWER CASE
note: the possible values for <l> are:
u means upper case
l means lower case.
<READING THE OUTPUT>
The cross-reference file CROSSLIST contains 4 parts:
1. THE PROGRAM LISTING:
the letters and numbers in the left margin indicate the presence
of reserved words which have to match. (BEGIN-END, etc.) The two
words that match accorde with the scope rules will have the
same number. The first one (e. g., BEGIN) will appear at left, and
the second one (e.g., END) at right, inside the margin. The meaning
of the letters is:
B Begin E end
I If T Then S Else
L Loop X Exit E End
C Case E End
R Repeat U Until
2. THE CROSS REFERENCE LISTING OF IDENTIFIERS:
It is ordered alphabetically. For each identifier it contains:
a. A 'P' or 'F' if it is a procedure or function, respectively.
b. The name of the identifier, up to 10 symbols.
c. The line numbers in which it occur. Those lines in which
it is declared are marked with a D; those in which it
occurs more than once are marked with an M (Multiple).
3. THE NESTING OF PROCEDURE-FUNCTION DECLARATION:
It describes the static links. The scope is shown by indentation.
Each line describes a procedure or function and contains:
a. The name.
b. an (M), (P) or (F) if it is the main program, a procedure
or a function, respectively.
c. If there are more than one procedure-function with the same
name (in different scopes, which is perfectly valid, but
a horrible thing to do), a D (for DOUBLE) appears next,
and the rest of the information in this and the next part
of the listing contains data on both (or all of them, if
there are more than one.).
d. If it is an external procedure, an E will appear next.
e. The line number where the header appeared.
f. The line number of the BEGIN statement.
g. The line number of the END statement.
4. THE NESTING OF PROCEDURE-FUNCTION CALLS:
It describes the dynamic links. Calling depth is indicated by
indenting. The format of each line is the same as in the previous
report, except for the following:
a. Lines are numbered.
b. A procedure can be called from more than one place. To avoid
repeating the list of proc-funcs called by it,an asterisk
is printed after the name to indicate that it has already
been 'described'. Instead of the line numbers for its
appearence in the program, that for its appearence in this
part of the listing is given, so that you can refer to it.
*************)
(******************************************************************************)
(*$T-,R100 *)
(*PROGRAM WHICH CREATES A CROSS REFERENCE LISTING WITH SIMULTANEOUS
FORMATTING OF A PASCAL PROGRAM. WRITTEN BY MANUEL MALL.*)
(* INDEX *)
(**) (*DECLARATIONS*)
(**) (*INITPROCEDURES*)
(**) (*CHECKOPTIONS[*) (*SETSWITCH*)
(**) (*PAGE AND LINE CONTROL*) (*HEADER*) (*NEWPAGE*) (*NEWLINE*)
(**) (*BLOCK[*) (*OUTPUT PROCEDURES:*) (*ERROR*) (*WRITELINE[*) (*USETABS*)
(*]*) (*SETLASTSPACES*)
(**) (*INPUT PROCEDURES:*) (*INSYMBOL[*) (*READBUFFER*)
(**) (*RESWORD*) (*FINDNAME*) (*PARENTHESE*)
(**) (*DOCOMMENT*) (*]INSYMBOL*)
(**) (*"PARSING" PROCEDURES:*) (*RECDEF[*) (*CASEDEF*) (*PARENTHESE*) (*]
*)
(**) (*STATEMENT[*) (*AND ITS PARTS*) (*]*)
(**) (*]BLOCK*)
(**) (*PRINT_XREF_LIST[*) (*CHECKPAGE*) (*WRITEPROCNAME*) (*WRITELINENR*) (*
DUMPCALL*)
(**) (*]PRINT_XREF_LIST*)
(**) (*MAIN PROGRAM*)
(*DECLARATIONS*)
(**********************************************************************
*
*
* PROGRAM WHICH CREATES A CROSS REFERENCE LISTING
* AND A NEW, REFORMATTED VERSION OF A PASCAL PROGRAM.
*
* INPUT: PASCAL SOURCE FILE.
* OUTPUT: NEW REFORMATTED SOURCE FILE AND
* CROSS-REFERENCE LISTING.
*
* AUTHOR: MANUEL MALL (1974).
*
* MODIFIED AT STANFORD UNIVERSITY BY LARRY PAULSON.
* + NOT AS MANY FORCED NEWLINES.
* + THE REPORT ON PROCEDURE CALLS WAS CANCELLED.
*
* MODIFIED AT STANFORD UNIVERSITY BY ARMANDO R. RODRIGUEZ. 24-MAR-78.
* + A NEW SET OF SWITCH OPTIONS.
* + SOME NEW ERRORS ARE REPORTED.
*
* SEE THE PROCEDURE CHECKOPTIONS FOR THE AVAILABLE SWITCHES.
*
* MODIFIED AT STANFORD UNIVERSITY BY ARMANDO R. RODRIGUEZ. 6-JUL-88.
* + ACCEPT COMMENTS BETWEEN '%' AND BACKLASH AND BETWEEN '/*
' AND '*/'.
* + MARK 'P' OR 'F' IN FRONT OF THE PROC-FUNC NAMES.
* + MARK 'D' FOR DECLARATIONS AND 'M' FOR MULTIPLE OCCURRENCE
S.
* + SWITCH CLEAN/NOCLEAN TO STANDARIZE COMMENTS.
* + LISTING OF PROC-FUNC CALL NESTING.
* + REPORT THE LINE NUMBERS OF BEGIN AND END OF BODY OF PROCE
DURES.
* THINGS TO BE FIXED, OR DOCUMENTED:
* + IF THERE ARE TWO PROCS WITH ONE NAME, IT MIXES THEM.
* + IF A PROC NAME IS USED AS A VAR LATER, IT WILL BE SEEN
* AS A PROC FOR CALL-NESTING.
* + MAKE IT SMART ENOUGH TO AVOID CREATING STRUCTURES
* THAT WON'T BE USED, WHEN CROSS IS NOT 15.
* + MAKE IT RUN FASTER IN GENERAL. (TRY SPECIFICALLY I/O).
*
*
***********************************************************************)
"**********************************************************************
* *
* *
* PCROSS is now modified to run under the Stanford PASCAL *
* system. The various option switches for the program should *
* now be specified in special comments of the following form: *
* *
* (*%X+,F+,N-,R+,I-,C+,... other comments *) *
* *
* where: *
* *
* X+/- --> generate/do not generate a cross reference table, *
* F+/- --> generate/do not generate a reformatted listing, *
* N+/- --> allow/do not allow nesing of comments, *
* R+/- --> use upper/lower case in printing the reserved words , *
* I+/- --> use upper/lower case in printing the identifieres, *
* C+/- --> use upper/lower case in printing comments. *
* *
* *
* *
* PCROSS in general, and its reformating function in particular, *
* can be fairly time consuming and it is known to have some *
* problems. *
* *
* *
* *
* Sassan Hazeghi *
* *
* Stanford Linear Accelerator Center *
* P. O. Box 4349 *
* Stanfor, CA 94305. *
* *
* Jan. 22 1979. *
* *
* *
**********************************************************************"
LABEL 444;
CONST
version ='PCROSS: VERSION OF 4-aug-78 AT STANFORD UNIVERSITY';
maxline = 55; (*MAXIMUM NUMBER OF LINES PER PAGE, IG
NORING HEADER*)
oldwidth =200; (*MAXIMUM LENGTH OF INPUT LINES*)
max_line_count = 7777(*B*); (*LIMIT OF LINES/EDIT-PAGE*)
max_page_count = 77(*B*); (*LIMIT OF EDIT-PAGES*)
(* MAX_LINE_COUNT AND MAX_PAGE_COUNT SHOULD NOT NEED MORE THAN 18 B
ITS TOTAL*)
ht = 9 (*11B*); (*ASCII HORIZONTAL TAB*)
ff = 12 (*14B*); (*ASCII FORM FEED*)
cr = 13 (*15B*); (*ASCII CARRIAGE RETURN*)
blanks = ' '; (*FOR EDITING PURPOSES*)
dots = ' . . . . . . . . . .';
(*' . . . . . . . . . . . . . .'; *)
TYPE
pack6 = PACKED ARRAY[1..6] OF char;
pack9 = PACKED ARRAY[1..9] OF char;
errkinds = (begerrinblkstr,enderrinblkstr,missgenduntil,missgthen,missgof,
missgexit,
missgrpar,missgquote,linetoolong,missgmain,missgpoint);
lineptrty = @line;
listptrty = @list;
procstructy = @procstruc;
calledty = @called;
linenrty = 0..max_line_count;
pagenrty = 0..max_page_count;
symbol = (labelsy,constsy,typesy,varsy,programsy, (*DECSYM*)
functionsy,proceduresy,initprocsy, (*PROSYM*)
endsy,untilsy,elsesy,thensy,exitsy,ofsy,dosy,eobsy, (*ENDSYMBOLS*)
beginsy,casesy,loopsy,repeatsy,ifsy, (*BEGSYM*)
recordsy,forwardsy,gotosy,othersy,intconst,ident,strgconst,
externsy,langsy,forsy,whilesy,
rbracket,rparent,semicolon,point,lparent,lbracket,colon,eqlsy,
otherssy(*DELIMITER*),
letterup, letterlo, digit,quotech, dquotech, spacech,
dollarch, undsch, skipch ) ;
line = PACKED RECORD
(*DESCRIPTION OF THE LINE NUMBER*)
linenr : linenrty; (*LINE NUMBER*)
pagenr : pagenrty; (*PAGE NUMBER*)
contlink : lineptrty; (*NEXT LINE NUMBER RECORD*)
declflag: char; (*'D' IF DECLARATION, 'M' IF
MULTIPLE OCCURRENCE, BLANK OTHERWISE*)
END;
list = PACKED RECORD
(*DESCRIPTION OF IDENTIFIERS*)
name : alfa; (*NAME OF THE IDENTIFIER*)
llink , (*LEFT SUCCESSOR IN TREE*)
rlink : listptrty; (*RIGHT SUCCESSOR IN TREE*)
first , (*POINTER TO FIRST LINE NUMB
ER RECORD*)
last : lineptrty; (*POINTER TO LAST LINE NUMBE
R RECORD*)
externflag: char; (*'E' IF EXTERNAL, 'F' IF FO
RWARD,
'D' IF TWO PROCS WITH THE S
AME NAME, BLANK OTHERWISE*)
profunflag : char; (*'P' IF PROCEDURE NAME, 'F'
IF FUNCTION, BLANK OTHERWISE*)
procdata: procstructy;
END;
procstruc = PACKED RECORD
(*DESCRIPTION OF THE PROCEDURE NESTING*)
procname : listptrty; (*POINTER TO THE APPROPRIATE
IDENTIFIER*)
nextproc : procstructy; (*POINTER TO THE NEXT ELEMEN
T*)
linenr, (*LINE NUMBER OF THE PROCEDU
RE DEFINITION*)
begline, (*LINE NUMBER OF THE BEGIN S
TATEMENT*)
endline: linenrty; (*LINENUMBER OF THE END STAT
EMENT*)
pagenr , (*PAGE NUMBER OF THE PROCEDU
RE DEFINITION*)
begpage, (*PAGE NUMBER OF THE BEGIN S
TATEMENT*)
endpage, (*PAGE NUMBER OF THE END STA
TEMENT*)
proclevel: pagenrty; (*NESTING DEPTH OF THE PROCE
DURE*)
firstcall: calledty; (*LIST OF PROCEDURES CALLED
BY THIS ONE*)
printed: boolean; (*TO AVOID LOOPS IN THE CALL
-NEST LIST*)
END;
called = PACKED RECORD
nextcall : calledty;
whom : procstructy;
END;
VAR
(* INPUT CONTROL*)
i, (*INDEX VARIABLE*)
bufflen, (*LENGTH OF THE CURRENT LINE IN THE IN
PUT BUFFER*)
buffmark, (*LENGTH OF THE ALREADY PRINTED PART O
F THE BUFFER*)
bufferptr, (*POINTER TO THE NEXT CHARACTER IN THE
BUFFER*)
syleng, (*LENGTH OF THE LAST READ IDENTIFIER O
R LABEL*)
(* NESTING AND MATCHING CONTROL*)
bmarknr, (*NUMBER FOR MARKING OF 'BEGIN', 'LOOP
' ETC.*)
emarknr, (*NUMBER FOR MARKING OF 'END', 'UNTIL'
ETC.*)
level, (*NESTING DEPTH OF THE CURRENT PROCEDU
RE*)
variant_level, (*NESTING DEPTH OF VARIANTS*)
blocknr, (*COUNTS THE STATEMENTS 'BEGIN', 'CASE
', 'LOOP', 'REPEAT', 'IF'*)
errcount, (*COUNTS THE ERRORS ENCOUNTERED*)
(* FORMATTING*)
maxch, (*PAGE WIDTH IN COLS FOR CROSSLIST*)
increment, (*LINE NUMBER INCREMENT*)
indentbegin, (*INDENTATION AFTER A BEGIN*)
begexd, (*EXDENTATION FOR BEGIN-END PAIRS*)
feed, (*INDENTATION BY PROCEDURES AND BLOCKS
*)
spaces, (*INDENTATION FOR THE FORMATTING*)
lastspaces, (*ONE-TIME OVERRIDING VALUE FOR SPACES
*)
goodversion, (*keeps the value of the version optio
n*)
pagecnt, (*COUNTS THE FILE PAGES*)
pagecnt2, (*COUNTS THE PRINT PAGES PER FILE PAGE
*)
maxinc, (*GREATEST ALLOWABLE LINE NUMBER*)
reallincnt, (*COUNTS THE LINES PER PRINT PAGE*)
linecnt : integer; (*COUNTS THE LINES PER FILE PAGE*)
rtime: ARRAY[0..3] OF integer; (*CPU TIME REPORT*)
procstrucdata : RECORD
(*NEXT PROCEDURE TO BE PUT IN NESTING LIST*)
exists : boolean;
item : procstruc;
END;
flagger : ARRAY [-1..202] OF boolean; (*INDICATOR FOR UPPER AND LOWER CASE P
RINTING*)
buffer : ARRAY [-1..202] OF char; (*INPUT BUFFER*)
(* BUFFER HAS 2 EXTRA POSITIONS ON THE LEFT AND ONE ON THE RIGHT*)
tabs: ARRAY [1..17] OF (*ascii*) char; (*A STRING OF TABS FOR FORMATTING*)
linenb : PACKED ARRAY [1..5] OF char; (*SOS-LINE NUMBER*)
"date_text,time_text: alfa;" (*HEADING DATE AND TIME*)
prog_name, (*NAME OF CURRENT PROGRAM*)
sy : alfa; (*LAST SYMBOL READ*)
syty : symbol; (*TYPE OF THE LAST SYMBOL READ*)
(* SWITCHES*)
renewing, (*SET IF THE NEWLSOURCE FILE IS BEING
WRITTEN*)
crossing, (*SET IF THE CROSSLIST FILE IS BEING W
RITEN*)
refing, (*SET IF THE REFERENCES WILL BE PRINTE
D*)
decnesting, (*SET IF THE PRO-FUNC DECLARATION LIST
ING WILL BE PRINTED*)
callnesting, (*SET IF THE PRO-FUNC CALL NESTING WIL
L BE PRINTED*)
doting, (*SET IF DOTED LINES WILL BE PRINTED A
T LEFT MARGIN*)
forcing, (*SET IF THEN, ELSE, DO, REPEAT WILL F
ORCE NEWLINE*)
nestcomments, (*ACCEPT NESTED COMMENTS*)
cleaning, (*SET IF COMMENTS WILL BE STANDARIZD*)
rescase, (*SET IF RESERVED WORDS WILL UPSHIFT*)
nonrcase, (*SET IF NONRESERVED WORDS WILL UPSHIF
T*)
comcase, (*SET IF COMMENTS WILL UPSHIFT*)
strcase, (*SET IF STRINGS WILL UPSHIFT*)
thendo, (*SET WHENEVER 'SPACES := SPACES+DOFEE
D' IS EXECUTED*)
anyversion, (*set if goodversion > 9*)
(* OTHER CONTROLS*)
fwddecl, (*SET TRUE BY BLOCK AFTER 'FORWARD', '
EXTERN'*)
oldspaces, (*SET WHEN LASTSPACES SHOULD BE USED*)
eoline, (*SET AT END ON INPUT LINE*)
gotoinline, (*SET IF A HORRENDOUS GOTO STATEMENT I
N THIS LINE*)
declaring, (*SET WHILE PARSING DECLARATIONS*)
programpresent, (*SET AFTER PROGRAM ENCOUNTERED*)
nobody, (*SET IF NO MAIN BODY IS FOUND*)
eob : boolean; (*EOF-FLAG*)
(**)
ch, (*LAST READ CHARACTER*)
bmarktext, (*CHARACTER FOR MARKING OF 'BEGIN' ETC
.*)
emarktext: char; (*CHARACTER FOR MARKING 'END' ETC.*)
(* SETS*)
delsy : ARRAY [CHAR"' '..'_'"] OF symbol; (*TYPE ARRAY FOR DELIMITER CHARS*)
resnum: ARRAY[char] OF integer; (*INDEX OF THE FIRST KEYWORD BEGINNING
WITH THE INDEXED LETTER*)
reslist : ARRAY [1..46] OF alfa; (*LIST OF THE RESERVED WORDS*)
ressy : ARRAY [1..46] OF symbol; (*TYPE ARRAY OF THE RESERVED WORDS*)
"alphanum, (*CHARACTERS FROM 0..9 AND A..Z*)
digits, (*CHARACTERS FROM 0..9*)
letters : SET OF char; " (*CHARACTERS FROM A..Z*)
relevantsym, (*START SYMBOLS FOR STATEMENTS AND PRO
CEDURES*)
prosym, (*ALL SYMBOLS WHICH BEGIN A PROC.*)
decsym, (*ALL SYMBOLS WHICH BEGIN DECLARATIONS
*)
begsym, (*ALL SYMBOLS WHICH BEGIN COMPOUND STA
TEMENTS*)
endsym : SET OF symbol; (*ALL SYMBOLS WHICH TERMINATE STATEME
NTS OR PROCEDURES*)
(* POINTERS AND FILES*)
listptr, heapmark : listptrty; (*POINTER INTO THE BINARY TREE OF THE
IDENTIFIER*)
firstname : ARRAY [char ] OF listptrty; (*POINTER TO THE ROOTS OF THE
TREE*)
procstrucf, (*POINTER TO THE FIRST ELEMENT OF THE
PROCEDURE CALLS LIST*)
procstrucl : procstructy; (*POINTER TO THE LAST ELEMENT OF THE P
ROCEDURE CALLS LIST*)
workcall: calledty;
link_name,
new_name, cross_name: pack9; (*USED TO GET THE PARAMETER FILES*)
old_dev,link_device,
new_dev,cross_dev:pack6;
old_prot,old_ppn,
new_prot,new_ppn,cross_prot,cross_ppn: integer;
programname,oldfileid,newfileid,crossfileid: alfa;
TTY,
OLDSOURCE,NEWSOURCE,CROSSLIST: text; (*FILES PROCESSED BY THIS PROGRAM*)
(*INITPROCEDURES*)
PROCEDURE init0; "INITPROCEDURE;"
BEGIN (*CONSTANTS*)
eob := false;
maxch:=114;
increment:= "100" 1;
feed:=4;
indentbegin:=0;
nestcomments := true ;
cleaning := true ;
begexd:=0;
rescase:=true;
nonrcase:=false;
comcase:=false;
strcase:=true;
renewing:=true;
crossing:=true;
refing:= true (*false*);
decnesting:= true (*false*);
callnesting:=true (*false*);
doting:=false (*true*);
nobody := false;
anyversion := false;
goodversion := -1;
new_name:=' ';
cross_name:=' ';
programname:='PCROSS ';
oldfileid:='OLDSOURCE ';
newfileid:='NEWSOURCE ';
crossfileid:='CROSSLIST ';
END (*CONSTANTS*);
procedure init1; "INITPROCEDURE;"
BEGIN (*RESERVED WORDS*)
resnum['A'] := 1; resnum['B'] := 3; resnum['C'] := 4;
resnum['D'] := 6; resnum['E'] := 9; resnum['F'] := 13;
resnum['G'] := 18; resnum['H'] := 19; resnum['I'] := 19;
resnum[succ('I')] := 22;
resnum['J'] := 22; resnum['K'] := 22; resnum['L'] := 22;
resnum['M'] := 24; resnum['N'] := 25; resnum['O'] := 27;
resnum['P'] := 30; resnum['Q'] := 33; resnum['R'] := 33;
resnum[succ('R')] := 35 ;
resnum['S'] := 35; resnum['T'] := 36; resnum['U'] := 39;
resnum['V'] := 40; resnum['W'] := 41; resnum['X'] := 43;
resnum['Y'] := 43; resnum['Z'] := 43; resnum[succ('Z')] := 43;
reslist[ 1] :='AND '; ressy [ 1] := othersy;
reslist[ 2] :='ARRAY '; ressy [ 2] := othersy;
reslist[ 3] :='BEGIN '; ressy [ 3] := beginsy;
reslist[ 4] :='CASE '; ressy [ 4] := casesy;
reslist[ 5] :='CONST '; ressy [ 5] := constsy;
reslist[ 6] :='DO '; ressy [ 6] := dosy;
reslist[ 7] :='DIV '; ressy [ 7] := othersy;
reslist[ 8] :='DOWNTO '; ressy [ 8] := othersy;
reslist[ 9] :='END '; ressy [ 9] := endsy;
reslist[10] :='ELSE '; ressy [10] := elsesy;
reslist[11] :='EXIT____ '; ressy [11] := exitsy;
reslist[12] :='EXTERN '; ressy [12] := externsy;
reslist[13] :='FOR '; ressy [13] := forsy;
reslist[14] :='FILE '; ressy [14] := othersy;
reslist[15] :='FORWARD '; ressy [15] := forwardsy;
reslist[16] :='FUNCTION '; ressy [16] := functionsy;
reslist[17] :='FORTRAN '; ressy [17] := langsy;
reslist[18] :='GOTO '; ressy [18] := gotosy;
reslist[19] :='IF '; ressy [19] := ifsy;
reslist[20] :='IN '; ressy [20] := othersy;
reslist[21] :='INITPROCED'; ressy [21] := initprocsy;
reslist[22] :='LOOP____ '; ressy [22] := loopsy;
reslist[23] :='LABEL '; ressy [23] := labelsy;
reslist[24] :='MOD '; ressy [24] := othersy;
reslist[25] :='NOT '; ressy [25] := othersy;
reslist[26] :='NIL '; ressy [26] := othersy;
reslist[27] :='OR '; ressy [27] := othersy;
reslist[28] :='OF '; ressy [28] := ofsy;
reslist[29] :='OTHERS '; ressy [29] := otherssy;
reslist[30] :='PACKED '; ressy [30] := othersy;
reslist[31] :='PROCEDURE '; ressy [31] := proceduresy;
reslist[32] :='PROGRAM '; ressy [32] := programsy;
reslist[33] :='RECORD '; ressy [33] := recordsy;
reslist[34] :='REPEAT '; ressy [34] := repeatsy;
reslist[35] :='SET '; ressy [35] := othersy;
reslist[36] :='THEN '; ressy [36] := thensy;
reslist[37] :='TO '; ressy [37] := othersy;
reslist[38] :='TYPE '; ressy [38] := typesy;
reslist[39] :='UNTIL '; ressy [39] := untilsy;
reslist[40] :='VAR '; ressy [40] := varsy;
reslist[41] :='WHILE '; ressy [41] := whilesy;
reslist[42] :='WITH '; ressy [42] := othersy;
END;
procedure init2; "INITPROCEDURE;"
BEGIN (*SETS*)
"digits := ['0'..'9'];
letters := ['A'..'Z'];
alphanum := ['0'..'9','A'..'Z'] (*LETTERS OR DIGITS*); "
decsym := [labelsy,constsy,typesy,varsy,programsy];
prosym := [functionsy..initprocsy];
endsym := [functionsy..eobsy]; (*PROSYM OR ENDSYMBOLS*)
begsym := [beginsy..ifsy];
relevantsym := [labelsy..initprocsy (*DECSYM OR PROSYM*),beginsy,forwardsy,
externsy,eobsy];
END (*SETS*);
PROCEDURE init;
BEGIN
init0 ;
init1 ;
init2 ;
rtime[0]:=clock(1);
new(heapmark); (*THE HEAP IS DEALLOCATED AFTER EACH PROGRAM*)
workcall := NIL;
i := 0;
bufflen := 0;
buffmark := 0;
bufferptr := 2;
variant_level := 0;
reallincnt:= 0;
linecnt :=0;
blocknr := 0;
level := 0;
pagecnt := 1;
pagecnt2 := 0;
errcount := 0;
eoline := true;
gotoinline := false;
programpresent := false;
procstrucdata.exists := false;
oldspaces := false;
declaring := false;
bmarktext := ' ';
emarktext := ' ';
sy := blanks; prog_name := blanks;
"date(date_text); time(time_text);"
FOR ch := chr(0) to chr(255) DO
firstname [ch] := NIL;
FOR ch := ' ' TO 'Z' DO
delsy [ch] := othersy;
FOR ch := 'A' TO 'I' DO delsy[ch] := letterup ;
FOR ch := 'J' TO 'R' DO delsy[ch] := letterup ;
FOR ch := 'S' TO 'Z' DO delsy[ch] := letterup ;
FOR ch := 'a' TO 'i' DO delsy[ch] := letterlo ;
FOR ch := 'j' TO 'r' DO delsy[ch] := letterlo ;
FOR ch := 's' TO 'z' DO delsy[ch] := letterlo ;
FOR ch := '0' TO '9' DO delsy[ch] := digit ;
delsy['"'] := dquotech;
delsy['#'] := skipch ;
delsy['$'] := dollarch ;
delsy[''''] := quotech ;
delsy['_'] := undsch ;
delsy [' '] := spacech;
delsy ['('] := lparent;
delsy [')'] := rparent;
delsy ['['] := lbracket;
delsy [']'] := rbracket;
delsy [';'] := semicolon;
delsy ['.'] := point;
delsy [':'] := colon;
delsy ['='] := eqlsy;
FOR i := -1 TO 201 DO
buffer [i] := ' ';
i := 0;
new (firstname['M']);
listptr := firstname ['M'];
WITH firstname ['M']@ DO
BEGIN
name := 'MAIN. ';
llink := NIL;
rlink := NIL;
profunflag := 'M';
new (first);
last := first;
WITH last@ DO
BEGIN
linenr := 1;
pagenr:=1;
contlink := NIL;
END;
END;
new (procstrucf);
WITH procstrucf@ DO
BEGIN
procname := firstname ['M'];
nextproc := NIL;
linenr := 1;
pagenr:=1;
proclevel:= 0;
firstcall := NIL;
END;
procstrucl := procstrucf;
ch := ' ';
FOR i := 1 TO 17 DO
tabs [i] := "chr (ht)" ' ';
linenb := '-----' ;
END (*INIT*);
(*CHECKOPTIONS[*) (*SETSWITCH*)
(*---------------------------------------------------------------------
! CHECKS THE PRESENCE OF SWITCHES WITH THE FILE NAMES.
!
! VALID SWITCHES ARE: BRACKETS INDICATE OPTIONAL.
! <N> STANDS FOR AN INTEGER NUMBER
.
! <L> STANDS FOR A LETTER.
!
! SWITCH MEANING DEFAULT.
!
! FILES.
! /[NO]NEW WRITTING OF THE NEWSOURCE FILE ON
! /[NO]CROSS[:<N>] WRITTING OF THE CROSSLIST FILE. ON,15
! <N> IS THE SUM OF:
! 1 SOURCE PROGRAM LISTING
! 2 LISTING OF IDENTIFIERS
! 4 LISTING OF PROC-FUNC
! DECLARATION NESTING.
! 8 LISTING OF PROC-FUNC CALL NESTING.
! /version:<n> behave as if conditionally compiling %<n>
! comments. -1
!
! PAGE AND LINE FORMAT
! /WIDTH:<N> PAGE WIDTH FOR CROSSLIST. (MINIMUM: 40) 132
! /INDENT:<N> INDENTATION BETWEEN LEVELS. 4
! /INCREMENT:<N> LINE NUMBER INCREMENT 100
! /[NO]DOTS PUT AS A GUIDE A DOTTED LINE AT THE LEFT
! MARGIN EVERY FIFTH LINE ON
!
! STATEMENT FORMAT
! /BEGIN:[-]<N> IF THE [-] IS NOT THERE, THE CONTENTS OF A
! BEGIN..END BLOCK IS INDENTED N SPACES FURTHER.
! IF IT IS THERE, THE BLOCK WILL NOT BE INDENTED,
! BUT THE BEGIN AND END STATEMENTS WILL BE
! EXDENTED N SPACES. 0
! /[NO]FORCE FORCES NEWLINE IN STANDARD PLACES. (BEFORE AND
! AFTER BEGIN, END, THEN, ELSE, REPEAT, ETC.) OFF
! /[NO]CLEAN CONVERTS THE SYMBOLS FOR BEGIN AND END OF
! COMMENT FROM OLD STANDARDS TO '('-'*' AND '*'-')'
ON
!
! UPPER AND LOWER CASE
! NOTE: THE POSSIBLE VALUES FOR <L> ARE:
! U MEANS UPPER CASE
! L MEANS LOWER CASE.
!
! /RES:<L> CASE USED FOR RESERVED WORDS. U
! /NONRES:<L> SAME FOR NON-RESERVED WORDS. L
! /COMM:<L> SAME FOR COMMENTS. L
! /STR:<L> SAME FOR STRINGS. U
! /CASE:<L> RESETS ALL THE DEFAULTS TO <L>.
OFF
!
+--------------------------------------------------------------------*)
PROCEDURE checkoptions;
VAR
try: integer;
PROCEDURE setswitch(opt:alfa;VAR switch:boolean);
VAR
i: integer;
BEGIN (*SETSWITCH*)
(* getoption(opt,i); *) i := ord('l') ;
IF i=ord('L') THEN
switch:=false
ELSE
IF i=ord('U') THEN
switch:=true;
END (*SETSWITCH*);
PROCEDURE showthemall (i: integer);
BEGIN
writeln (tty,'(',i:3,')',oldfileid,',',programname);
writeln (tty, new_name,',',new_prot,',',new_ppn,',',new_dev,',',
newfileid,',',programname);
writeln (tty, cross_name,',',cross_prot,',',cross_ppn,',',cross_dev,',',
crossfileid,',',programname);
writeln (tty);
(* break(tty); *)
END;
BEGIN (*CHECKOPTIONS*)
(*##############
getparameter(oldsource,oldfileid,programname,true);
IF NOT option('NONEW ') THEN
parnameget(new_name,new_prot,new_ppn,new_dev,newfileid,programname,false);
IF NOT option('NOCROSS ') THEN
parnameget(cross_name,cross_prot,cross_ppn,cross_dev,crossfileid,program
name,false);
IF NOT option('NONEW ') THEN
begin
IF (new_name = ' ') AND (new_dev = 'dsk ') THEN
BEGIN
getstatus(oldsource, new_name,old_prot,old_ppn,old_dev);
new_name[7]:='N';
new_name[8]:='E';
new_name[9]:='W';
END;
startfile(newsource,new_name,new_prot,new_ppn,new_dev,false,newfileid);
end;
IF NOT option('NOCROSS ') THEN
begin
IF (cross_name = ' ') AND (cross_dev = 'dsk ') THEN
BEGIN
getstatus(oldsource, cross_name,old_prot,old_ppn,old_dev);
cross_name[7]:='C';
cross_name[8]:='R';
cross_name[9]:='L';
END;
startfile(crosslist,cross_name,cross_prot,cross_ppn,cross_dev,false,cros
sfileid);
end;
#####################*)
renewing:= true "NOT option('NONEW ')" ;
crossing:= true "NOT option('NOCROSS ')" ;
IF crossing THEN
BEGIN
(* getoption('CROSS ',try); *) try := 0 ;
IF try = 0 THEN
try:=15;
callnesting:=try > 7;
decnesting:=(try MOD 8) > 3;
refing:= (try MOD 4) > 1;
crossing:=(try MOD 2) = 1;
END;
(*if option('version ') then *)
begin
(* getoption('version ',goodversion); *) goodversion := 15 ;
if goodversion > 9 then
begin
goodversion := -1;
anyversion := true;
end;
end;
(*IF option('WIDTH ') THEN *)
BEGIN
(* getoption('WIDTH ',maxch); *) maxch := 90 ;
IF maxch < 40 THEN
maxch:=40;
maxch:=maxch-18;
END;
(* #################
IF option('INDENT ') THEN
BEGIN
// getoption('INDENT ',feed); *)
IF feed < 0 THEN
feed:=4;
END;
IF option('INCREMENT ') THEN
BEGIN
(* getoption('INCREMENT ',increment); *)
IF increment < 0 THEN
increment:= "100" 1;
END;
doting:=NOT option('NODOTS ');
IF option('BEGIN ') THEN
BEGIN
(* getoption('BEGIN ',indentbegin); *)
IF indentbegin < 0 THEN
BEGIN
begexd:=-indentbegin;
indentbegin:=0;
END;
END;
forcing:=option('FORCE ');
cleaning := NOT option('NOCLEAN ');
IF option('CASE ') THEN
BEGIN
setswitch('CASE ',rescase);
nonrcase:=rescase;
comcase:=rescase;
strcase:=rescase;
END;
setswitch('RES ',rescase);
setswitch('NONRES ',nonrcase);
setswitch('COMM ',comcase);
setswitch('STR ',strcase);
END (*CHECKOPTIONS*);
(*PAGE AND LINE CONTROL*) (*HEADER*) (*NEWPAGE*) (*NEWLINE*)
PROCEDURE header (name: alfa);
(*PRINT TOP OF FORM AND HEADER ON LIST OUTPUT*)
VAR
position: integer;
BEGIN (*HEADER*)
pagecnt2 := pagecnt2 + 1;
reallincnt := 0;
IF crossing THEN
BEGIN
page(crosslist); " writeln(crosslist) ;"
write (crosslist, 'Page':9, pagecnt:4, '-', pagecnt2:3 ", ' ':15");
position := 84;
IF maxch < 84 THEN
BEGIN
reallincnt:=1;
writeln(crosslist);
position := 42;
END;
write(crosslist,' [', prog_name,']', time"_text":50, date"_text");
IF (name <> blanks) AND (maxch < position + 25) THEN
BEGIN
reallincnt := reallincnt + 1;
writeln (crosslist);
position := 0;
END;
writeln (crosslist, ' ': maxch - position, name);
writeln(crosslist);
END;
END (*HEADER*);
PROCEDURE newpage;
BEGIN (*NEWPAGE*)
pagecnt2 := 0;
pagecnt := pagecnt + 1;
IF renewing THEN
(*write(newsource, chr(cr), chr(ff));*) writeln(newsource) ;
header (blanks);
IF eoln (oldsource) THEN
readln(oldsource);
linecnt := 0;
reallincnt := 0;
IF prog_name <> blanks THEN
write(tty, pagecnt:3,'..');
(* break(tty); *)
END (*NEWPAGE*);
PROCEDURE newline;
BEGIN
IF reallincnt = maxline THEN
header (blanks);
linecnt := linecnt + 1;
reallincnt := reallincnt + 1;
if crossing then write(crosslist, ' ':5);
if renewing then write(newsource, ' ':5) ;
END;
(*BLOCK[*) (*OUTPUT PROCEDURES:*) (*ERROR*) (*WRITELINE[*) (*USETABS*) (*]*)
(*SETLASTSPACES*)
PROCEDURE block;
VAR
curproc : listptrty; (*ZEIGER AUF DIE PROZEDUR IN DEREN ANWEISUNG
STEIL DAS PROGRAMM SICH BEFINDET*)
itisaproc : boolean; (*TRUE WHEN THE WORD PROCEDURE IS FOUND*)
locprocstl: procstructy;
PROCEDURE error (errnr : errkinds);
BEGIN (*ERROR*)
errcount := errcount+1;
reallincnt := reallincnt + 1; (*COUNT THE LINE OF THE ERROR MESSAGE ON T
HE LPT: FILE*)
IF crossing THEN
BEGIN
write (crosslist, ' ':17,' *??* ');
CASE errnr OF
begerrinblkstr : write(crosslist, sy,' ? ? ? : ERROR IN BLOCK'
,'STRUCTURE. POSSIBLY A MISSING BEGIN.');
enderrinblkstr : write(crosslist, sy,' ? ? ? : ERROR IN BLOCK'