pas1.red 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %
  3. % PASCAL BASED MINI-LISP
  4. %
  5. % File: PAS1.RED - Basic I/O Functions
  6. % ChangeDate: 10:48pm Wednesday, 15 July 1981
  7. % By: M. L. Griss
  8. % Change to add Features for Schlumberger Demo
  9. %
  10. % All RIGHTS RESERVED
  11. % COPYRIGHT (C) - 1981 - M. L. GRISS
  12. % Computer Science Department
  13. % University of Utah
  14. %
  15. % Do Not distribute with out written consent of M. L. Griss
  16. %
  17. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  18. % Additional Support procedures for optimized code;
  19. SYMBOLIC PROCEDURE CAAR(X);
  20. CAR CAR X;
  21. SYMBOLIC PROCEDURE CADR X;
  22. CAR CDR X;
  23. SYMBOLIC PROCEDURE CDAR X;
  24. CDR CAR X;
  25. SYMBOLIC PROCEDURE CDDR X;
  26. CDR CDR X;
  27. % All Friendly CxxxR's
  28. SYMBOLIC PROCEDURE CAAAAR X; CAR CAR CAR CAR X;
  29. SYMBOLIC PROCEDURE CAAADR X; CAR CAR CAR CDR X;
  30. SYMBOLIC PROCEDURE CAADAR X; CAR CAR CDR CAR X;
  31. SYMBOLIC PROCEDURE CAADDR X; CAR CAR CDR CDR X;
  32. SYMBOLIC PROCEDURE CADAAR X; CAR CDR CAR CAR X;
  33. SYMBOLIC PROCEDURE CADADR X; CAR CDR CAR CDR X;
  34. SYMBOLIC PROCEDURE CADDAR X; CAR CDR CDR CAR X;
  35. SYMBOLIC PROCEDURE CADDDR X; CAR CDR CDR CDR X;
  36. SYMBOLIC PROCEDURE CDAAAR X; CDR CAR CAR CAR X;
  37. SYMBOLIC PROCEDURE CDAADR X; CDR CAR CAR CDR X;
  38. SYMBOLIC PROCEDURE CDADAR X; CDR CAR CDR CAR X;
  39. SYMBOLIC PROCEDURE CDADDR X; CDR CAR CDR CDR X;
  40. SYMBOLIC PROCEDURE CDDAAR X; CDR CDR CAR CAR X;
  41. SYMBOLIC PROCEDURE CDDADR X; CDR CDR CAR CDR X;
  42. SYMBOLIC PROCEDURE CDDDAR X; CDR CDR CDR CAR X;
  43. SYMBOLIC PROCEDURE CDDDDR X; CDR CDR CDR CDR X;
  44. SYMBOLIC PROCEDURE CAAAR X; CAR CAR CAR X;
  45. SYMBOLIC PROCEDURE CAADR X; CAR CAR CDR X;
  46. SYMBOLIC PROCEDURE CADAR X; CAR CDR CAR X;
  47. SYMBOLIC PROCEDURE CADDR X; CAR CDR CDR X;
  48. SYMBOLIC PROCEDURE CDAAR X; CDR CAR CAR X;
  49. SYMBOLIC PROCEDURE CDADR X; CDR CAR CDR X;
  50. SYMBOLIC PROCEDURE CDDAR X; CDR CDR CAR X;
  51. SYMBOLIC PROCEDURE CDDDR X; CDR CDR CDR X;
  52. symbolic procedure prin2(x);
  53. begin
  54. if pairp(x) then
  55. << wrtok( '!( );
  56. while pairp(x) do
  57. << prin2 car(x);
  58. x := cdr x;
  59. if not eq(x,NIL) then wrtok('! ); % A space.
  60. >>;
  61. if not eq(x,NIL) then
  62. << wrtok( '!.! ); %Period followed by space.
  63. prin2(x);
  64. >>;
  65. wrtok( '!) );
  66. >>
  67. else
  68. wrtok(x);
  69. end;
  70. symbolic procedure revx(l1,l2);
  71. % Non-destructive reverser, adds reverse of l1 to front of l2.
  72. begin
  73. while pairp(l1) do
  74. << l2 := (car l1).l2;
  75. l1 := cdr l1;
  76. >>;
  77. if not null (l1) then l2 := l1 . l2;
  78. return l2;
  79. end;
  80. symbolic procedure rev(l1);
  81. revx(l1,NIL);
  82. % EOF code is Ascii Z plus an offset of 1, much too obscure!.
  83. symbolic procedure eofp(x);
  84. if atom(x) and (!*inf(x) eq 27) then 'T else 'NIL;
  85. symbolic procedure read();
  86. begin scalar itm,ii;
  87. itm := rdtok();
  88. if not(toktype eq 3) or eofp(itm) then return(itm); % Over cautious;
  89. if (itm eq '!( )
  90. then return rlist()
  91. else if (itm eq '!' ) % Treat quote mark as QUOTE.
  92. then return <<ii := read();
  93. if eofp(ii) then ii
  94. else ('QUOTE . ii . NIL)>>
  95. else return itm;
  96. end;
  97. symbolic procedure rlist();
  98. % Non destructive READ of S-expr, including ".".
  99. begin scalar itm,lst,done,last;
  100. itm := read();
  101. if eofp(itm) then return itm;
  102. done := NIL;
  103. while not done do
  104. if itm eq '!) and toktype eq 3
  105. then done :='T
  106. else if itm = '!. and toktype eq 3
  107. then <<done:='T; last:= car rlist()>> %CAR cures bug? WFG
  108. else
  109. <<lst := itm.lst; itm := read()>>;
  110. % ??? if pairp last then last:=car last>>;
  111. if eofp(itm) then return itm;
  112. return revx(lst,last);
  113. end;
  114. END$