[Python-ideas] Yield-from example: A parser

Antoine Pitrou solipsis at pitrou.net
Tue Feb 17 11:19:18 CET 2009


Greg Ewing <greg.ewing at ...> writes:
> 
> I hope this helps to give an idea of what I'm talking about
> with generators-as-threads. The whole parser can be seen as
> a lightweight thread, implemented as a collection of mutually
> recursive functions. Whenever any of the functions needs to
> get a token, it yields.

Perhaps that's a stupid question but what is the point of version 2 over
version 1?
If I sum it up:
- in version 1, the parsing functions pull the tokens using scanner.next() (*)
- in version 2, the parsing functions pull the tokens using "yield from"

They may be syntactically different, but semantically they look completely the
same. 

(*) by the way, using a "for" loop would probably have felt more natural

Regards

Antoine.





More information about the Python-ideas mailing list