[Parsing] How do I process loops with PLY?
edwin at bathysphere.org
Sun Dec 26 20:04:12 CET 2004
"F. GEIGER" <f.geiger at vol.at> writes:
> But when loops enter the game, things seem to become more difficult:
> FOR C # Exec the following lines C times
> G X=A+DX Y=B Z=34 # Move to X, Y, Z
> # more statements...
> How can I tell PLY to go back to the beginning of the FOR-loop's
> body to execute it C-1 more times? A syntax checker would not need
> to do that, but an interpreter (which actually I am building) has
Typically, you would separate parsing from executing the code. Use PLY
to parse the whole thing once and produce a data structure
representing the code (usually called an 'abstract syntax tree') then
write an interpreter which uses that tree as its input.
More information about the Python-list