What do you think of this iterator syntax?
Posted
by
ChaosPandion
on Programmers
See other posts from Programmers
or by ChaosPandion
Published on 2011-01-29T23:30:40Z
Indexed on
2011/01/29
23:32 UTC
Read the original article
Hit count: 388
I've been working on an ECMAScript dialect for quite some time now and have reached a point where I am comfortable adding new language features. I would love to hear some thoughts and suggestions on the syntax.
Example
iterator Numbers {
yield 1;
yield 2;
yield 3;
if (true) {
yield break;
}
yield continue iterator {
yield 4;
yield 5;
yield 6;
};
}
Syntax
IteratorDeclaration:
iterator Identifier { IteratorBody }
IteratorExpression:
iterator Identifieropt { IteratorBody }
IteratorBody:
IteratorStatementsopt
IteratorStatements:
IteratorStatement IteratorStatementsopt
IteratorStatement:
Statement but not one of BreakStatement ContinueStatement ReturnStatement
YieldStatement
YieldBreakStatement
YieldContinueStatement
YieldStatement:
yield Expression ;
YieldBreakStatement:
yield break ;
YieldContinueStatement:
yield continue Expression ;
© Programmers or respective owner