Exemplo n.º 1
0
        public override object VisitLoopStatement(LoopStatementContext context)
        {
            var obj    = "";
            var arr    = ((Result)Visit(context.expression()));
            var target = arr.text;
            var ids    = "";

            foreach (var(i, v) in context.loopId().WithIndex())
            {
                if (i != 0)
                {
                    ids += "," + Visit(v);
                }
                else
                {
                    ids += Visit(v);
                }
            }
            if (context.loopId().Length > 1)
            {
                ids = "(" + ids + ")";
            }
            obj += (new System.Text.StringBuilder().Append("foreach (var ").Append(ids).Append(" in ").Append(target).Append(")")).To_Str();
            obj += BlockLeft + Wrap;
            Add_current_set();
            obj += ProcessFunctionSupport(context.functionSupportStatement());
            Delete_current_set();
            obj += BlockRight + Wrap;
            return(obj);
        }
Exemplo n.º 2
0
        public override object VisitLoopStatement([NotNull] LoopStatementContext context)
        {
            var obj = "";
            var id  = "ea";

            if (context.id() != null)
            {
                id = ((Result)Visit(context.id())).text;
            }
            var it = (Iterator)Visit(context.iteratorStatement());

            obj += $"for (var {id} = {it.from.text};";
            if (it.op == ">" || it.op == ">=")
            {
                obj += $"{id} {it.op} {it.to.text};";
                obj += $"{id} -= {it.step.text})";
            }
            else
            {
                obj += $"{id} {it.op} {it.to.text};";
                obj += $"{id} += {it.step.text})";
            }

            obj += $"{Wrap} {BlockLeft} {Wrap}";
            obj += ProcessFunctionSupport(context.functionSupportStatement());
            obj += $"{BlockRight} {Terminate} {Wrap}";
            return(obj);
        }
Exemplo n.º 3
0
        public override object VisitLoopStatement(LoopStatementContext context)
        {
            var obj    = "";
            var id     = ((Result)(Visit(context.id()))).text;
            var it     = (Iterator)(Visit(context.iteratorStatement()));
            var target = (new System.Text.StringBuilder().Append("range(").Append(it.begin.text).Append(", ").Append(it.end.text).Append(", ").Append(it.step.text).Append(", ").Append(it.order).Append(", ").Append(it.close).Append(")")).to_str();

            obj += (new System.Text.StringBuilder().Append("foreach (var ").Append(id).Append(" in ").Append(target).Append(")")).to_str();
            obj += BlockLeft + Wrap;
            this.add_current_set();
            obj += ProcessFunctionSupport(context.functionSupportStatement());
            this.delete_current_set();
            obj += BlockRight + Wrap;
            if (context.loopElseStatement() != null)
            {
                var elseContent = (string)(Visit(context.loopElseStatement()));
                obj = (new System.Text.StringBuilder().Append("if (!can_range(").Append(target).Append(")) ").Append(elseContent).Append(" else ").Append(BlockLeft).Append(Wrap).Append(obj).Append(BlockRight).Append(Wrap)).to_str();
            }
            return(obj);
        }