private static int seekKeyWord(ref List <Token> ts, int i, string word)
 {
     while (i < ts.Count && !Syntax.IsTokenHasKeyWord(ts[i], word))
     {
         i++;
     }
     return(i);
 }
        private static int readIf(ref List <Token> ts, ref List <byte> bytes, ref List <string> vars, int i)
        {
            //if [var | has | pop | const] { ... }
            //ARGUMENT:
            Token arg = ts[i];

            switch (arg.Type)
            {
            case TknType.Number: bytes.AddCmd(CmdType.IF_C, toByte(arg.Text, inFile(ref ts, i), inLine(ref ts, i))); break;

            case TknType.Char: bytes.AddCmd(CmdType.IF_C, (byte)arg.Text[0]); break;

            case TknType.Word:
                switch (arg.Text)
                {
                case Syntax.OP_HAS: bytes.AddCmd(CmdType.IF_HAS); break;

                case Syntax.KW_POP: bytes.AddCmd(CmdType.IF_POP); break;

                default:
                    if (!vars.Contains(arg.Text))
                    {
                        new CompileException(inFile(ref ts, i), inLine(ref ts, i), ErrCode.UndefinedVariable, arg.Text);
                    }

                    bytes.AddCmd(CmdType.IF_B, (uint)getVarID(ref vars, arg.Text));
                    break;
                }
                break;

            default: new CompileException(inFile(ref ts, i), inLine(ref ts, i), ErrCode.InvalidArgument, $"'{arg.Text}' for if"); break;
            }
            //SEEK BODY ('{'):
            i++;
            while (!Syntax.IsTokenHasOperator(ts[i], Syntax.OP_BEGIN))
            {
                if (ts[i].Type != TknType.NewLine)
                {
                    new CompileException(inFile(ref ts, i), inLine(ref ts, i), ErrCode.UndefinedBody, "if");
                }
                i++;
            }
            //READ BODY:
            i = readNextBody(ref ts, ref bytes, ref vars, i) + 1;
            //SEEK ELSE:
            while (!Syntax.IsTokenHasKeyWord(ts[i], Syntax.KW_ELSE))
            {
                if (ts[i].Type != TknType.NewLine)
                {
                    break;
                }
                i++;
            }
            //IS ELSE?
            if (Syntax.IsTokenHasKeyWord(ts[i], Syntax.KW_ELSE))
            {
                bytes.AddCmd(CmdType.IF_ELSE);
                //SEEK ELSE BODY ('{'):
                i++;
                while (!Syntax.IsTokenHasOperator(ts[i], Syntax.OP_BEGIN))
                {
                    if (ts[i].Type != TknType.NewLine)
                    {
                        new CompileException(inFile(ref ts, i), inLine(ref ts, i), ErrCode.UndefinedBody, "else");
                    }
                    i++;
                }
                //READ ELSE BODY:
                i = readNextBody(ref ts, ref bytes, ref vars, i) + 1;
            }
            //END:
            bytes.AddCmd(CmdType.IF_END);

            return(i);
        }
        private static void seekProcDefs(ref List <Token> ts)
        {
            defProcs = new List <string>();

            int    L   = 1;
            string F   = "[not found]";
            int    lvl = 0;

            for (int i = 0; i < ts.Count; i++)
            {
                if (Syntax.IsTokenHasKeyWord(ts[i], Syntax.KW_PROCESS))
                {
                    if (lvl != 0)
                    {
                        new CompileException(F, L, ErrCode.ProcInProc);
                    }

                    i++;
                    if (ts[i].Type != TknType.Word)
                    {
                        new CompileException(F, L, ErrCode.ProcNameNotFound);
                    }

                    if (!Syntax.IsKeyWord(ts[i].Text))
                    {
                        addUniqueProcName(ts[i].Text);
                    }
                    else
                    {
                        new CompileException(F, L, ErrCode.KeyProc, ts[i].Text);
                    }
                    //skip args...
                    i = seekProcBodies(i, ref ts, F, ref L);
                }
                else
                {
                    if (ts[i].Type != TknType.FilePtr && ts[i].Type != TknType.NewLine && lvl == 0)
                    {
                        new CompileException(F, L, ErrCode.BadTokenArea, ts[i].Text);
                    }
                }

                if (ts[i].Type == TknType.Operator)
                {
                    if (ts[i].Text == Syntax.OP_BEGIN)
                    {
                        lvl++;
                    }
                    if (ts[i].Text == Syntax.OP_END)
                    {
                        lvl--;
                    }
                }

                if (ts[i].Type == TknType.FilePtr)
                {
                    F = ts[i].Text;
                    L = 1;
                }

                L += ts[i].Type == TknType.NewLine ? 1 : 0;
            }
        }