示例#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;
        }
示例#2
0
        // Parse a DO WHILE loop construct
        ParseNode KDoWhile(SymbolParseNode endLabelNode)
        {
            LoopParseNode node = new LoopParseNode();

            ExpectToken(TokenID.KWHILE);
            ExpectToken(TokenID.LPAREN);
            node.StartExpression = Expression();
            ExpectToken(TokenID.RPAREN);
            ExpectEndOfLine();
            node.LoopBody = ParseDoBody(endLabelNode);

            if (node.StartExpression.IsConstant && !node.StartExpression.Value.BoolValue) {
                _messages.Warning(MessageCode.LOOPSKIPPED, 2, "Loop will be skipped because the expression is false");
            }
            return node;
        }
示例#3
0
        // Parse an implied do.
        ParseNode ParseImpliedDo()
        {
            LoopParseNode node = new LoopParseNode();

            // The first element of an implied DO loop is an expression
            // which uses the loop variable as an operand.
            node.LoopValue = ParseExpressionWithImpliedDo();
            ExpectToken(TokenID.COMMA);

            // Control identifier
            node.LoopVariable = ParseBasicIdentifier();

            // Range. This is:
            //  start, end [,step]
            // where step defaults to 1 if omitted
            ExpectToken(TokenID.EQUOP);
            node.StartExpression = Expression();
            ExpectToken(TokenID.COMMA);
            node.EndExpression = Expression();
            if (_ls.PeekToken().ID == TokenID.COMMA) {
                ExpectToken(TokenID.COMMA);
                node.StepExpression = Expression();
            }
            ExpectToken(TokenID.RPAREN);
            return node;
        }