poltok.red 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. LISP$
  2. % Simple TOKEN scanner to Debug POLY. RED;
  3. % Griss and Morrison
  4. GLOBAL '(CURCHARTYPE!* CURCHAR!* TOK!*);
  5. SYMBOLIC PROCEDURE CLEARTOKEN; %. Clear token scanner
  6. <<CURCHARTYPE!* := 'WHITE; CURCHAR!* := '! >>;
  7. SYMBOLIC PROCEDURE NTOKEN; %. get next token
  8. BEGIN SCALAR TOK;
  9. WHILE CURCHARTYPE!* MEMQ '(WHITE COMMENT) DO
  10. IF CURCHARTYPE!* EQ 'WHITE THEN
  11. READCHAR()
  12. ELSE << % Skip the comment
  13. REPEAT
  14. READCHAR()
  15. UNTIL CURCHAR!* MEMQ COMMENTEND!*;
  16. READCHAR() >>;
  17. IF CURCHARTYPE!* EQ 'DIGIT THEN <<
  18. WHILE CURCHARTYPE!* EQ 'DIGIT DO <<
  19. TOK := CURCHAR!* . TOK;
  20. READCHAR() >>;
  21. TOK!* := COMPRESS REVERSIP TOK >>
  22. ELSE IF CURCHARTYPE!* MEMQ '(LETTER ESCAPE) THEN <<
  23. WHILE CURCHARTYPE!* MEMQ '(LETTER ESCAPE) DO <<
  24. IF CURCHARTYPE!* EQ 'ESCAPE THEN <<
  25. TOK := '!! . TOK;
  26. READCHAR() >>;
  27. TOK := CURCHAR!* . TOK;
  28. READCHAR() >>;
  29. TOK!* := INTERN COMPRESS REVERSIP TOK >>
  30. ELSE IF CURCHARTYPE!* EQ 'DELIMITER THEN <<
  31. TOK!* := CURCHAR!*;
  32. READCHAR();TOK!* >>
  33. ELSE IF CURCHARTYPE!* EQ 'TERMINATOR THEN <<
  34. TOK!* := CURCHAR!*; CLEARTOKEN(); TOK!*>>
  35. ELSE
  36. ERROR(1010,
  37. LIST( "Illegal character `",COMPRESS LIST('!!,CURCHAR!*),
  38. "' in input stream -- NTOKEN") );
  39. END NTOKEN;
  40. SYMBOLIC PROCEDURE READCHAR; %. Get next char and classify
  41. << CURCHAR!* := READCH();
  42. CURCHARTYPE!* := GET(CURCHAR!*,'CHARACTERTYPE) >>;
  43. SYMBOLIC PROCEDURE INITTOKEN; %. Initialise TOKEN scan
  44. BEGIN
  45. DEFLIST('(
  46. (A LETTER)
  47. (B LETTER)
  48. (C LETTER)
  49. (D LETTER)
  50. (E LETTER)
  51. (F LETTER)
  52. (G LETTER)
  53. (H LETTER)
  54. (I LETTER)
  55. (J LETTER)
  56. (K LETTER)
  57. (L LETTER)
  58. (M LETTER)
  59. (N LETTER)
  60. (O LETTER)
  61. (P LETTER)
  62. (Q LETTER)
  63. (R LETTER)
  64. (S LETTER)
  65. (T LETTER)
  66. (U LETTER)
  67. (V LETTER)
  68. (W LETTER)
  69. (X LETTER)
  70. (Y LETTER)
  71. (Z LETTER)
  72. (a LETTER)
  73. (b LETTER)
  74. (c LETTER)
  75. (d LETTER)
  76. (e LETTER)
  77. (f LETTER)
  78. (g LETTER)
  79. (h LETTER)
  80. (i LETTER)
  81. (j LETTER)
  82. (k LETTER)
  83. (l LETTER)
  84. (m LETTER)
  85. (n LETTER)
  86. (o LETTER)
  87. (p LETTER)
  88. (q LETTER)
  89. (r LETTER)
  90. (s LETTER)
  91. (t LETTER)
  92. (u LETTER)
  93. (v LETTER)
  94. (w LETTER)
  95. (x LETTER)
  96. (y LETTER)
  97. (z LETTER)
  98. (!_ LETTER)
  99. (!. LETTER)
  100. (!0 DIGIT)
  101. (!1 DIGIT)
  102. (!2 DIGIT)
  103. (!3 DIGIT)
  104. (!4 DIGIT)
  105. (!5 DIGIT)
  106. (!6 DIGIT)
  107. (!7 DIGIT)
  108. (!8 DIGIT)
  109. (!9 DIGIT)
  110. (!+ DELIMITER)
  111. (!- DELIMITER)
  112. (!* DELIMITER)
  113. (!/ DELIMITER)
  114. (!^ DELIMITER)
  115. (!' DELIMITER)
  116. (!( DELIMITER)
  117. (!) DELIMITER)
  118. (!, DELIMITER)
  119. (!; TERMINATOR)
  120. (!! ESCAPE)
  121. (! WHITE) % Blank
  122. (! WHITE) % Tab
  123. (! WHITE) % Carriage Return
  124. (!
  125. WHITE) % Line Feed
  126. (! WHITE) % Form Feed
  127. (!% COMMENT)
  128. ), 'CHARACTERTYPE);
  129. PUT(!$EOL!$,'CHARACTERTYPE,'WHITE);
  130. COMMENTEND!* := LIST !$EOL!$;
  131. CLEARTOKEN();
  132. END;
  133. INITTOKEN();
  134. SYMBOLIC PROCEDURE XAPPLY(FN,ARGS); %. Interface for PLISP
  135. APPLY(FN,ARGS)$
  136. END$