Sunday, February 15, 2004
the one-stack interpreter
last time the question was, how does kamin design his interpreter so that it only uses one stack? the answer: he does it by not using a stack at all! well, at least not explicitly. in the code for the lisp and scheme interpreter (and probably apl and others) expressions from the user are processed into a big parse tree, and then evaluated in place, with lots of recursion. this is exactly how version I through III of our interpreter worked.
But he does have a chapter at the end of his book, chapter 10, where he talks
about modifying the lisp interpreter to use a single stack, compiler stylz.
that is, like interpreter IV, expressions to be evaluated are pushed on to a
stack. unlike interpreter IV, variable references are handled by using
offsets within the stack. So if x
is the 2nd formal parameter of some
function, then references to it are resolved by looking at the (BLAH + 1)th
thing on the stack. 'nuff said.
quasiquotation
it's a way to quote an S-Expression except for certain parts which are to be replaced by their evaluations. quasiquotation is introduced by the backtick, `, and the bits of the S-Expression to 'unquote' are prefixed by a comma. example:-> `,x 100
-> `(,x) (100)
According to the spec, "Quasiquote forms may be nested. Substitutions are made only for unquoted components appearing at the same nesting level as the outermost backquote. The nesting level increases by one inside each successive quasiquotation, and decreases by one inside each unquotation."
the backquote/comma notation is exactly equivalent to (quasiquotation
<S-Expression>)
and (unquote <S-Expression>)
. it appears
that the 'unquote' symbol is only used as a delimiter, not as a variable bound
to a function. For instance, (quasiquotation (unquote unquote))
in guile
leads to an unbound symbol 'unquote' error.