コード例 #1
0
 public Conditional(Token conditionalType, Ast predicate, ScopeDeclr body, Conditional alternate = null)
     : this(conditionalType)
 {
     Predicate = predicate;
     Body = body;
     Alternate = alternate;
 }
コード例 #2
0
 public Conditional(Token conditionalType, Ast predicate, ScopeDeclr body, Conditional alternate = null)
     : this(conditionalType)
 {
     Predicate = predicate;
     Body      = body;
     Alternate = alternate;
 }
コード例 #3
0
        public void Visit(Conditional ast)
        {
            if (ast.Predicate != null)
            {
                ast.Predicate.Visit(this);
            }

            ast.Body.Visit(this);

            if (ast.Alternate != null)
            {
                ast.Alternate.Visit(this);
            }

            SetScope(ast);
        }
コード例 #4
0
        public void Visit(Conditional ast)
        {
            Console.Write(ast.Token);

            if (ast.Predicate != null)
            {
                PrintWrap("Predicate", () => ast.Predicate.Visit(this));
            }

            ast.Body.Visit(this);

            if (ast.Alternate != null)
            {
                if (ast.Alternate.Token.TokenType == TokenType.If)
                {
                    Console.Write("Else");
                }

                ast.Alternate.Visit(this);
            }
        }
コード例 #5
0
 public void Visit(Conditional ast)
 {
     Exec(ast);
 }
コード例 #6
0
        private void ConditionalDo(Conditional conditional)
        {
            // else has no predicate
            if (conditional.Predicate == null)
            {
                Exec(conditional.Body);
                return;
            }

            MemorySpaces.CreateScope();

            var success = Convert.ToBoolean(Exec(conditional.Predicate));

            if(success)
            {
                Exec(conditional.Body);

                MemorySpaces.PopScope();
            }
            else
            {
                MemorySpaces.PopScope();

                Exec(conditional.Alternate);
            }
        }