I currently implementing a JavaScript/ECMAScript 5.1 parser with JavaCC and have problems with the ArrayLiteral production.
ArrayLiteral :
[ Elision_opt ]
[ ElementList ]
[ ElementList , Elision_opt ]
ElementList :
Elision_opt AssignmentExpression
ElementList , Elision_opt AssignmentExpression
Elision :
,
Elision ,
I have three questions, I'll ask them one by one.
I have tried to simplify/to rewrite the ArrayLiteral
production depicted above and finally arrived to the following production (pseudo-grammar):
ArrayLiteral:
"[" ("," | AssignmentExpression ",") * AssignmentExpression ? "]"
My first question: is this rewriting correct?
Two other quetsions:
- LOOKAHEADs for the JavaScript/ECMAScript array literal production
- How to implement a negative LOOKAHEAD check for a token in JavaCC?