Subject: Re: simple lisp interpreter
From: rpw3@rpw3.org (Rob Warnock)
Date: Thu, 06 Sep 2007 20:45:13 -0500
Newsgroups: comp.lang.lisp
Message-ID: <JtWdnUw7V8e0MH3bnZ2dnUVZ_s2tnZ2d@speakeasy.net>
George Neuner  <gneuner2/@comcast.net> wrote:
+---------------
| Kent M Pitman <pitman@nhplace.com> wrote:
| >George Neuner <gneuner2/@comcast.net> writes:
| >> If you confine the problem to Lisp syntax then the answer is yes.
| >
| >Terminology: You mean to say "pre-defined Lisp syntax".  The stuff written
| >by users is _still_ Lisp syntax.
| 
| Sort of.  What I mean exactly is any sexpr syntax that conforms to
| Lisp's prefix notation.
+---------------

I think you've missed Kent's point entirely. When coding a CL READ in C
[and ignoring READ's &OPTIONAL parameters for the nonce], the top level
"parsing" routine looks like this [or something closely equivalent]:

    lispobj
    reader(lispobj stream)
    {
        for (;;) {         /* Needed for reader macros that do nothing. */
          lispobj obj;
          int c = flush_whitespace(stream);
          if (EOF == c)
            return type_EOF;
          obj = (*read_macro_table[c])(stream, c);
          if (obj != type_ZeroValues)  /* Comments, #+/-, and the like. */
            return obj;
	  /* else keep reading... */
        }
    }

The key is that *ALL* "parsing" starts with that crucial indirection
through the current readtable. There *is* no such thing as a
"[conforming] s-expr syntax" unless the readmacro currently in
force for #\( just happens to be one which gives you the "usual"
s-expr syntax.


-Rob

p.s. And, no, that's not the way you'd really do it [except for an
inflexible toy CL subset], since that makes it too hard to switch
readtables. You need to add a level of indirection:

	  ...
          obj = (*(*read_macro_table)[c])(stream, c);
	  ...

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607