ECMAScript 1 Grammar (Left Recursion Eliminated)

Modified grammar with left-recursion eliminated


Program :
SourceElements

SourceElements :
SourceElement SourceElements’

SourceElements’ :
SourceElement SourceElements’
ε

SourceElement :
Statement
FunctionDeclaration

Statement :
Block
VariableStatement
EmptyStatement
ExpressionStatement
IfStatement
IterationStatement
ContinueStatement
BreakStatement
ReturnStatement
WithStatement

Block :
{ StatementListopt }

StatementList :
Statement StatementList’

StatementList’ :
Statement StatementList’
ε

VariableStatement :
var VariableDeclarationList ;

VariableDeclarationList :
VariableDeclaration VariableDeclarationList’

VariableDeclarationList’ :
, VariableDeclaration VariableDeclarationList’
ε

VariableDeclaration :
Identifier Initializeropt
*Identifier as defined in Chapter 7 of the spec

Initializer :
= AssignmentExpression

AssignmentExpression :
ConditionalExpression
LeftHandSideExpression AssignmentOperator AssignmentExpression
*AssignmentOperator as defined in Chapter 7 of the spec

ConditionalExpression :
LogicalORExpression
LogicalORExpression ? AssignmentExpression : AssignmentExpression

LogicalORExpression :
LogicalANDExpression LogicalORExpression’

LogicalORExpression’ :
|| LogicalANDExpression LogicalORExpression’
ε

LogicalANDExpression :
BitwiseORExpression LogicalANDExpression’

LogicalANDExpression’ :
&& BitwiseORExpression LogicalANDExpression’
ε

BitwiseORExpression :
BitwiseXORExpression BitwiseORExpression’

BitwiseORExpression’ :
| BitwiseXORExpression BitwiseORExpression’
ε

BitwiseXORExpression :
BitwiseANDExpression BitwiseXORExpression’

BitwiseXORExpression’ :
^ BitwiseANDExpression BitwiseXORExpression’
ε

BitwiseANDExpression :
EqualityExpression BitwiseANDExpression’

BitwiseANDExpression’ :
& EqualityExpression BitwiseANDExpression’
ε

EqualityExpression :
RelationalExpression EqualityExpression’

EqualityExpression’ :
== RelationalExpression EqualityExpression’
!= RelationalExpression EqualityExpression’
ε

RelationalExpression :
ShiftExpression RelationalExpression’

RelationalExpression’ :
< ShiftExpression RelationalExpression’
> ShiftExpression RelationalExpression’
<= ShiftExpression RelationalExpression’
=> ShiftExpression RelationalExpression’
ε

ShiftExpression :
AdditiveExpression ShiftExpression’

ShiftExpression’ :
<< AdditiveExpression ShiftExpression’
>> AdditiveExpression ShiftExpression’
>>> AdditiveExpression ShiftExpression’
ε

AdditiveExpression :
MultiplicativeExpression AdditiveExpression’

AdditiveExpression’ :
+ MultiplicativeExpression AdditiveExpression’
- MultiplicativeExpression AdditiveExpression’
ε

MultiplicativeExpression :
UnaryExpression MultiplicativeExpression’

MultiplicativeExpression’ :
* UnaryExpression MultiplicativeExpression’
/ UnaryExpression MultiplicativeExpression’
% UnaryExpression MultiplicativeExpression’
ε

UnaryExpression :
PostfixExpression
delete UnaryExpression
void UnaryExpression
typeof UnaryExpression
++ UnaryExpression
-- UnaryExpression
+ UnaryExpression
- UnaryExpression
~ UnaryExpression
! UnaryExpression

PostfixExpression :
LeftHandSideExpression
LeftHandSideExpression [no LineTerminator here] ++
LeftHandSideExpression [no LineTerminator here] --

LeftHandSideExpression :
NewExpression
CallExpression

NewExpression :
MemberExpression
new NewExpression

MemberExpression :
PrimaryExpression MemberExpression’
new MemberExpression Arguments MemberExpression’

MemberExpression’ :
[ Expression ] MemberExpression’
. Identifier MemberExpression’
ε

PrimaryExpression :
this
Identifier
Literal
( Expression )
*Literal as defined in Chapter 7 of the spec

Expression :
AssignmentExpression Expression’

Expression’ :
, AssignmentExpression Expression’
ε

Arguments :
( )
( ArgumentList )

ArgumentList :
AssignmentExpression ArgumentList’

ArgumentList’ :
, AssignmentExpression ArgumentList’
ε

CallExpression :
MemberExpression Arguments CallExpression’

CallExpression’ :
Arguments CallExpression’
[ Expression ] CallExpression’
. Identifier CallExpression’
ε

EmptyStatement :
;

ExpressionStatement :
Expression ;

IfStatement :
if ( Expression ) Statement else Statement
if ( Expression ) Statement

IterationStatement :
while ( Expression ) Statement
for ( Expression(opt) ; Expression(opt) ; Expression(opt) ) Statement
for ( var VariableDeclarationList ; Expression(opt) ; Expression(opt) ) Statement
for ( LeftHandSideExpression in Expression ) Statement
for ( var Identifier Initializer(opt) in Expression ) Statement

ContinueStatement :
continue ;

BreakStatement :
break ;

ReturnStatement :
return [no LineTerminator here] Expression(opt) ;

WithStatement :
with ( Expression ) Statement

FunctionDeclaration :
function Identifier ( FormalParameterList(opt) ) Block

FormalParameterList :
Identifier FormalParameterList’

FormalParameterList’ :
, Identifier FormalParameterList’
ε