Exemple #1
0
        public override IAst Parse(Token raw)
        {
            var re = new LoopStmt();

            if (raw.RawHeader.Split(' ').Length == 2)//counted
            {
                if (char.IsDigit(raw.RawHeader.Split(' ').Last()[0]))
                {
                    re.LoopType = LoopType.CountedLoop;
                    re.CountedLoop = IAst.ParseToken(raw.RawHeader.Split(' ').Last())[0];
                }
            }
            else
            {

                if (raw.RawHeader.Trim() == "loop")//infinitloop
                {
                    re.LoopType = LoopType.InfinitLoop;
                }
                else
                {
                    if (raw.RawHeader.Trim().Split(' ')[2] == "to")//ForLoop
                    {
                        re.LoopType = LoopType.ForLoop;
                        var parts = raw.RawHeader.Trim().Split(' ');
                        re.VarName = parts[1];
                        re.CountedLoop = IAst.ParseToken(parts[3])[0];
                        //todo: step
                    }
                    else
                    {
                        if (raw.RawHeader.Trim().Split(' ')[2] == "in")//ForLoop
                        {
                            re.LoopType = LoopType.Foreachloop;
                            var parts = raw.RawHeader.Trim().Split(' ');
                            re.VarName = parts[1];
                            re.CollectionName = IAst.ParseToken(parts[3])[0];
                            
                        }
                    }
                }
            }
           


            foreach (var i in raw.Body)
            {
                re.Body.AddRange(IAst.ParseToken(i));
            }

            return re;
        }
Exemple #2
0
        public override IAst Parse(Token raw)
        {
            var re = new LoopStmt();

            if (raw.RawHeader.Split(' ').Length == 2)//counted
            {
                if (char.IsDigit(raw.RawHeader.Split(' ').Last()[0]))
                {
                    re.LoopType    = LoopType.CountedLoop;
                    re.CountedLoop = IAst.ParseToken(raw.RawHeader.Split(' ').Last())[0];
                }
            }
            else
            {
                if (raw.RawHeader.Trim() == "loop")//infinitloop
                {
                    re.LoopType = LoopType.InfinitLoop;
                }
                else
                {
                    if (raw.RawHeader.Trim().Split(' ')[2] == "to")//ForLoop
                    {
                        re.LoopType = LoopType.ForLoop;
                        var parts = raw.RawHeader.Trim().Split(' ');
                        re.VarName     = parts[1];
                        re.CountedLoop = IAst.ParseToken(parts[3])[0];
                        //todo: step
                    }
                    else
                    {
                        if (raw.RawHeader.Trim().Split(' ')[2] == "in")//ForLoop
                        {
                            re.LoopType = LoopType.Foreachloop;
                            var parts = raw.RawHeader.Trim().Split(' ');
                            re.VarName        = parts[1];
                            re.CollectionName = IAst.ParseToken(parts[3])[0];
                        }
                    }
                }
            }



            foreach (var i in raw.Body)
            {
                re.Body.AddRange(IAst.ParseToken(i));
            }

            return(re);
        }