Javascript grammar

Russell Shaw <rjshaw@netspace.net.au>
25 Feb 2007 13:23:00 -0500

          From comp.compilers

Related articles
Javascript grammar rjshaw@netspace.net.au (Russell Shaw) (2007-02-25)
Re: Javascript grammar rjshaw@netspace.net.au (Russell Shaw) (2007-02-25)
| List of all articles for this month |

From: Russell Shaw <rjshaw@netspace.net.au>
Newsgroups: comp.compilers
Date: 25 Feb 2007 13:23:00 -0500
Organization: Compilers Central
Keywords: parse, question
Posted-Date: 25 Feb 2007 13:23:00 EST

Hi,
I downloaded and inspected the Ecmascript-262 grammar on page 157:

http://www.ecma-international.org/publications/standards/Ecma-262.htm
http://www.ecma-international.org/publications/files/ecma-st/ECMA-262.pdf

I found a reduce-reduce conflict in that the kernels for "FunctionExpression"
and "FunctionDeclaration" both start from the same LALR state (state 0), and
can consist of an identical sequence of symbols:

FunctionDeclaration ->
                'function' '<Identifier>' '(' FormalParameterList_opt ')' '{' FunctionBody '}'

FunctionExpression ->
                'function' '<Identifier_opt>' '(' FormalParameterList_opt ')' '{' FunctionBody '}'

and have these lookaheads in common: ++ -- ; [ ( + -

(I think my tool is correct from manually looking through the grammar)

Is it an accepted way of tolerating a reduce-reduce conflict by detecting
unsuitable reductions in the symantic analysis?

The list of relevant productions are:

************************************************************************************

Program ->
                SourceElements

SourceElements ->
                SourceElement |
                SourceElements SourceElement

SourceElement ->
                Statement |
                FunctionDeclaration

FunctionDeclaration ->
                'function' '<Identifier>' '(' FormalParameterList_opt ')' '{' FunctionBody '}'

Statement ->
                  Block |
                  VariableStatement |
                  EmptyStatement |
                  ExpressionStatement |
                  IfStatement |
                  IterationStatement |
                  ContinueStatement |
                  BreakStatement |
                  ReturnStatement |
                  WithStatement |
                  LabelledStatement |
                  SwitchStatement |
                  ThrowStatement |
                  TryStatement

ExpressionStatement ->
                  Expression ';'

Expression ->
                AssignmentExpression |
                Expression ',' AssignmentExpression

AssignmentExpression ->
                ConditionalExpression |
                LeftHandSideExpression '<AssignmentOperator>' AssignmentExpression

LeftHandSideExpression ->
                NewExpression |
                CallExpression

NewExpression ->
                MemberExpression |
                'new' NewExpression

MemberExpression ->
                PrimaryExpression |
                FunctionExpression |
                MemberExpression '[' Expression ']' |
                MemberExpression '.' '<Identifier>' |
                'new' MemberExpression Arguments

FunctionExpression ->
                'function' '<Identifier_opt>' '(' FormalParameterList_opt ')' '{' FunctionBody '}'


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.