Пример #1
0
        protected virtual void ProcessTimeCommand()
        {
            DmlSyntaxError badTimeCommand = DmlSyntaxError.BadTimeCommandSyntax();

            ProcessExpression(GetUntil(DmlTokens.LANGLE));

            string jumpName = String.Format("#{0:X6}", Globals.randGen.Next(0x1000000));

            Instructions.Add(new JumpIfFalse(jumpName));

            Advance(exception: badTimeCommand);

            int angleDepth = 0;

            while (!Done)
            {
                if (DmlTokens.IsMatch(CurrentToken, DmlTokens.LANGLE))
                {
                    angleDepth++;
                }
                else if (DmlTokens.IsMatch(CurrentToken, DmlTokens.RANGLE))
                {
                    if (angleDepth == 0)
                    {
                        break;
                    }
                    angleDepth--;
                }
                ParseNext();
            }
            if (angleDepth != 0) // We want it to break forcefully, otherwise there would be invalid syntax.
            {
                throw DmlSyntaxError.MismatchedNamespaceDelimiters();
            }

            Instructions.Add(new Label(jumpName));
        }
Пример #2
0
        protected override void ProcessTimeCommand()
        {
            if (inTimeStamp)
            {
                throw DmlSyntaxError.BadTimeCommandPlacement();
            }
            inTimeStamp = true;

            DmlSyntaxError badTimeCommand = DmlSyntaxError.BadTimeCommandSyntax();
            double         time, start = -1, end = -1;
            string         timeCommand = CurrentToken;

            switch (timeCommand)
            {
            case "At":
            case "Before":
            case "After":
                SetExpecting(DmlTokens.LPAR, DmlTokens.NUMBER, DmlTokens.RPAR, DmlTokens.LANGLE);

                Advance(2, exception: badTimeCommand);
                time = Double.Parse(CurrentToken);

                Advance(2, exception: badTimeCommand);
                if (timeCommand == "At")
                {
                    currentTimestamp = new TimestampAt(time);
                }
                else if (timeCommand == "Before")
                {
                    currentTimestamp = new TimestampBefore(time);
                }
                else
                {
                    currentTimestamp = new TimestampAfter(time);
                }
                break;

            case "AtIntervals":
            case "DuringIntervals":
                SetExpecting(DmlTokens.LPAR, DmlTokens.NUMBER);

                Advance(2, exception: badTimeCommand);
                time = Double.Parse(CurrentToken);

                if (DmlTokens.IsMatch(NextToken, DmlTokens.COMMA))
                {
                    SetExpecting(DmlTokens.COMMA, DmlTokens.NUMBER);
                    Advance(2, exception: badTimeCommand);
                    start = Double.Parse(CurrentToken);

                    SetExpecting(DmlTokens.COMMA, DmlTokens.NUMBER);
                    Advance(2, exception: badTimeCommand);
                    end = Double.Parse(CurrentToken);
                }

                SetExpecting(DmlTokens.RPAR, DmlTokens.LANGLE);
                Advance(2, exception: badTimeCommand);

                if (timeCommand == "AtIntervals")
                {
                    if (start == -1)
                    {
                        currentTimestamp = new TimestampAtIntervals(time);
                    }
                    else
                    {
                        currentTimestamp = new TimestampAtIntervals(time, start, end);
                    }
                }
                else
                {
                    if (start == -1)
                    {
                        currentTimestamp = new TimestampDuringIntervals(time);
                    }
                    else
                    {
                        currentTimestamp = new TimestampDuringIntervals(time, start, end);
                    }
                }
                break;

            case "From":
                SetExpecting(
                    DmlTokens.LPAR, DmlTokens.NUMBER, DmlTokens.COMMA,
                    DmlTokens.NUMBER, DmlTokens.RPAR, DmlTokens.LANGLE
                    );
                Advance(2, exception: badTimeCommand);
                start = Double.Parse(CurrentToken);

                Advance(2, exception: badTimeCommand);
                end = Double.Parse(CurrentToken);

                Advance(2, exception: badTimeCommand);
                currentTimestamp = new TimestampFrom(start, end);
                break;
            }

            Advance(exception: badTimeCommand);
            int angleDepth = 0;

            while (!Done)
            {
                if (DmlTokens.IsMatch(CurrentToken, DmlTokens.LANGLE))
                {
                    angleDepth++;
                }
                else if (DmlTokens.IsMatch(CurrentToken, DmlTokens.RANGLE))
                {
                    if (angleDepth == 0)
                    {
                        break;
                    }
                    angleDepth--;
                }
                ParseNext();
            }

            currentTimestamp.SetCode(new CodeBlock(Instructions.ToArray()));
            Instructions = new List <Instruction>();
            timeline.AddTimestamp(currentTimestamp);
            inTimeStamp = false;
        }