Example #1
0
 //TODO:まだ実装できてない
 private void _try(NakoNodeTry node)
 {
     int labelId = GetLableId();
     NakoILCode label_try = createLABEL("TRY" + labelId.ToString());
     NakoILCode label_catch = createLABEL("CATCH" + labelId.ToString());
     NakoILCode label_finally = createLABEL("FINALLY" + labelId.ToString());
     // (0) Tryを埋め込む
     result.Add(label_try);
     // (1) 通常実行をコードにする
     Write_r(node.nodeTry);
     result.Add(createJUMP(label_finally));
     // (2) 例外処理
     result.Add(label_catch);
     //TODO ○○のエラーならば〜☆☆のエラーならば〜への対応
     //TODO ○○や☆☆のエラーならばへの対応
        if (node.nodeCatch != null)
     {
         Write_r(node.nodeCatch);
         result.Add(createJUMP(label_finally));
         NakoILCode c = new NakoILCode ();
         c.type = NakoILType.EXCEPTIONTABLE;
         c.value = new NakoException (label_try,label_catch,new Exception());
         result.Insert (0, c);
        }
     // (3) 最後に必ず実行する処理
     result.Add(label_finally);
     if (node.nodeFinally != null)
     {
         Write_r(node.nodeFinally);
     }
 }
Example #2
0
        private bool _try_stmt()
        {
            if (!Accept(NakoTokenType.TRY)) return false;
            tok.MoveNext(); // skip IF

            NakoNodeTry trynode = new NakoNodeTry();

            NakoToken t = tok.CurrentToken;

            while (Accept(NakoTokenType.EOL)) tok.MoveNext();

            // TRY
            trynode.nodeTry = _scope_or_statement();
            while (Accept(NakoTokenType.EOL)) tok.MoveNext();

            // CATCH
            //TODO ○○のエラーならば〜☆☆のエラーならば〜への対応
            //TODO ○○や☆☆のエラーならばへの対応
            while (Accept(NakoTokenType.CATCH))
            {
                //TODO:catchの例外種別を取得
                tok.MoveNext();//skip catch
                while (Accept(NakoTokenType.EOL)) tok.MoveNext();
                //while (calcStack.Count > 0) {
                //	calcStack.Pop ();
                //}
                NakoNode nodeCatch = _scope_or_statement();//TODO Add
                trynode.nodeCatch = nodeCatch;
            }
            //TODO set finally
            this.parentNode.AddChild(trynode);
            this.lastNode = trynode;
            return true;
        }