private void _while(NakoNodeWhile node) { int labelId = GetLableId(); // (1) 条件をコードにする NakoILCode label_while_begin = createLABEL("WHILE_BEGIN" + labelId.ToString()); result.Add(label_while_begin); Write_r(node.nodeCond); // (2) コードの結果により分岐する // 分岐先をラベルとして作成 NakoILCode label_while_end = createLABEL("WHILE_END" + labelId.ToString()); addNewILCode(NakoILType.BRANCH_FALSE, label_while_end); // (3) ループブロックを書き込む _loop_check_break_continue(node.nodeBlocks, label_while_end, label_while_begin); Write_r(node.nodeBlocks); result.Add(createJUMP(label_while_begin)); result.Add(label_while_end); }
//> _while : _value WHILE _scope_or_statement //> ; private bool _while() { TokenTry(); if (!_value()) { TokenBack(); return false; } if (!Accept(NakoTokenType.WHILE)) { TokenBack(); return false; } TokenFinally(); tok.MoveNext(); calcStack.Pop(); NakoNodeWhile node_while = new NakoNodeWhile(); // condition node_while.nodeCond = lastNode; // block node_while.nodeBlocks = _scope_or_statement(); this.parentNode.AddChild(node_while); lastNode = node_while; return true; }