/// <summary>
 /// Exit a parse tree produced by <see cref="DDD_layout_scriptParser.range_and_step"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitRange_and_step([NotNull] DDD_layout_scriptParser.Range_and_stepContext context)
 {
 }
Example #2
0
        /* Megnézzük, hogy érvényes-e a külön-külön és együtt a range és a step.
         *
         * Ha nem, akkor nullt adunk vissza, hogy a for ciklus ne futhasson. És hibát írunk ki.
         * Különben egy háromelemű tuple-t adunk vissza, kezdet vég és step intekkel.
         * Így ha esetleg valamelyik ezek közül float-lenne, annak az alsó egészrészét vesszük és warningot kap a programozó.
         */
        public override object VisitRange_and_step([NotNull] DDD_layout_scriptParser.Range_and_stepContext context)
        {
            var     operations = context.operation();
            dynamic rangeStart = VisitOperation(operations[0]);
            dynamic rangeEnd   = VisitOperation(operations[1]);
            dynamic step       = 1;

            if (context.STEP() != null)
            {
                step = VisitOperation(operations[2]);
            }

            // ha bármelyik nem int vagy float, akkor ott hiba van
            if (!(rangeStart is double || rangeStart is int) || !(rangeEnd is double || rangeEnd is int) || !(step is int || step is double))
            {
                alerts.Add(new error(context.Start.Line, "Range and step can only hold Int or Float values"));
                return(null);
            }

            if (rangeStart is double)
            {
                alerts.Add(new warning(context.Start.Line, "The start of the range is casted from Float to Int. You may ignore this warning"));
                rangeStart = (int)rangeStart;
            }

            if (rangeEnd is double)
            {
                alerts.Add(new warning(context.Start.Line, "The end of the range is casted from Float to Int. You may ignore this warning"));
                rangeEnd = (int)rangeEnd;
            }

            if (step is double)
            {
                alerts.Add(new warning(context.Start.Line, "The step is casted from Float to Int. You may ignore this warning"));
                step = (int)step;
            }

            if (context.BRACKET_O() != null)
            {
                rangeStart += (step > 0) ? 1 : -1;
            }

            if (context.BRACKET_C() != null)
            {
                rangeEnd -= (step > 0) ? 1 : -1;
            }

            if (step == 0)
            {
                alerts.Add(new error(context.Start.Line, "Step was 0. This would cause an infinite loop"));
                return(null);
            }

            if ((step > 0 && rangeEnd - rangeStart < 0) || (step < 0 && rangeEnd - rangeStart > 0))
            {
                alerts.Add(new error(context.Start.Line, $"Infinite loop. [Range: {rangeStart}..{rangeEnd}, Step: {step}]"));
                return(null);
            }

            return(new Tuple <int, int, int>(rangeStart, rangeEnd, step));
        }
Example #3
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="DDD_layout_scriptParser.range_and_step"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitRange_and_step([NotNull] DDD_layout_scriptParser.Range_and_stepContext context)
 {
     return(VisitChildren(context));
 }