How To Simplify Javascript/ecmascript Array Literal Production?
I currently implementing a JavaScript/ECMAScript 5.1 parser with JavaCC and have problems with the ArrayLiteral production. ArrayLiteral : [ Elision_opt ] [ ElementList ]
Solution 1:
Yes, that correctly captures the grammar presented.
However, a better rewrite would be:
"[" AssignmentExpression ? ( "," AssignmentExpression ? ) * "]"because the rewriting in the OP is not LL(1) -- you cannot distinguish the possibilities without reading the entire AssignmentExpression -- whereas with this one you can figure out which alternative to use simply by looking at the first token.
Post a Comment for "How To Simplify Javascript/ecmascript Array Literal Production?"