Web pdp-10.trailing-edge.com

Trailing-Edge - PDP-10 Archives - decuslib10-01 - 43,50110/wellfm.log
```100'  NAME--WELLFM
110'
120'  DESCRIPTION--CHECKS TO SEE IF A STRING OF SYMBOLS TAKEN FROM
130'  THE LIST
140'  A,B,C,.......,R,S,T
150'  - (NOT), & (AND), V (OR), => (IF...THEN),
160'  <=> (IF AND ONLY IF), / (NOT BOTH), (, )
170'  CONSTITUTES A WELL-FORMED FORMULA OF THE PROPOSITIONAL CALCULUS.
180'  A STRING OF SYMBOLS IS A WELL-FORMED FORMULA IF AND ONLY IF
190'  IT CAN BE OBTAINED BY TH FOLLOWING RULES.
200'  (1)  ANY LETTER A,...,T STANDING ALONE IS A WELL-FORMED FORMULA.
210'  (2)  IS X AND Y ARE WELL-FORMED FORMULAS, THEN SO ARE -X,(X&Y)
220'       (XVY), (X=>Y), (X<=>Y), AND (X/Y).
230'  (3) NO STRING OTHER THAN THOSE OBTAINED BY RULES (1) AND (2)
240'      IS A WELL-FORMED FORMULA.
250'
260'  SOURCE--UNKNOWN
270'
280'  INSTRUCTIONS-- ENTER THE STRING OF SYMBOLS TO BE CHECKED
290'  AS DATA IN LINE 2000 AND THEN TYPE "RUN". E.G., TO CHECK THE STRING
300'  ( P => ( Q V -R) )    TYPE
310'    2000 DATA "( P => ( Q V -R ) )"
320'  NOTE: BLANKS WITHIN THE STRING ARE IGNORED.
330'  THE PROGRAM CHECKS THE GIVEN STRING FOR WELL-FORMEDNESS AND
340'  PRINTS OUT THE RESULT TOGETHER WITH A TABLE GIVING THE
350'  "DEPTH" OF EACH COMPONENT OF THE STRING.
360'
370'
380'  *  *  *  *  *  *  *  *  MAIN PROGRAM  *  *  *  *  *  *  *  *  *  *
390'
400 REM  INITIALIZATION
410 REM
420 DIM G(127), H(60), F(60), V\$(20)
430 LET L(0) = 1
440 FOR I = 1 TO 9
460 NEXT I
470 DATA "(", ")", "-", "&", "V", "*", "=>", "<=>", "/"
490 DATA -6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6
500 DATA -6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-5,-6,-6,-6,-6,-6,3,-6,0
510 DATA 1,-6,-6,-6,2,-6,8,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-1
520 DATA -2,-3,-6,-6,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4
530 DATA -4,-4,-4,-4,-6,4,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6
540 DATA -6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6
550 DATA -6,-6,-6,-6,-6,-6,-6
560 LET G(0) = -6
570 REM
580 REM
590 REM  STRING INPUT AND CONVERSION
600 REM
620 CHANGE F\$ TO H
630 PRINT "THE FORMULA"
640 PRINT "      "; F\$
650 LET P = 9
660 LET N = 0
670 LET E = H(0)
680 FOR I = 1 TO E
690 LET C = G(H(I))
700 IF C < 0 THEN 750
710 LET N = N+1
720 LET F(N) = C
730 NEXT I
740 GOTO 970
750 ON C+7 GOTO 760, 730, 780, 760, 840, 880
760 PRINT "CONTAINS AN ILLEGAL CHARACTER"
770 STOP
780 LET P = P+1
790 LET G(H(I)) = P
800 LET C = P
810 LET L(1) = H(I)
820 CHANGE L TO V\$(P+1)
830 GOTO 710
840 IF G(H(I+1)) <> -3 THEN 760
850 LET I = I+1
860 LET C = 6
870 GOTO 710
880 IF G(H(I+1)) <> -2 THEN 760
890 IF G(H(I+2)) <> -3 THEN 760
900 LET I = I+2
910 LET C = 7
920 GOTO 710
930 REM
940 REM
950 REM  SYNTAX CHECK
960 REM
970 FOR M=1 TO N
980 LET I=1
990 IF F(I) < 100 THEN 1030
1000 IF I=N THEN 1470
1010 LET I=I+1
1020 GOTO 990
1030 IF F(I)<10 THEN 1080
1040 LET F(I)=F(I)+100*M
1050 IF I=N THEN 1470
1060 IF F(I+1)<100 THEN 1630
1070 GOTO 1010
1080 IF F(I) = 0 THEN 1110
1090 IF F(I) = 2 THEN 1540
1100 GOTO 1630
1110 LET F(I)=100*M
1120 IF F(I+1)>=100 THEN 1630
1130 IF F(I+1)>=10 THEN 1410
1140 IF F(I+1)=2 THEN 1440
1150 IF F(I+1)=0 THEN 1170
1160 GOTO 1630
1170 GOSUB 1780
1180 IF I=N THEN 1630
1190 LET I=I+1
1200 IF F(I)>9 THEN 1630
1210 IF F(I)<3 THEN 1630
1220 LET F(I)=F(I)+100*M
1230 IF I=N THEN 1630
1240 IF F(I+1)>= 100 THEN 1630
1250 IF F(I+1)>=10 THEN 1380
1260 IF F(I+1) = 0 THEN 1300
1270 IF F(I+1) <> 2 THEN 1630
1280 LET I = I+1
1290 GOTO 1230
1300 GOSUB 1780
1310 IF I=N THEN 1630
1320 LET I=I+1
1330 IF F(I)<> 1 THEN 1630
1340 LET F(I)=1+100*M
1350 IF I = N THEN 1470
1360 IF F(I+1)<100 THEN 1630
1370 GOTO 1010
1380 IF I+1=N THEN 1630
1390 LET I=I+2
1400 GOTO 1330
1410 IF I+1=N THEN 1630
1420 LET I=I+2
1430 GOTO 1200
1440 LET I=I+1
1450 IF I = N THEN 1630
1460 GOTO 1120
1470 NEXT M
1480 REM
1490 REM
1500 REM  OUTPUT
1510 REM
1520 PRINT "IS WELL-FORMED"
1530 GOTO 1640
1540 LET F(I) = 100*M+2
1550 IF I=N THEN 1630
1560 LET I = I+1
1570 IF F(I) >= 100 THEN 1630
1580 IF F(I) >= 10 THEN 1350
1590 IF F(I) = 2 THEN 1550
1600 IF F(I) > 0 THEN 1630
1610 GOSUB 1780
1620 GOTO 1350
1630 PRINT "IS NOT WELL-FORMED"
1640 PRINT
1650 PRINT
1660 PRINT "DEPTH", "SYMBOL"
1670 PRINT
1680 FOR I = 1 TO N
1690 LET C = INT(F(I)/100)
1700 PRINT " "; C, "  ";
1710 PRINT V\$(F(I)-C*100+1)
1720 NEXT I
1730 STOP
1740 REM
1750 REM
1760 REM  SUBROUTINE TO FIND MATCHING )
1770 REM
1780 LET C = 1
1790 IF I=N THEN 1630
1800 LET I = I+1
1810 IF F(I) = 0 THEN 1840
1820 IF F(I) = 1 THEN 1860
1830 GOTO 1790
1840 LET C = C+1
1850 GOTO 1790
1860 LET C = C-1
1870 IF C>1 THEN 1790
1880 RETURN
2000 DATA "( P => ( Q & -R ) )"
3000 END

```