np.for 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. C RDLINE- READ INPUT LINE
  2. C
  3. C COPYRIGHT 1980, INFOCOM COMPUTERS AND COMMUNICATIONS, CAMBRIDGE MA. 02142
  4. C ALL RIGHTS RESERVED, COMMERCIAL USAGE STRICTLY PROHIBITED
  5. C WRITTEN BY R. M. SUPNIK
  6. C
  7. C DECLARATIONS
  8. C
  9. SUBROUTINE RDLINE(BUFFER,LENGTH,WHO)
  10. IMPLICIT INTEGER(A-Z)
  11. CHARACTER BUFFER(78)
  12. character*78 sysbuf
  13. include 'parser.h'
  14. include 'io.h'
  15. 5 GO TO (90,10),WHO+1
  16. C !SEE WHO TO PROMPT FOR.
  17. 10 WRITE(OUTCH,50)
  18. C !PROMPT FOR GAME.
  19. 50 FORMAT(' >',$)
  20. 90 READ(INPCH,100) BUFFER
  21. 100 FORMAT(78A1)
  22. DO 200 LENGTH=78,1,-1
  23. IF(BUFFER(LENGTH).NE.' ') GO TO 250
  24. 200 CONTINUE
  25. GO TO 5
  26. C !TRY AGAIN.
  27. C
  28. C check for shell escape here before things are
  29. C converted to upper case
  30. C
  31. C NO SHELL ESCAPE /*TAA*/
  32. 250 CONTINUE
  33. C250 if (buffer(1) .ne. '!') go to 300
  34. C do 275 j=2,length
  35. C sysbuf(j-1:j-1) = buffer(j)
  36. C275 continue
  37. C sysbuf(j:j) = char(0)
  38. C call system(sysbuf)
  39. C go to 5
  40. C CONVERT TO UPPER CASE
  41. 300 DO 400 I=1,LENGTH
  42. IF((BUFFER(I).GE.'a').AND.(BUFFER(I).LE.'z'))
  43. & BUFFER(I)=char(ichar(BUFFER(I))-32)
  44. 400 CONTINUE
  45. if(LENGTH.EQ.0) GO TO 5
  46. PRSCON=1
  47. C !RESTART LEX SCAN.
  48. RETURN
  49. END
  50. C PARSE- TOP LEVEL PARSE ROUTINE
  51. C
  52. C DECLARATIONS
  53. C
  54. C THIS ROUTINE DETAILS ON BIT 0 OF PRSFLG
  55. C
  56. LOGICAL FUNCTION PARSE(INBUF,INLNT,VBFLAG)
  57. IMPLICIT INTEGER(A-Z)
  58. CHARACTER INBUF(78)
  59. LOGICAL LEX,SYNMCH,VBFLAG
  60. INTEGER OUTBUF(40)
  61. include 'debug.h'
  62. include 'parser.h'
  63. include 'xsrch.h'
  64. C
  65. D DFLAG=IAND(PRSFLG,1).NE.0
  66. PARSE=.FALSE.
  67. C !ASSUME FAILS.
  68. PRSA=0
  69. C !ZERO OUTPUTS.
  70. PRSI=0
  71. PRSO=0
  72. C
  73. IF(.NOT.LEX(INBUF,INLNT,OUTBUF,OUTLNT,VBFLAG)) GO TO 100
  74. IF(SPARSE(OUTBUF,OUTLNT,VBFLAG)) 100,200,300
  75. C !DO SYN SCAN.
  76. C
  77. C PARSE REQUIRES VALIDATION
  78. C
  79. 200 IF(.NOT.VBFLAG) GO TO 350
  80. C !ECHO MODE, FORCE FAIL.
  81. IF(.NOT.SYNMCH(X)) GO TO 100
  82. C !DO SYN MATCH.
  83. IF((PRSO.GT.0).AND.(PRSO.LT.XMIN)) LASTIT=PRSO
  84. C
  85. C SUCCESSFUL PARSE OR SUCCESSFUL VALIDATION
  86. C
  87. 300 PARSE=.TRUE.
  88. 350 CALL ORPHAN(0,0,0,0,0)
  89. C !CLEAR ORPHANS.
  90. D if(dflag) write(0,*) 'parse good'
  91. D IF(DFLAG) PRINT 10,PARSE,PRSA,PRSO,PRSI
  92. D10 FORMAT(' PARSE RESULTS- ',L7,3I7)
  93. RETURN
  94. C
  95. C PARSE FAILS, DISALLOW CONTINUATION
  96. C
  97. 100 PRSCON=1
  98. D if(dflag) write(0,*) 'parse failed'
  99. D IF(DFLAG) PRINT 10,PARSE,PRSA,PRSO,PRSI
  100. RETURN
  101. C
  102. END
  103. C ORPHAN- SET UP NEW ORPHANS
  104. C
  105. C DECLARATIONS
  106. C
  107. SUBROUTINE ORPHAN(O1,O2,O3,O4,O5)
  108. IMPLICIT INTEGER(A-Z)
  109. COMMON /ORPHS/ A,B,C,D,E
  110. C
  111. A=O1
  112. C !SET UP NEW ORPHANS.
  113. B=O2
  114. C=O3
  115. D=O4
  116. E=O5
  117. RETURN
  118. END
  119. C LEX- LEXICAL ANALYZER
  120. C
  121. C
  122. C THIS ROUTINE DETAILS ON BIT 1 OF PRSFLAG
  123. C
  124. LOGICAL FUNCTION LEX(INBUF,INLNT,OUTBUF,OP,VBFLAG)
  125. IMPLICIT INTEGER(A-Z)
  126. CHARACTER INBUF(78),J,DLIMIT(9)
  127. INTEGER OUTBUF(40)
  128. LOGICAL VBFLAG
  129. include 'parser.h'
  130. C
  131. include 'debug.h'
  132. C
  133. DATA DLIMIT/'A','Z','\x40','1','9','\x12','-','-','\x12'/
  134. C
  135. DO 100 I=1,40
  136. C !CLEAR OUTPUT BUF.
  137. OUTBUF(I)=0
  138. 100 CONTINUE
  139. C
  140. D DFLAG=IAND(PRSFLG,2).NE.0
  141. LEX=.FALSE.
  142. C !ASSUME LEX FAILS.
  143. OP=-1
  144. C !OUTPUT PTR.
  145. 50 OP=OP+2
  146. C !ADV OUTPUT PTR.
  147. CP=0
  148. C !CHAR PTR=0.
  149. C
  150. 200 IF(PRSCON.GT.INLNT) GO TO 1000
  151. C !END OF INPUT?
  152. J=INBUF(PRSCON)
  153. C !NO, GET CHARACTER,
  154. PRSCON=PRSCON+1
  155. C !ADVANCE PTR.
  156. IF(J.EQ.'.') GO TO 1000
  157. C !END OF COMMAND?
  158. IF(J.EQ.',') GO TO 1000
  159. C !END OF COMMAND?
  160. IF(J.EQ.' ') GO TO 6000
  161. C !SPACE?
  162. DO 500 I=1,9,3
  163. C !SCH FOR CHAR.
  164. IF((J.GE.DLIMIT(I)).AND.(J.LE.DLIMIT(I+1)))
  165. & GO TO 4000
  166. 500 CONTINUE
  167. C
  168. IF(VBFLAG) CALL RSPEAK(601)
  169. C !GREEK TO ME, FAIL.
  170. RETURN
  171. C
  172. C END OF INPUT, SEE IF PARTIAL WORD AVAILABLE.
  173. C
  174. 1000 IF(PRSCON.GT.INLNT) PRSCON=1
  175. C !FORCE PARSE RESTART.
  176. IF((CP.EQ.0).AND.(OP.EQ.1)) RETURN
  177. IF(CP.EQ.0) OP=OP-2
  178. C !ANY LAST WORD?
  179. LEX=.TRUE.
  180. D IF(DFLAG) PRINT 10,CP,OP,PRSCON,(OUTBUF(I),I=1,OP+1)
  181. D10 FORMAT(' LEX RESULTS- ',3I7/1X,10I7)
  182. RETURN
  183. C
  184. C LEGITIMATE CHARACTERS: LETTER, DIGIT, OR HYPHEN.
  185. C
  186. 4000 J1=ichar(J)-ichar(DLIMIT(I+2))
  187. D IF(DFLAG) PRINT 20,J,J1,CP
  188. D20 FORMAT(' LEX- CHAR= ',A1,2I7)
  189. IF(CP.GE.6) GO TO 200
  190. C !IGNORE IF TOO MANY CHAR.
  191. K=OP+(CP/3)
  192. C !COMPUTE WORD INDEX.
  193. GO TO (4100,4200,4300),(MOD(CP,3)+1)
  194. C !BRANCH ON CHAR.
  195. 4100 J2=J1*780
  196. C !CHAR 1... *780
  197. OUTBUF(K)=OUTBUF(K)+J2+J2
  198. C !*1560 (40 ADDED BELOW).
  199. 4200 OUTBUF(K)=OUTBUF(K)+(J1*39)
  200. C !*39 (1 ADDED BELOW).
  201. 4300 OUTBUF(K)=OUTBUF(K)+J1
  202. C !*1.
  203. CP=CP+1
  204. GO TO 200
  205. C !GET NEXT CHAR.
  206. C
  207. C SPACE
  208. C
  209. 6000 IF(CP.EQ.0) GO TO 200
  210. C !ANY WORD YET?
  211. GO TO 50
  212. C !YES, ADV OP.
  213. C
  214. END