Exemplo n.º 1
0
        public static While TryParse(ref Source s)
        {
            const string WhileName = "while";
            While        res       = null;

            if (!s.SkipIf(WhileName))
            {
                s.Rollback();
                return(null);
            }
            res = new While();

            res.condition = Condition.TryParse(ref s);
            if (res.condition == null)
            {
                s.Rollback();
                return(null);
            }

            Source tempSource = s.Clone();

            res.body     = StatementSequence.TryParse(ref tempSource);
            s.currentPos = tempSource.currentPos;
            s.Save();

            return(res);
        }
Exemplo n.º 2
0
        public static Statement TryParseAny(ref Source s)
        {
            Spaces.Skip(ref s);

            Statement res;

            s.Save();

            res = If.TryParse(ref s);
            if (res == null)
            {
                s.Rollback();
                res = While.TryParse(ref s);
            }
            if (res == null)
            {
                s.Rollback();
                res = Return.TryParse(ref s);
            }
            if (res == null)
            {
                s.Rollback();
                res = Assignment.TryParse(ref s);
            }
            if (res == null)
            {
                s.Rollback();
                res = ExprStatement.TryParse(ref s);
            }
            if (res == null)
            {
                s.Rollback();
                s.SkipIf(";");
            }

            s.Check(res);
            return(res);
        }