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

Ian Bicking ianb at colorstudy.com
Fri Nov 1 14:42:53 EST 2002


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?

You can create a tokenizer with regular expressions, though Scheme's
tokenization rules are simple enough you could pretty much do it with
string.find.  You can't turn the tokens into a parse tree using regular
expressions, but the relation between tokens and parse trees in Scheme
is clear enough that it should be obvious how you'll do that portion.

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

  Ian





More information about the Python-list mailing list