Пример #1
0
        internal ForStatement(ContextScope scope, Lexer lexer) : base(scope, lexer)
        {
            // FOR ( STATEMENT; CONDEXPR; EXPR ) STATEMENT
            // FOR ( STATEMENT; CONDEXPR; EXPR ) { STATEMENT STATEMENT STATEMENT ... }
            // or
            // ASSIGNMENTEXPR

            if (lexer.TokenType == TokenEnum.FOR)
            {
                lexer.Next(); //FOR
                if (lexer.TokenType != TokenEnum.BRACKETOPEN)
                {
                    throw new ParseException(lexer, TokenEnum.BRACKETOPEN);
                }
                lexer.Next(); //BRACKETOPEN

                _scope = scope.Next;
                _begin = new Statement(_scope, lexer).Get();

                _condition = new Expression(_scope, lexer).Get();

                if (lexer.TokenType != TokenEnum.SEMICOLON)
                {
                    throw new ParseException(lexer, TokenEnum.SEMICOLON);
                }
                lexer.Next(); //SEMICOLON

                _next = new AssignmentStatement(_scope, lexer).Get();

                if (lexer.TokenType != TokenEnum.BRACKETCLOSE)
                {
                    throw new ParseException(lexer, TokenEnum.BRACKETCLOSE);
                }
                lexer.Next(); //BRACKETCLOSE

                if (lexer.TokenType == TokenEnum.BRACEOPEN)
                {
                    lexer.Next(); //BRACEOPEN
                    while (lexer.TokenType != TokenEnum.BRACECLOSE)
                    {
                        _actions.Add(new Statement(_scope, lexer).Get());
                    }
                    lexer.Next(); //BRACECLOSE
                }
                else
                {
                    _actions.Add(new Statement(scope, lexer).Get());
                }
            }
            else
            {
                _actions.Add(GetNext(scope, lexer));
            }
        }
Пример #2
0
        internal SingleStatement(ContextScope scope, Lexer lexer) : base(scope, lexer)
        {
            _statement = GetNext(scope, lexer);

            if (lexer.TokenType == TokenEnum.SEMICOLON)
            {
                lexer.Next(); // SEMICOLON
            }
            else
            {
                throw new ParseException(lexer, TokenEnum.SEMICOLON);
            }
        }
Пример #3
0
        internal Statement(ContextScope scope, Lexer lexer) : base(scope, lexer)
        {
            // IFTHENELSE

            if (lexer.TokenType != TokenEnum.NOTHING && lexer.TokenType != TokenEnum.COMMENT)
            {
                _statement = GetNext(scope, lexer);

                // comment (eliminated by lexer)
                //if (lexer.TokenType == TokenEnum.COMMENT)
                //  lexer.Next();
            }
            else
            {
                lexer.Next();
            }
        }