Пример #1
0
 public Unit VisitBlockStmt(Stmt.Block stmt)
 {
     BeginScope();
     Resolve(stmt.Statments);
     EndScope();
     return(new Unit());
 }
Пример #2
0
 public object visitBlockStmt(Stmt.Block stmt)
 {
     beginScope();
     resolve(stmt.statements);
     endScope();
     return(null);
 }
Пример #3
0
        public static Stmt.Member Member(this Parser parser)
        {
            Lexer.Token name = parser.Consume("Expected identifier after 'member'", Lexer.Token.TokenType.IDENTIFIER);

            Expr initialiser = null;

            if (parser.Match(Lexer.Token.TokenType.EQUAL))
            {
                initialiser = parser.Comparison();
                return(new Stmt.Member(name, initialiser));
            }

            Stmt.Comma args = null;
            if (parser.Match(Lexer.Token.TokenType.WITH))
            {
                args = parser.Comma();
            }

            Stmt.Block block = null;
            if (parser.Match(Lexer.Token.TokenType.DO))
            {
                block = parser.Block();
            }

            return(new Stmt.Member(name, block, args));
        }
Пример #4
0
    Stmt repeat()
    {
        Expr left  = condition();
        Expr right = null;

        // hey we've got a high low loop
        // also im exhausted
        if (match(Lexer.Token.TokenType.COLON, Lexer.Token.TokenType.TO))
        {
            right = condition();
        }

        Stmt.Block blk = null;
        if (match(Lexer.Token.TokenType.DO))
        {
            blk = new Stmt.Block(block());
        }
        else
        {
            throw new ParseError("Expected block after repeat statement");
        }

        if (right != null)
        {
            return(new Stmt.Repeat(left, right, blk));
        }

        return(new Stmt.Repeat(left, blk));
    }
Пример #5
0
 public object VisitBlockStmt(Stmt.Block stmt)
 {
     BeginScope();
     Resolve(stmt.statements);
     EndScope();
     return(new Stmt.DefaultStatement());
 }
Пример #6
0
 public object VisitBlockStmt(Stmt.Block stmt)
 {
     BeginScope();
     Resolve(stmt.Statements);
     EndScope();
     return(null);
 }
Пример #7
0
        public static Stmt Repeat(this Parser parser)
        {
            var line = parser.Previous().Line;

            Expr left  = parser.Comparison();
            Expr right = null;

            // hey we've got a high low loop
            // also im exhausted
            if (parser.Match(Lexer.Token.TokenType.COLON, Lexer.Token.TokenType.TO))
            {
                right = parser.Comparison();
            }

            Stmt.Block blk = null;
            if (parser.Match(Lexer.Token.TokenType.DO))
            {
                blk = parser.Block();
            }
            else
            {
                throw new Parser.ParseError("Expected block after repeat statement", line);
            }

            if (right != null)
            {
                return(new Stmt.Repeat(left, right, blk));
            }

            return(new Stmt.Repeat(left, blk));
        }
Пример #8
0
 public Unit VisitBlockStmt(Stmt.Block stmt)
 {
     // Functions, and block statements where scopes are resolved.
     this.BeginScope();
     this.Resolve(stmt.Statments);
     this.EndScope();
     return(new Unit());
 }
Пример #9
0
        public VoidObject VisitBlockStmt(Stmt.Block stmt)
        {
            BeginScope();
            Resolve(stmt.Statements);
            EndScope();

            return(VoidObject.Void);
        }
Пример #10
0
        private Stmt ForStatment()
        {
            Consume(LEFT_PAREN, "Exepect '(' after 'for.");
            Stmt initialiser;

            if (Match(SEMICOLON))
            {
                initialiser = null;
            }
            else if (Match(VAR))
            {
                initialiser = VarDeclaration();
            }
            else
            {
                initialiser = ExpressionStatement();
            }

            Expr Condition = null;

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

            Expr increment = null;

            if (!Check(RIGHT_PAREN))
            {
                increment = Expression();
            }
            Consume(RIGHT_PAREN, "Expect ')' after for clausess.");

            Stmt body = Statement();

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

            if (Condition == null)
            {
                Condition = new Expr.Literal(true);
            }
            body = new Stmt.While(Condition, body);

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

            return(body);
        }
Пример #11
0
 public object visitBlockStmt(Stmt.Block blockStmt)
 {
     beginScope();
     foreach (Stmt stmt in blockStmt.statements)
     {
         compile(stmt);
     }
     endScope();
     return(null);
 }
Пример #12
0
    public object VisitBlockStmt(Stmt.Block stmt, object options = null)
    {
        var previousTypeTableTypes = SymbolTable.Types;

        SymbolTable.Types = AddSymbolDefinition("void", stmt.token.lexeme, AccessModifier.Private, true, new Token[] { stmt.token });
        foreach (Stmt statement in stmt.statements)
        {
            statement.Accept(this);
        }
        SymbolTable.Types = previousTypeTableTypes;
        return(null);
    }
Пример #13
0
        public object VisitBlockStmt(Stmt.Block stmt, object options)
        {
            StringBuilder builder = new();

            builder.Append("(block ");
            foreach (Stmt statement in stmt.statements)
            {
                builder.Append(statement.Accept(this, null));
            }
            builder.Append(')');
            return(builder.ToString());
        }
Пример #14
0
        public IEnumerable <string> VisitBlockStmt(Stmt.Block stmt)
        {
            StringBuilder builder = new StringBuilder();

            yield return("{");

            foreach (Stmt subStmt in stmt.Statements)
            {
                foreach (string print in PrintStmt(subStmt))
                {
                    yield return($"  {print}");
                }
            }
            yield return("}");
        }
Пример #15
0
        public string VisitBlockStmt(Stmt.Block stmt)
        {
            StringBuilder builder = new();

            builder.Append("(block ");

            foreach (Stmt statement in stmt.Statements)
            {
                builder.Append(statement.Accept(this));
            }

            builder.Append(')');

            return(builder.ToString());
        }
Пример #16
0
        public static Stmt If(this Parser parser)
        {
            var line = parser.Previous().Line;
            var cond = parser.Comparison();

            parser.Consume("Expected 'do' after 'if'", Lexer.Token.TokenType.DO);
            var blk = parser.Block();

            Stmt.Block blk2 = null;

            if (parser.Match(Lexer.Token.TokenType.ELSE))
            {
                blk2 = parser.Block();
            }

            return(new Stmt.If(cond, blk, blk2));
        }
Пример #17
0
 public Macro(Lexer.Token name, Stmt.Block body)
 {
     this.Name = name;
     this.Body = body;
 }
Пример #18
0
 public TrashObject VisitBlockStmt(Stmt.Block stmt)
 {
     return(this.BlockStmt(stmt));
 }
Пример #19
0
        private Stmt ForStatement()
        {
            // The "for" implementation is a bit special in that it doesn't use any special AST nodes of its own.
            // Instead, it just desugars the for loop into already existing elements in our toolbox.
            // More details: http://craftinginterpreters.com/control-flow.html#desugaring
            Consume(LEFT_PAREN, "Expect '(' after 'for'.");

            Stmt initializer;

            if (Match(SEMICOLON))
            {
                initializer = null;
            }
            else if (Match(VAR))
            {
                initializer = VarDeclaration();
            }
            else
            {
                initializer = ExpressionStatement();
            }

            Expr condition = null;

            if (!Check(SEMICOLON))
            {
                condition = Expression();
            }

            Consume(SEMICOLON, "Expect ';' after loop condition.");

            Expr increment = null;

            if (!Check(RIGHT_PAREN))
            {
                increment = Expression();
            }

            Consume(RIGHT_PAREN, "Expect ')' after for clauses.");

            Stmt body = Statement();

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

            condition ??= new Expr.Literal(true);

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

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

            return(body);
        }
Пример #20
0
 public LoxVoid VisitBlockStmt(Stmt.Block stmt)
 {
     ExecuteBlock(stmt.Statements, new Environment(_environment));
     return(null);
 }
Пример #21
0
 public object visitBlockStmt(Stmt.Block stmt)
 {
     executeBlock(stmt.statements, new Environment(environment));
     return(null);
 }
Пример #22
0
        /// <summary>
        /// Parse a for loop
        /// </summary>
        /// <returns>The statement</returns>
        private Stmt ForStatement()
        {
            _loop_depth++;

            try
            {
                Consume(TokenType.LEFT_PAREN, "Expect '(' after 'for'.");

                // Initializer

                Stmt initializer;
                if (Match(TokenType.SEMICOLON))
                {
                    // No initialiser
                    initializer = null;
                }
                else if (Match(TokenType.VAR))
                {
                    // Its a variable decalration
                    initializer = VarDeclaration();
                }
                else
                {
                    // Its an expression
                    // This must be a _statement_
                    initializer = ExpressionStatement();
                }

                // Condition
                Expr condition = null;
                if (!Check(TokenType.SEMICOLON))
                {
                    condition = Expression();
                }
                Consume(TokenType.SEMICOLON, "Expect ';' after loop condition.");

                // Increment
                Expr increment = null;
                if (!Check(TokenType.SEMICOLON))
                {
                    increment = Expression();
                }
                Consume(TokenType.RIGHT_PAREN, "Expect ')' after for clauses.");

                // Body
                Stmt body = Statement();

                // Convert to a while loop
                if (increment != null)
                {
                    body = new Stmt.Block(new[] { body, new Stmt.ExpressionStatement(increment) });
                }

                if (condition == null)
                {
                    // No condition, so set to true
                    condition = new Expr.Literal(true);
                }

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

                if (initializer != null)
                {
                    body = new Stmt.Block(new[] { initializer, body });
                }

                return(body);
            }
            finally
            {
                _loop_depth--;
            }
        }
Пример #23
0
 public Stmt VisitBlockStmt(Stmt.Block stmt)
 {
     throw new NotImplementedException();
 }
Пример #24
0
    private Stmt ForStatement()
    {
        Consume(LeftParen, "Expect '(' after 'for'.");

        Stmt initializer;

        if (Match(Semicolon))
        {
            initializer = null;
        }
        else if (Match(Var))
        {
            initializer = VarDeclaration();
        }
        else
        {
            initializer = ExpressionStatement();
        }

        Expr condition = null;

        if (!Check(Semicolon))
        {
            condition = Expression();
        }

        Consume(Semicolon, "Expect ';' after loop condition.");

        Expr increment = null;

        if (!Check(RightParen))
        {
            increment = Expression();
        }

        Consume(RightParen, "Expect ')' after for clauses.");

        Stmt body = Statement();

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

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

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

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

        return(body);
    }
Пример #25
0
 Stmt Stmt.Visitor <Stmt> .VisitBlockStmt(Stmt.Block stmt)
 {
     ExecuteBlock(stmt.statements, new JukaEnvironment(this.environment));
     return(null);
 }
Пример #26
0
 public static TrashObject BlockStmt(this Interpreter interpreter, Stmt.Block stmt)
 {
     return(interpreter.ExecuteBlock(stmt.Statements, new Environment(interpreter.IntEnvironment.Name + " Block", interpreter.IntEnvironment)));
 }
Пример #27
0
 public object VisitBlockStmt(Stmt.Block stmt)
 {
     ExecuteBlock(stmt.Statements, new Environment(Environment));
     return(null);
 }
Пример #28
0
 public Repeat(Expr cond, Stmt.Block bl)
 {
     this.Condition = cond;
     this.Block     = bl;
 }
Пример #29
0
 public Repeat(Expr lv, Expr hv, Stmt.Block bl)
 {
     this.LowValue  = lv;
     this.HighValue = hv;
     this.Block     = bl;
 }
Пример #30
0
 object Stmt.Visitor <object> .VisitBlockStmt(Stmt.Block stmt)
 {
     ExecuteBlock(stmt.statements, new Environment.Environment(environment));
     return(null);
 }