/// <summary>
 /// Create a new statement node.
 /// </summary>
 /// <param name="parent">The parent node that defines the statement.</param>
 protected StatementNode(IStatementParentNode parent)
 {
     #if DEBUG
     if (parent == null)
         throw new ArgumentNullException("parent");
     #endif
     this.Parent = parent;
 }
 /// <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;
 }
Beispiel #3
0
        /// <summary>
        /// Create a new statement node.
        /// </summary>
        /// <param name="parent">The parent node that defines the statement.</param>
        protected StatementNode(IStatementParentNode parent)
        {
#if DEBUG
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
#endif
            this.Parent = parent;
        }
Beispiel #4
0
        /// <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;
        }
Beispiel #5
0
        protected virtual StatementSequenceNode ParseStatementSequence(IStatementParentNode parent, Token token)
        {
            // PARSE: (<expression> ['.' [<statements>]])
            StatementSequenceNode result = new StatementSequenceNode(parent);

            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;
            }
            else
            {
                result.SetContents(expression, null, null);
                this.ResidueToken = token;
                return(result);
            }

            // ['.' [<statements>]])
            token = this.GetNextTokenxx(Preference.NegativeSign);
            if (token is EofToken)
            {
                result.SetContents(expression, period, null);
                this.ResidueToken = token;
                return(result);
            }
            if (Parser.IsBlockEndDelimiter(token))
            {
                result.SetContents(expression, period, null);
                this.ResidueToken = token;
                return(result);
            }
            else if (Parser.IsStatementDelimiter(token))
            {
                this.ReportParserError(result, SemanticErrors.MissingStatement, token);
                result.SetContents(expression, period, null);
                this.ResidueToken = token;
                return(result);
            }

            StatementNode nextStatement = this.ParseStatement(result, token);

            result.SetContents(expression, period, nextStatement);
            return(result);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        protected virtual StatementNode ParseStatement(IStatementParentNode parent, Token token)
        {
            // PARSE: <statements> ::=
            //      (<return statement> ['.'] ) |
            //      (<expression> ['.' [<statements>]])

            if ((token is EofToken) || Parser.IsBlockEndDelimiter(token))
            {
                this.ResidueToken = token;
                return(null);
            }

            if (token is ReturnOperatorToken)
            {
                return(this.ParseReturnStatement(parent, (ReturnOperatorToken)token));
            }
            else
            {
                return(this.ParseStatementSequence(parent, token));
            }
        }
 /// <summary>
 /// Create and initialize a new statement node.
 /// </summary>
 /// <param name="parent">Parent node that defines the statement.</param>
 protected internal StatementSequenceNode(IStatementParentNode parent)
     : base(parent)
 {
 }
Beispiel #9
0
 /// <summary>
 /// Create and initialize a new statement node.
 /// </summary>
 /// <param name="parent">Parent node that defines the statement.</param>
 protected internal StatementSequenceNode(IStatementParentNode parent)
     : base(parent)
 {
 }
Beispiel #10
0
        protected virtual StatementSequenceNode ParseStatementSequence(IStatementParentNode parent, Token token)
        {
            // PARSE: (<expression> ['.' [<statements>]])
            StatementSequenceNode result = new StatementSequenceNode(parent);

            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;
            }
            else
            {
                result.SetContents(expression, null, null);
                this.ResidueToken = token;
                return result;
            }

            // ['.' [<statements>]])
            token = this.GetNextTokenxx(Preference.NegativeSign);
            if (token is EofToken)
            {
                result.SetContents(expression, period, null);
                this.ResidueToken = token;
                return result;
            }
            if (Parser.IsBlockEndDelimiter(token))
            {
                result.SetContents(expression, period, null);
                this.ResidueToken = token;
                return result;
            }
            else if (Parser.IsStatementDelimiter(token))
            {
                this.ReportParserError(result, SemanticErrors.MissingStatement, token);
                result.SetContents(expression, period, null);
                this.ResidueToken = token;
                return result;
            }

            StatementNode nextStatement = this.ParseStatement(result, token);
            result.SetContents(expression, period, nextStatement);
            return result;
        }
Beispiel #11
0
        protected virtual StatementNode ParseStatement(IStatementParentNode parent, Token token)
        {
            // PARSE: <statements> ::=
            //      (<return statement> ['.'] ) |
            //      (<expression> ['.' [<statements>]])

            if ((token is EofToken) || Parser.IsBlockEndDelimiter(token))
            {
                this.ResidueToken = token;
                return null;
            }

            if (token is ReturnOperatorToken)
                return this.ParseReturnStatement(parent, (ReturnOperatorToken)token);
            else
                return this.ParseStatementSequence(parent, token);
        }
Beispiel #12
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;
        }