Lisp Reader Implementation

The following programs illustrate how the Lisp reader can be implemented in terms of a function readtoken that reads an ``item'' from the input line and looks it up in the symbol table to get a pointer to its symbol structure.


;   Read an S-expression (Atom or List).
(define (read-sexpr)
  (let ((next (readtoken)))
    (if (eqv? next #\()
        (read-list)
        (if (eqv? next #\')
            (list 'quote (read-sexpr))
            next)) ) )

; read a list of items. (define (read-list) (let ((done #f) (next #f) (result '())) (while (not done) (set! next (read-sexpr)) (if (eqv? next #\) ) (set! done #t) (set! result (cons next result)) ) ) (nreverse result) ) )

Contents    Page-10    Prev    Next    Index