Macros in Python, and using reg exps to build a scheme interpreter

Matthew Knepley knepley at mcs.anl.gov
Sat Nov 2 13:12:39 EST 2002


>>>>> "IB" == Ian Bicking <ianb at colorstudy.com> writes:

  IB> On Thu, 2002-10-31 at 14:46, Peter L. Markowsky wrote:
  >> Currently in one of my classes I'm building a scheme interpreter in Java. This has brought two questions to
  >> mind. First does python use language macros to define higher level functionality. And two does anyone know a good
  >> place to look for how to implement a scheme parser using regular expressions?

  IB> You can create a tokenizer with regular expressions, though Scheme's tokenization rules are simple enough you
  IB> could pretty much do it with string.find.  You can't turn the tokens into a parse tree using regular expressions,
  IB> but the relation between tokens and parse trees in Scheme is clear enough that it should be obvious how you'll do
  IB> that portion.
  This is possible, but I would say that it is (in my opinion) more elegant, and certainly just as easy to write
  the parser using PLY (Python Lex-Yacc) from David Beazley, http://systems.cs.uchicago.edu/ply. It has a great
  design which makes is really easy to do these kinds of things (making use of Python's reflection capabilities).

         Matt

  IB> I.e., you'll want to tokenize the expression (cons "a" 'a) into something like: [('symbol', '('), ('identifier',
  IB> 'cons'), ('string', 'a'), ('symbol', "'"), ('identifier', 'a'), ('symbol', ')')], and then turn that into
  IB> something more sensible.

  IB>   Ian



-- 
"Failure has a thousand explanations. Success doesn't need one" -- Sir Alec Guiness



More information about the Python-list mailing list