// Parse a left hand side expression. private JNode LeftHandSideExpression() { JNode expr = MemberExpression(); JNode expr2; while(token == JSToken.LeftParen || token == JSToken.LeftBracket || token == JSToken.AccessField) { if(token == JSToken.LeftParen) { // Parse a function call expression. NextToken(); expr2 = ArgumentList(); if(token == JSToken.RightParen) { if(IsBuiltinCall(expr, "eval")) { expr = new JEval (Context.BuildRange (expr.context, tokenInfo), expr2); } else if(IsBuiltinCall(expr, "print") && printSupported) { expr = new JPrint (Context.BuildRange (expr.context, tokenInfo), expr2); } else { expr = new JCall (Context.BuildRange(expr.context, tokenInfo), expr, expr2); } NextToken(); } else { SyntaxError("`)' expected"); } } else if(token == JSToken.LeftBracket) { // Parse an array access expression. NextToken(); expr2 = Expression(); if(token == JSToken.RightBracket) { expr = new JArrayAccess (Context.BuildRange(expr.context, tokenInfo), expr, expr2); NextToken(); } else { SyntaxError("`]' expected"); } } else { // Parse a field access expression. NextToken(); if(token == JSToken.Identifier) { expr = new JFieldAccess (Context.BuildRange(expr.context, tokenInfo), expr, scanner.GetIdentifierName()); NextToken(); } else { SyntaxError("identifier expected"); } } } return expr; }
// Parse a member expression. private JNode MemberExpression() { JNode expr = null; JNode expr2; Context save; switch(token) { case JSToken.Function: { // Inline function definition. expr = FunctionExpression(); } break; case JSToken.New: { // Object construction, with arguments. save = tokenInfo.MakeCopy(); NextToken(); expr = MemberExpression(); if(token == JSToken.LeftParen) { NextToken(); expr2 = Arguments(); if(token == JSToken.RightParen) { expr = new JNew(Context.BuildRange (save, tokenInfo), expr, expr2); NextToken(); } else { SyntaxError("`)' expected"); } } else { expr = new JNew(Context.BuildRange (save, expr.context), expr, null); } } break; default: { // Parse a primary expression. expr = PrimaryExpression(); } break; } while(token == JSToken.LeftBracket || token == JSToken.AccessField) { if(token == JSToken.LeftBracket) { // Parse an array access expression. NextToken(); expr2 = Expression(); if(token == JSToken.RightBracket) { expr = new JArrayAccess (Context.BuildRange(expr.context, tokenInfo), expr, expr2); NextToken(); } else { SyntaxError("`]' expected"); } } else { // Parse a field access expression. NextToken(); if(token == JSToken.Identifier) { expr = new JFieldAccess (Context.BuildRange(expr.context, tokenInfo), expr, scanner.GetIdentifierName()); NextToken(); } else { SyntaxError("identifier expected"); } } } return expr; }