mini-read.red 620 B

1234567891011121314151617181920212223242526
  1. % MINI-READ.RED - A small reader
  2. CompileTime <<GLOBAL '(DEBUG);
  3. FLUID '(TOK!* TOKTYPE!* CH!* !*RAISE);>>;
  4. Procedure READ;
  5. % start RATOM, get first fresh token
  6. Read1(Ratom());
  7. Procedure READ1(x);
  8. If x eq '!( then READLIST(RATOM()) % Skip the (
  9. else if x eq '!' then CONS('QUOTE, NCONS READ())
  10. else x;
  11. Procedure ReadList(x);
  12. % read LIST, starting at token x
  13. Begin scalar y;
  14. If x eq '!) then Return NIL;
  15. y:=Read1(x); % Finish read CAR of pair
  16. x:=Ratom(); % Check dot
  17. If x eq '!. then return CONS(y,car READLIST(RATOM()));
  18. Return CONS(y , READLIST(x))
  19. End;
  20. End;