private ExpressionNode parseExpression() {
            ExpressionNode result = null;
            var restorePoint = this.createRestorePoint();
            switch (lexicalUnit) {
            case Identifier:
            case VerbatimIdentifier:
            case OpenParenthesis:
                result = parseLambdaExpression();
                break;

            case ContextualKeyword:
                if (scanner.Keyword == Keyword.From) {
                    result = parseQueryExpression();
                } else {
                    result = parseLambdaExpression();
                }
                break;
            }
            if (result != null) {
                return result;
            } else {
                this.restore(restorePoint);
            }

            result = parseConditionalExpression();
            switch (result.ExpressionKind) {
            case Conditional:
            case Binary:
                return result;
            }
            AssignOperator op = null;
            switch (lexicalUnit) {
            case Assign:
                nextLexicalUnit(true);
                op = AssignOperator.Assign;
                break;

            case AddAssign:
                nextLexicalUnit(true);
                op = AssignOperator.Add;
                break;

            case AndAssign:
                nextLexicalUnit(true);
                op = AssignOperator.And;
                break;

            case DivideAssign:
                nextLexicalUnit(true);
                op = AssignOperator.Divide;
                break;

            case LeftShiftAssign:
                nextLexicalUnit(true);
                op = AssignOperator.LeftShift;
                break;

            case ModuloAssign:
                nextLexicalUnit(true);
                op = AssignOperator.Modulo;
                break;

            case MultiplyAssign:
                nextLexicalUnit(true);
                op = AssignOperator.Multiply;
                break;

            case OrAssign:
                nextLexicalUnit(true);
                op = AssignOperator.Or;
                break;

            case SubtractAssign:
                nextLexicalUnit(true);
                op = AssignOperator.Subtract;
                break;

            case XorAssign:
                nextLexicalUnit(true);
                op = AssignOperator.Xor;
                break;

            case GreaterThan:
                switch (scanner.nextLexicalUnit()) {
                case GreaterThanOrEqual:
                    nextLexicalUnit(true);
                    op = AssignOperator.RightShift;
                    break;
                case GreaterThan:
                    if (scanner.nextLexicalUnit() != LexicalUnit.GreaterThanOrEqual) {
                        throw error(ParseErrorId.UnexpectedLexicalUnit);
                    }
                    nextLexicalUnit(true);
                    op = AssignOperator.UnsignedRightShift;
                    break;
                default:
                    throw error(ParseErrorId.UnexpectedLexicalUnit);
                }
                break;
            }
            if (op != null) {
                var assign = new AssignExpressionNode();
                copyScannerState(result, assign);
                assign.Left = result;
                assign.Operator = op;
                assign.Right = parseExpression();
                assign.EndPosition = assign.Right.EndPosition;
                result = assign;
            }
            return result;
        }
示例#2
0
 protected virtual TResult handleAssign(AssignExpressionNode assign, TSource source, bool nested)
 {
     return(defaultHandler());
 }