Subject: Re: enumerating constants From: Erik Naggum <email@example.com> Date: 14 Oct 2002 03:55:32 +0000 Newsgroups: comp.lang.lisp Message-ID: <firstname.lastname@example.org> * Tim Daly, Jr. | I'm going through Holub's book on compilers, and working out the code in | lisp. Listing 1.1 starts out I am not familiar with the book, but the "usual" way to return tokens from the tokenizer, which I presume this is all about, is to fake dynamic types pretty badly. E.g., your tokenizer would return (the integer) SEMI and possibly some other value or write something into a pointer you passed the tokenizer. The caller would dispatch upon the "type" of the returned value to do something interesting with the token. In Common Lisp, we have real dynamic types and you may return a real object from the tokenizer. Normally, you would return an instance of any of the token classes. In the case of trivial things like symbols, return the symbol. That is, return the symbol for + and ; and whatever else your tokenizer has produced. Call `intern´ on the string you collect from the input source in the tokenization phase in the appropriate package. (If your vocabulary of symbols is restricted, you may want to use `find-symbol´ and signal or handle a syntax error at this point.) Note that you are reinventing some of the fundamentals of Common Lisp in this part of your project. Common Lisp already has the function `read´ that tokenizes and returns Common Lisp objects. You may want to study how it works before you try to do something like it. Lots of data types are available in Common Lisp that should be usable directly, such as symbol names, integers, floating-point numbers, etc. Much of the work you are about to do, if my guess about the purpose of your question is correct, will be to build the lexer/tokenizer/reader functions for your new language. If you really want to do this in Common Lisp instead of C, you should investigate the higher-level purpose of the C code. You may be very surprised at how much smaller the Common Lisp code is compared to the C code. Somebody should have written a book on compiler design in Common Lisp. -- Erik Naggum, Oslo, Norway Act from reason, and failure makes you rethink and study harder. Act from faith, and failure makes you blame someone and push harder.