예제 #1
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;
 }
 /// <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;
 }
예제 #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;
        }
예제 #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;
        }
예제 #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);
        }
예제 #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);
        }
예제 #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));
            }
        }
예제 #8
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)
 {
 }
예제 #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)
 {
 }
예제 #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;
        }
예제 #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);
        }
예제 #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;
        }