I am writing a JavaScript parser, but the grammar rules for for loops is a bit confusing. From the specs:
'for' LPAREN (
(expressionNoln)? SEMI (expression)? SEMI (expression)? RPAREN statement
| 'var' variableDeclarationListNoln SEMI (expression)? SEMI (expression)? RPAREN statement
| leftHandSideExpression 'in' expression RPAREN statement
| 'var' variableDeclarationNoln 'in' expression RPAREN statement
)
I’m trying to figure out what the difference between expressionNoln and just a regular expression. And, in the process, figure out what’s going on with variableDeclartionNoln and variableDeclartionListNoln.
The only difference I’ve found is a bit further down, between relationalExpression and relationalExpressionNoln. The latter rule is missing the in operator.
Did I get that right, or am I just confused?
You are correct. I think you are confused because the ANTLR grammar has the identifier misspelled. It should be
variableDeclarationListNoInfor “no in”. ANTLR spells itNolnusing an lowercaselinstead of an uppercaseI.Removing the
infrom the expression is important to avoid an ambiguity for the special use of theinin theforstatement.BTW, your question implies that the link you give is the specification. It is not. It is a link to an example ANTLR grammar. The official standard can be found here: http://www.ecma-international.org/publications/standards/Ecma-262.htm