Exemple #1
0
        // DO statement:
        // Syntax: DO label, var=start,end
        ParseNode KDo()
        {
            if (_parsingIf) {
                _messages.Error(MessageCode.DONOTPERMITTED, "DO statement not permitted in IF statement");
                return null;
            }

            // Label.
            SymbolParseNode endLabelNode = null;

            // Can omit the end label if this will be a DO..ENDDO loop
            TokenID id = _ls.PeekKeyword();
            if (id == TokenID.INTEGER) {
                endLabelNode = ParseLabel();

                // Optional comma.
                SkipToken(TokenID.COMMA);
                id = _ls.PeekKeyword();
            }

            // Is this Do while?
            if (id == TokenID.KWHILE) {
                return KDoWhile(endLabelNode);
            }

            // Control identifier
            IdentifierToken identToken = ExpectIdentifierToken();
            if (identToken == null) {
                SkipToEndOfLine();
                return null;
            }

            LoopParseNode node = new LoopParseNode();

            Symbol symLoop = GetMakeSymbolForCurrentScope(identToken.Name);
            symLoop.IsReferenced = true;
            node.LoopVariable = new IdentifierParseNode(symLoop);
            ExpectToken(TokenID.EQUOP);

            // Loop starting value
            node.StartExpression = Expression();
            ExpectToken(TokenID.COMMA);

            // Loop ending value
            node.EndExpression = Expression();

            // Optional increment?
            SimpleToken token = _ls.GetToken();
            if (token.ID == TokenID.COMMA) {
                node.StepExpression = Expression();
            } else {
                _ls.BackToken();
            }
            ExpectEndOfLine();

            // Get the body of the loop until we see the end label.
            node.LoopBody = ParseDoBody(endLabelNode);

            // Warn if the loop will be skipped
            if (node.IterationCount() == 0) {
                _messages.Warning(MessageCode.LOOPSKIPPED, 2, "Loop will be skipped because iteration count is zero");
            }
            return node;
        }