/// <summary>
 /// Create and initialize a new return statement node.
 /// </summary>
 /// <param name="parent">The parent node that defines the statement.</param>
 /// <param name="token">The up-arrow return operator.</param>
 protected internal ReturnStatementNode(IStatementParentNode parent, ReturnOperatorToken token)
     : base(parent)
 {
     #if DEBUG
     if (token == null)
         throw new ArgumentNullException("token");
     #endif
     this.Token = token;
 }
예제 #2
0
        protected virtual ReturnStatementNode ParseReturnStatement(IStatementParentNode parent, ReturnOperatorToken returnOperator)
        {
            // PARSE: <return statement> ::= returnOperator <expression>
            // Also: <statements> ::= <return statement> [’.’]
            ReturnStatementNode result = new ReturnStatementNode(parent, returnOperator);

            Token token = this.GetNextTokenxx(Preference.NegativeSign);
            ExpressionNode expression = this.ParseExpression(result, token);
            if (expression == null)
                this.ReportParserError(result, SemanticErrors.MissingExpression, token);

            SpecialCharacterToken period = null;
            token = this.GetNextTokenxx(Preference.Default);
            if (Parser.IsStatementDelimiter(token))
            {
                period = (SpecialCharacterToken)token;
                token = this.GetNextTokenxx(Preference.Default);
            }

            result.SetContents(expression, period);

            // Returns statement ... should have reached the end of the statement.
            this.ResidueToken = token;
            if (token is EofToken)
                return result; // OK
            else if (Parser.IsBlockEndDelimiter(token))
                return result; // OK;
            else if (Parser.IsStatementDelimiter(token))
                this.ReportParserError(result, SemanticErrors.MissingStatement, token);
            else
                this.ReportParserError(result, SemanticErrors.CodeAfterReturnStatement, token);
            return result;
        }