// 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; }
// Parse the body of a standard DO or DO WHILE loop. CollectionParseNode ParseDoBody(SymbolParseNode endLabelNode) { CollectionParseNode statements = new CollectionParseNode(); bool loopDone = false; SimpleToken token = _ls.GetKeyword(); ++_blockDepth; do { ParseNode labelNode = CheckLabel(); if (labelNode != null) { statements.Add(labelNode); } if (token.ID == TokenID.KENDDO) { _messages.Warning(MessageCode.NONSTANDARDENDDO, 4, "Use of ENDDO is non-standard"); loopDone = true; break; } statements.Add(MarkLine()); ParseNode subnode = Statement(token); if (subnode != null) { statements.Add(subnode); } if (_ls.HasLabel && endLabelNode != null && _ls.Label == endLabelNode.Symbol.Name) { loopDone = true; break; } ExpectEndOfLine(); token = _ls.GetKeyword(); } while (token.ID != TokenID.ENDOFFILE); --_blockDepth; if (!loopDone) { _messages.Error(MessageCode.MISSINGDOENDLABEL, "End label for DO loop not found"); } return statements; }