parsing - LOOKAHEADs for the JavaScript/ECMAScript array literal production -
parsing - LOOKAHEADs for the JavaScript/ECMAScript array literal production -
i implementing javascript/ecmascript 5.1 parser javacc , have problems arrayliteral production.
arrayliteral : [ elision_opt ] [ elementlist ] [ elementlist , elision_opt ] elementlist : elision_opt assignmentexpression elementlist , elision_opt assignmentexpression elision : , elision , i have 3 questions, i'll inquire them 1 one.
this sec one.
i have simplified production next form:
arrayliteral: "[" ("," | assignmentexpression ",") * assignmentexpression ? "]" please see first question on whether right or not:
how simplify javascript/ecmascript array literal production?
now have tried implement in javacc follows:
void arrayliteral() : { } { "[" ( "," | assignmentexpression() "," ) * ( assignmentexpression() ) ? "]" } javacc complains ambiguous , or assignmentexpression (its contents). obviously, lookahead specification required. have spent lot of time trying figure lookaheads out, tried different things like
lookahead (assignmentexpression() ",") in (...)* lookahead (assignmentexpression() "]") in (...)? and few other variations, not rid of javacc warning.
i fail understand why not work:
void arrayliteral() : { } { "[" ( lookahead ("," | assignmentexpression() ",") "," | assignmentexpression() "," ) * ( lookahead (assignmentexpression() "]") assignmentexpression() ) ? "]" } ok, assignmentexpression() per se ambiguous, trailing "," or "]" in lookaheads should create clear of choices should taken - or mistaken here?
what right lookahead specification production like?
update
this did not work, unfortunately:
void arrayliteral() : { } { "[" ( "," | lookahead (assignmentexpression() ",") assignmentexpression() "," ) * ( assignmentexpression() ) ? "]" } warning:
warning: selection conflict in (...)* build @ line 6, column 5. expansion nested within build , expansion next build have mutual prefixes, 1 of is: "function" consider using lookahead of 2 or more nested expansion. line 6 ( before first lookahead. mutual prefix "function" 1 of possible starts of assignmentexpression.
here yet approach. has advantage of identifying commas indicate undefined elements without using semantic actions.
void arrayliteral() : {} { "[" morearrayliteral() } void morearrayliteral() : {} { "]" | "," /* undefined item */ morearrayliteral() | assignmentexpression() ( "]" | "," morearrayliteral() ) } javascript parsing grammar ecmascript-5 javacc
Comments
Post a Comment