public Unit VisitBlockStmt(Stmt.Block stmt) { BeginScope(); Resolve(stmt.Statments); EndScope(); return(new Unit()); }
public object visitBlockStmt(Stmt.Block stmt) { beginScope(); resolve(stmt.statements); endScope(); return(null); }
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)); }
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)); }
public object VisitBlockStmt(Stmt.Block stmt) { BeginScope(); Resolve(stmt.statements); EndScope(); return(new Stmt.DefaultStatement()); }
public object VisitBlockStmt(Stmt.Block stmt) { BeginScope(); Resolve(stmt.Statements); EndScope(); return(null); }
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)); }
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()); }
public VoidObject VisitBlockStmt(Stmt.Block stmt) { BeginScope(); Resolve(stmt.Statements); EndScope(); return(VoidObject.Void); }
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); }
public object visitBlockStmt(Stmt.Block blockStmt) { beginScope(); foreach (Stmt stmt in blockStmt.statements) { compile(stmt); } endScope(); return(null); }
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); }
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()); }
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("}"); }
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()); }
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)); }
public Macro(Lexer.Token name, Stmt.Block body) { this.Name = name; this.Body = body; }
public TrashObject VisitBlockStmt(Stmt.Block stmt) { return(this.BlockStmt(stmt)); }
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); }
public LoxVoid VisitBlockStmt(Stmt.Block stmt) { ExecuteBlock(stmt.Statements, new Environment(_environment)); return(null); }
public object visitBlockStmt(Stmt.Block stmt) { executeBlock(stmt.statements, new Environment(environment)); return(null); }
/// <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--; } }
public Stmt VisitBlockStmt(Stmt.Block stmt) { throw new NotImplementedException(); }
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); }
Stmt Stmt.Visitor <Stmt> .VisitBlockStmt(Stmt.Block stmt) { ExecuteBlock(stmt.statements, new JukaEnvironment(this.environment)); return(null); }
public static TrashObject BlockStmt(this Interpreter interpreter, Stmt.Block stmt) { return(interpreter.ExecuteBlock(stmt.Statements, new Environment(interpreter.IntEnvironment.Name + " Block", interpreter.IntEnvironment))); }
public object VisitBlockStmt(Stmt.Block stmt) { ExecuteBlock(stmt.Statements, new Environment(Environment)); return(null); }
public Repeat(Expr cond, Stmt.Block bl) { this.Condition = cond; this.Block = bl; }
public Repeat(Expr lv, Expr hv, Stmt.Block bl) { this.LowValue = lv; this.HighValue = hv; this.Block = bl; }
object Stmt.Visitor <object> .VisitBlockStmt(Stmt.Block stmt) { ExecuteBlock(stmt.statements, new Environment.Environment(environment)); return(null); }