C++, using Generators
Declaration of simple range generator:
$generator(range)
{
int i;
int _max;
int _min;
range(int minv, int maxv):_max(maxv),_min(minv) {}
$emit(int) // will emit int values. Start of body of the generator.
for (i = _min; i <= _max; ++i)
$yield(i);
$stop;
};
Its usage:
range r10(1,10);
for(int n; r10(n);)
printf("%d\n",n);
Will output
1
2
...
10