Copyright © 2003-2005, Peter Seibel
30. Practical: An HTML Generation Library, the Interpreter
In this chapter and the next you’ll take a look under the hood of the FOO HTML generator that you’ve been using in the past few chapters. FOO is an example of a kind of programming that’s quite common in Common Lisp and relatively uncommon in non-Lisp languages, namely, language-oriented programming. Rather than provide an API built primarily out of functions, classes, and macros, FOO provides language processors for a domain-specific language that you can embed in your Common Lisp programs.
FOO provides two language processors for the same s-expression language. One is an interpreter that takes a FOO “program” as data and interprets it to generate HTML. The other is a compiler that compiles FOO expressions, possibly with embedded Common Lisp code, into Common Lisp that generates HTML and runs the embedded code. The interpreter is exposed as the function emit-html
and the compiler as the macro html
, which you used in previous chapters.
In this chapter you’ll look at some of the infrastructure shared between the interpreter and the compiler and then at the implementation of the interpreter. In the next chapter, I’ll show you how the compiler works.