Beispiel #1
0
		private Expression ParsePostfixExpression ()
		{
			Expression expr = ParseLeftHandSideExpression ();
			
			switch (current.Kind) {
				case Token.Type.PlusPlus :
					expr = new UnaryOperatorExpression (expr, Expression.Operation.PostfixPlusPlus, new TextSpan (expr.Location.StartLine, expr.Location.StartColumn, current.StartLine, current.StartColumn + current.Width, expr.Location.StartPosition, current.StartPosition+current.Width));
					Next ();
					break;
				case Token.Type.MinusMinus:
					expr = new UnaryOperatorExpression (expr, Expression.Operation.PostfixMinusMinus, new TextSpan (expr.Location.StartLine, expr.Location.StartColumn, current.StartLine, current.StartColumn + current.Width, expr.Location.StartPosition, current.StartPosition + current.Width));
					Next ();
					break;
			}
			return expr;
		}
Beispiel #2
0
		private Expression ParseUnaryExpression (bool noIn)
		{
			Token start = current;
			Expression expr;
			// get by first token
			switch (current.Kind) {
				case Token.Type.delete:
					Next ();
					expr = new UnaryOperatorExpression (this.ParseExpression (noIn), Expression.Operation.delete, new TextSpan (start, current));
					break;
				case Token.Type.@void:
					Next ();
					expr = new UnaryOperatorExpression (this.ParseExpression (noIn), Expression.Operation.@void, new TextSpan (start, current));
					break;
				case Token.Type.@typeof:
					Next (); 
					expr = new UnaryOperatorExpression (this.ParseExpression (noIn), Expression.Operation.@typeof, new TextSpan (start, current));
					break;
				case Token.Type.PlusPlus:
					Next ();
					expr = new UnaryOperatorExpression (this.ParseExpression (noIn), Expression.Operation.PrefixPlusPlus, new TextSpan (start, current));
					break;
				case Token.Type.MinusMinus:
					Next ();
					expr = new UnaryOperatorExpression (this.ParseExpression (noIn), Expression.Operation.PrefixMinusMinus, new TextSpan (start, current));
					break;
				case Token.Type.Plus:
					Next ();
					expr = new UnaryOperatorExpression (this.ParseExpression (noIn), Expression.Operation.PrefixPlus, new TextSpan (start, current));
					break;
				case Token.Type.Minus:
					Next ();
					expr = new UnaryOperatorExpression (this.ParseExpression (noIn), Expression.Operation.PrefixMinus, new TextSpan (start, current)); 
					break;
				case Token.Type.Tilda:
					Next ();
					expr = new UnaryOperatorExpression (this.ParseExpression (noIn), Expression.Operation.Tilda, new TextSpan (start, current));
					break;
				case Token.Type.Bang:
					Next ();
					expr = new UnaryOperatorExpression (this.ParseExpression (noIn), Expression.Operation.Bang, new TextSpan (start, current));
					break;
				default:
					expr = ParsePostfixExpression ();
					break;
			}
			//Next (); //go ahead
			return expr;
		}
Beispiel #3
0
		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);
		}