コード例 #1
0
ファイル: Parser.cs プロジェクト: alesliehughes/olive
		//not in ecma but more clean to cut it from left hand side expr
		//group some of member expression and call expression
		private Expression ParseRightExpression (Expression expr)
		{
			Token start = current;
			while(true) {
				switch (current.Kind) {
					case Token.Type.LeftParenthesis:
						ArgumentList argumentList = ParseArgumentList ();
						expr = new InvocationExpression (expr, argumentList, Expression.Operation.Invocation, new TextSpan (start, current));
						Next ();
						break;
					case Token.Type.LeftBracket:
						Next ();
						Expression subscript = ParseExpression ();
						CheckSyntaxExpected (Token.Type.RightBracket);
						expr = new SubscriptExpression (expr, subscript, new TextSpan (start, current), new TextPoint (start.StartPosition));
						Next ();
						break;
					case Token.Type.Dot:
						Next ();
						Identifier id = null;
						if (CheckSyntaxExpected (Token.Type.Identifier))
							id = ((IdentifierToken)current).Spelling;
						expr = new QualifiedExpression (expr, id, new TextSpan (start, current), new TextPoint (start.StartPosition), new TextPoint (current.StartPosition));
						Next ();
						break;
					default:
						return expr;
				}
			}
		}
コード例 #2
0
ファイル: Parser.cs プロジェクト: alesliehughes/olive
		private Expression ParseLeftHandSideExpression ()
		{
			Token start = current;
			Expression expr;
			switch (current.Kind) {
				//primary expression
				case Token.Type.@this:
					expr = new Expression (Expression.Operation.@this, new TextSpan (current, current));
					break;
				case Token.Type.Identifier:
					expr = new IdentifierExpression ((current as IdentifierToken).Spelling, new TextSpan (current, current));
					break;
				case Token.Type.@null:
					expr = new NullExpression (new TextSpan (current, current));
					break;
				case Token.Type.@true:
					expr = new Expression (Expression.Operation.@true, new TextSpan (current, current));
					break;
				case Token.Type.@false:
					expr = new Expression (Expression.Operation.@false, new TextSpan (current, current));
					break;
				case Token.Type.NumericLiteral:
					expr = new NumericLiteralExpression (((NumericLiteralToken)current).Spelling, new TextSpan (current, current));
					break;
				case Token.Type.OctalIntegerLiteral:
					expr = new OctalLiteralExpression (((OctalIntegerLiteralToken)current).Value, new TextSpan (current, current));
					break;
				case Token.Type.HexIntegerLiteral:
					expr = new HexLiteralExpression (((HexIntegerLiteralToken)current).Value, new TextSpan (current, current));
					break;
				case Token.Type.StringLiteral:
					expr = new StringLiteralExpression ((current as StringLiteralToken).Value, (current as StringLiteralToken).Spelling, new TextSpan (current, current));
					break;
				case Token.Type.LeftBracket:
					expr = ParseArrayLiteral ();
					break;
				case Token.Type.LeftBrace:
					expr = ParseObjectLiteral ();
					break;
				case Token.Type.LeftParenthesis:
					Next ();
					expr = new UnaryOperatorExpression(ParseExpression (), Expression.Operation.Parenthesized, new TextSpan(current,current));
					CheckSyntaxExpected (Token.Type.RightParenthesis);
					break;
				//end primary
				case Token.Type.function:
					expr = new FunctionExpression (ParseFunctionDefinition ());
					break;
				case Token.Type.@new:
					Next ();
					Expression target = ParseExpression ();
					ArgumentList arguments;
					if (current.Kind == Token.Type.LeftParenthesis) {
						arguments = this.ParseArgumentList ();
					} else {
						arguments = new ArgumentList (new List<ExpressionListElement> (), new TextSpan (start, current));
					}
					expr = new InvocationExpression (target, arguments,Expression.Operation.@new, new TextSpan(start,current));
					break;
				default:
					SyntaxError.Add ("Expression start with a strange token :" + current.Kind.ToString ());
					return new Expression (Expression.Operation.SyntaxError, new TextSpan (start, current));
			}
			Next (); // to go ahead for other part
			return ParseRightExpression (expr);
		}