Re: recursive iterators

"Randall Hyde" <>
6 Apr 2002 22:39:25 -0500

          From comp.compilers

Related articles
recursive iterators (2002-03-09)
Re: recursive iterators (Randall Hyde) (2002-03-19)
Re: recursive iterators (Ray Dillinger) (2002-03-21)
Re: recursive iterators (2002-03-31)
Re: recursive iterators (Randall Hyde) (2002-04-06)
| List of all articles for this month |

From: "Randall Hyde" <>
Newsgroups: comp.compilers
Date: 6 Apr 2002 22:39:25 -0500
Organization: Prodigy Internet
References: 02-03-032 02-03-187
Keywords: design
Posted-Date: 06 Apr 2002 22:39:25 EST

Sarah Thompson wrote in message 02-03-187...
>The C++ Standard Template Library contains a number of classes (e.g.
>map, multimap, set, multiset) that are normally constructed as trees
>internally, but which provide iterators that work the way you mention.
>There is no reason in principle why an AST node class (say) couldn't
>offer iterators that make walking subtrees trivially easy, using the
>same kind of idea, e.g.:
>It is possible to see how (as I've hinted) you could define preorder,
>in order and postorder iterators. Note that STL iterators are kind-of
>scrunged to 'look like' pointers syntactically, but except in special
>cases they are often not implemented as anything remotely like a

What C++ calls "iterators" are more properly called "cursors." The
original poster mentioned 'CLU' in his message, unless the C++
run-time system has changed radically since I last took a close look,
doing true iterators in C++ without resorting to some assembly code
would be an interesting project. Furthermore, without the
corresponding "FOREACH" loop syntax, you wouldn't gain much by
creating an iterator function.

OTOH, if you *are* willing to play with some in-line assembly code and
use CPP to extend C++, it *is* possible to create true iterators in
C++ (well, "in C++" is a bit strained since it requires assembly code,
but...) I actually pulled this trick off once in Delphi (without
macros) using procedure calls, but the code was rather ugly when it
was all said and done.

Randy Hyde

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.