Exemplo n.º 1
0
        // Block IF
        ParseNode KBlockIf(ParseNode expr)
        {
            ConditionalParseNode node = new ConditionalParseNode();
            TokenID id;

            do {
                ParseNode labelNode;

                CollectionParseNode statements = new CollectionParseNode();

                SimpleToken token = _ls.GetKeyword();
                ++_blockDepth;
                while (!IsEndOfIfBlock(token.ID)) {
                    labelNode = CheckLabel();
                    if (labelNode != null) {
                        statements.Add(labelNode);
                    }
                    ParseNode subnode = Statement(token);
                    if (subnode != null) {
                        statements.Add(MarkLine());
                        statements.Add(subnode);
                    }
                    ExpectEndOfLine();
                    token = _ls.GetKeyword();
                }
                --_blockDepth;

                // Labels on terminators are valid so we need
                // to check for and add those.
                labelNode = CheckLabel();
                if (labelNode != null) {
                    statements.Add(labelNode);
                }
                node.Add(expr, statements);

                id = token.ID;
                if (id == TokenID.KELSEIF) {
                    ExpectToken(TokenID.LPAREN);
                    expr = Expression();
                    ExpectToken(TokenID.RPAREN);
                    ExpectToken(TokenID.KTHEN);
                    ExpectEndOfLine();
                } else if (id == TokenID.KELSE) {
                    // We mark the end of the sequence of IF blocks with
                    // a null expression.
                    expr = null;
                    ExpectEndOfLine();
                }
            } while(id == TokenID.KELSEIF || id == TokenID.KELSE);
            _ls.BackToken();
            ExpectToken(TokenID.KENDIF);
            return node;
        }
Exemplo n.º 2
0
 // Logical IF
 ParseNode KLogicalIf(ParseNode expr)
 {
     ConditionalParseNode node = new ConditionalParseNode();
     _parsingIf = true;
     CollectionParseNode body = new CollectionParseNode();
     body.Add(Statement(_ls.GetKeyword()));
     _parsingIf = false;
     node.Add(expr, body);
     return node;
 }
Exemplo n.º 3
0
 // 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;
 }