Esempio n. 1
0
 public object Visit(Stmt.Expression _expression)
 {
     Resolve(_expression.expression);
     return(null);
 }
Esempio n. 2
0
        private Stmt ForStatement()
        {
            Consume(TokenType.LeftParen, "Expect '(' after 'for'.");

            Stmt initializer;

            if (Match(TokenType.Semicolon))
            {
                // None is defined
                initializer = null;
            }
            else if (Match(TokenType.Var))
            {
                initializer = VarDeclartion();
            }
            else
            {
                initializer = ExpressionStatement();
            }

            Expr condition = null;

            if (!Check(TokenType.Semicolon))
            {
                condition = Expression();
            }
            Consume(TokenType.Semicolon, "Expect ';' after loop condition");

            Expr increment = null;

            if (!Check(TokenType.RightParen))
            {
                increment = Expression();
            }
            Consume(TokenType.RightParen, "Expect ')' after for clauses.");

            Exception exception = null;

            try
            {
                m_LoopDepth++;
                Stmt body = Statement();

                if (increment != null)
                {
                    Stmt.Expression expression = new Stmt.Expression(increment);
                    List <Stmt>     content    = new List <Stmt>()
                    {
                        body, expression
                    };
                    body = new Stmt.Block(content);
                }

                if (condition == null)
                {
                    condition = new Expr.Literal(true);
                }

                body = new Stmt.While(condition, body);

                if (initializer != null)
                {
                    List <Stmt> content = new List <Stmt>()
                    {
                        initializer, body
                    };
                    body = new Stmt.Block(content);
                }

                return(body);
            }
            catch (Exception e)
            {
                exception = e;
            }
            finally
            {
                m_LoopDepth--;
            }

            throw exception;
        }
Esempio n. 3
0
 public object Visit(Stmt.Expression _expression)
 {
     Evaluate(_expression.expression);
     return(null);
 }