Well, there are lots of "do x" libs that I don't think a C programmer could easily copy, but hey, we're all Turing complete here. But for a long time, this sort of meta-programming where you write the program at the high level to generate the code at the low level for you, was basically a proprietary superpower for Lisp. Other languages provide similar capabilities now, though sometimes not so general in ability. I suspect that's a big part of why Lisp was so popular for so long. But the nice part of doing it that way is that you retain the full Lisp system your generated blobs of "machine-level Lisp" are still just another Lisp object, so you can take your generated functions and single-step it in interpretation, or transform it further. Not so different from the usual parser generator technique. The end result was probably only a few times slower than doing the recognizers directly in C. The Lisp program then compiles that definition into to a low-level sequence of unboxed boolean and arithmetic ops and conditionals in Lisp which, being primitives with direct machine code equivalents, the Lisp compiler can translate into reasonable machine code. One describes the language to be parsed, in a high and abstract level in a DSL in Lisp. With a good compiler, using unboxed values and primitive arithmetic and Boolean operations on ints, most code will compile to not much slower than the C version.įor example, I just saw an old paper where the author implements dynamic compilation from Lisp, to Lisp, in Lisp, for parsers.
0 Comments
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |