Abstract Syntax Trees

Andrew Wilkinson ajw126NO at SPAMyork.ac.uk
Wed Sep 11 07:09:38 EDT 2002


I'm having a lot of trouble trying to get the parser and compiler modules to
properly parse some files.

At the moment the trouble seems to be with any loop construct (i.e. for or

If you create a test file like this...

for i in range(10):
    print i
That'll run fine, but type this into python...

>>> import compiler
>>> compiler.parseFile(<insert name of file here>)

and you get...
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\PROGRA~2\Python22\lib\compiler\transformer.py", line 43, in
    return parse(src)
  File "C:\PROGRA~2\Python22\lib\compiler\transformer.py", line 47, in parse
    return Transformer().parsesuite(buf)
  File "C:\PROGRA~2\Python22\lib\compiler\transformer.py", line 115, in
    return self.transform(parser.suite(text))
parser.ParserError: could not parse string

I get the same thing if I replace the for loop with a while loop. A couple
of times it has parsed the for loop correctly, but that just seems to be
down to which way the wind was blowing a the time.

Does anyone know what's going on? I've only been able to test it on my
computer, so it could just be me...

I'm running Python 2.2.1

Thanks in advance,
Andrew Wilkinson

More information about the Python-list mailing list