Regex: Parsing Lisp with Python
Thomas Guettler
zopestoller at thomas-guettler.de
Thu Aug 8 10:22:38 EDT 2002
Yigal Duppen wrote:
>>I need to parse lisp with python. Has anyone
>>experience with this?
>>
>
> Yes I do :)
> Actually, I have a program that parses Scheme, but as far as the syntax is
> concerned, that's probably OK.
>
> I used Plex for it -- much better than regular expressions for non-trivial
> tokens.
Thank you for your quick reply.
I tried it like this, but this gives me all tokens
serialized. It is hard to get the second symbol without
counting all open and close tokens. Is there a way to get
the tokens in nested lists?
((a b) c) --> [[a b] c]
I tried it like this:
import lexer
fd=open(sys.argv[1])
while 1:
line=fd.readline()
if not line:
break
tokens=lexer.tokenize(line)
print tokens
thomas
More information about the Python-list
mailing list