Пример #1
0
        public static FuncValue TryParse(ref Source s)
        {
            const string funcName = "function";
            FuncValue    res      = null;

            if (!s.SkipIf(funcName))
            {
                s.Rollback();
                return(null);
            }

            res = new FuncValue();

            if (!ArgumentsFormal.TryParse(ref s, res))
            {
                s.Rollback();
                return(null);
            }


            Source tempSource = s.Clone();

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

            return(res);
        }
Пример #2
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);
        }
Пример #3
0
        public static StatementSequence TryParse(ref Source s)
        {
            StatementSequence res = new StatementSequence();

            Spaces.Skip(ref s);
            bool flag = s.SkipIf("{");

            while (true)
            {
                Statement st = Statement.TryParseAny(ref s);
                if (st != null)
                {
                    res.AddStatement(st);
                }
                else
                {
                    break;
                }
            }
            Spaces.Skip(ref s);
            if (flag)
            {
                if (!s.SkipIf("}"))
                {
                    return(null);
                }
            }

            return(res);
        }
Пример #4
0
 public void Parse(string str)
 {
     sourceCode = new Source(str);
     statements = StatementSequence.TryParse(ref sourceCode);
 }
Пример #5
0
 public ProgramParse()
 {
     context    = new Context(null);
     statements = new StatementSequence();
     InitPrint();
 }