Esempio n. 1
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;
 }
Esempio n. 2
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;
        }