示例#1
0
        public void CreateInvalidStack()
        {
            ParseContext context = new ParseContext(null);

            Assert.Throws <IndexOutOfRangeException>(() =>
            {
                context.PushStack();
                context.CreateStackVariable("test", 4);
                context.PopStack();
                context.PopStack();
                context.CreateStackVariable("test", 4);
            });
        }
示例#2
0
 private void Body(ParseContext context)
 {
     if (Accept(Tokens.If))
     {
         IfStatement(context);
         Expect(Tokens.End);
         context.PopStack();
     }
     else if (Accept(Tokens.Var))
     {
         var    token = Expect(Tokens.Name);
         var    name  = token.Value;
         string value = null;
         if (Accept(Tokens.Assigns))
         {
             value = Var(context);
         }
         context.CreateStackVariable(name, value);
     }
     else if (Accept(Tokens.Name, out var token))
     {
         if (token.Value == "say")
         {
             context.responses.Add(Var(context));
         }
     }
     else if (Accept(Tokens.Stop))
     {
         _shouldStop = true;
     }
     else
     {
         _shouldStop = true;
     }
 }
示例#3
0
        public void CreateStackTest()
        {
            ParseContext context = new ParseContext(null);

            context.PushStack();
            context.CreateStackVariable("test", 4);
            context.PopStack();

            Assert.False(context.HasVariableOnStack("test"));
        }