Inheritance: Microsoft.R.Core.AST.Functions.FunctionDefinition, IStatement
Exemplo n.º 1
0
        /// <summary>
        /// Abstract factory
        /// </summary>
        public static IStatement CreateStatement(ParseContext context, IAstNode parent)
        {
            RToken     currentToken = context.Tokens.CurrentToken;
            string     keyword      = context.TextProvider.GetText(currentToken);
            IStatement statement    = null;

            switch (keyword)
            {
            case "if":
                statement = new If();
                break;

            case "for":
                statement = new For();
                break;

            case "while":
                statement = new KeywordExpressionScopeStatement();
                break;

            case "repeat":
                statement = new KeywordScopeStatement(allowsSimpleScope: false);
                break;

            case "break":
            case "next":
                statement = new KeywordStatement();
                break;

            case "function":
                statement = new FunctionStatement();
                break;

            default:
                context.AddError(new ParseError(ParseErrorType.UnexpectedToken, ErrorLocation.Token, currentToken));
                break;
            }

            return(statement);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Abstract factory
        /// </summary>
        public static IStatement CreateStatement(ParseContext context, IAstNode parent) {
            RToken currentToken = context.Tokens.CurrentToken;
            string keyword = context.TextProvider.GetText(currentToken);
            IStatement statement = null;

            switch (keyword) {
                case "if":
                    statement = new If();
                    break;

                case "for":
                    statement = new For();
                    break;

                case "while":
                    statement = new KeywordExpressionScopeStatement();
                    break;

                case "repeat":
                    statement = new KeywordScopeStatement(allowsSimpleScope: false);
                    break;

                case "break":
                case "next":
                    statement = new KeywordStatement();
                    break;

                case "function":
                    statement = new FunctionStatement();
                    break;

                default:
                    context.AddError(new ParseError(ParseErrorType.UnexpectedToken, ErrorLocation.Token, currentToken));
                    break;
            }

            return statement;
        }