Ejemplo n.º 1
0
        public override MultilineStatement Interprete(string src)
        {
            string main     = "";
            string elsemain = "";
            bool   tmp      = false;

            for (int index = 0;
                 index < src.Split(new[] { '\n', ';' }, StringSplitOptions.RemoveEmptyEntries).Length;
                 index++)
            {
                string i = src.Split(new[] { '\n', ';' }, StringSplitOptions.RemoveEmptyEntries)[index];
                if (Parser.Grammar.GetPattern("else").IsValid(i.TrimEnd(' ').TrimStart(' ')))
                {
                    tmp   = true;
                    main += i + ";\n";
                }
                else if (tmp == false)
                {
                    main += i + ";\n";
                }
                else if (tmp)
                {
                    elsemain += i + ";\n";
                }
            }
            src = main;

            var    returns = new IfStmt();
            string temp    = "";

            for (int index = 0;
                 index < src.Split(new[] { '\n', ';' }, StringSplitOptions.RemoveEmptyEntries).Length;
                 index++)
            {
                string i = src.Split(new[] { '\n', ';' }, StringSplitOptions.RemoveEmptyEntries)[index];
                if (index == 0)
                {
                    returns.Header = i;
                }
                else if (index > 0 &&
                         index < src.Split(new[] { '\n', ';' }, StringSplitOptions.RemoveEmptyEntries).Length - 1)
                {
                    temp += i + ";\n";
                    ;
                }
            }
            returns.Statements     = Parser.ParseCodeBlock(temp, "").Nodes;
            returns.ElseStatements = Parser.ParseCodeBlock(elsemain, "").Nodes;
            return(returns);
        }
Ejemplo n.º 2
0
        public override MultilineStatement Interprete(string src)
        {
            string main = "";
            string elsemain = "";
            bool tmp = false;
            for (int index = 0;
                index < src.Split(new[] { '\n', ';' }, StringSplitOptions.RemoveEmptyEntries).Length;
                index++)
            {
                string i = src.Split(new[] { '\n', ';' }, StringSplitOptions.RemoveEmptyEntries)[index];
                if (Parser.Grammar.GetPattern("else").IsValid(i.TrimEnd(' ').TrimStart(' ')))
                {
                    tmp = true;
                    main += i + ";\n";
                }
                else if (tmp == false)
                {
                    main += i + ";\n";
                }
                else if (tmp)
                {
                    elsemain += i + ";\n";
                }
            }
            src = main;

            var returns = new IfStmt();
            string temp = "";
            for (int index = 0;
                index < src.Split(new[] { '\n', ';' }, StringSplitOptions.RemoveEmptyEntries).Length;
                index++)
            {
                string i = src.Split(new[] { '\n', ';' }, StringSplitOptions.RemoveEmptyEntries)[index];
                if (index == 0)
                {
                    returns.Header = i;
                }
                else if (index > 0
                         && index < src.Split(new[] { '\n', ';' }, StringSplitOptions.RemoveEmptyEntries).Length - 1)
                {
                    temp += i + ";\n";
                    ;
                }
            }
            returns.Statements = Parser.ParseCodeBlock(temp, "").Nodes;
            returns.ElseStatements = Parser.ParseCodeBlock(elsemain, "").Nodes;
            return returns;
        }