+fn statement(self: *Parser) !*const Stmt {
+ if (self.match(&.{.print})) {
+ return self.printStatement();
+ }
+
+ return self.expressionStatement();
+}
+
+fn printStatement(self: *Parser) !*const Stmt {
+ const value = try self.expression();
+ _ = try self.consume(.semicolon, "Expect ';' after value.");
+ const stmt = try self.allocator.create(Stmt);
+ stmt.* = .{ .print = .init(value) };
+ return stmt;
+}
+
+fn expressionStatement(self: *Parser) !*const Stmt {
+ const expr = try self.expression();
+ _ = try self.consume(.semicolon, "Expect ';' after expression.");
+ const stmt = try self.allocator.create(Stmt);
+ stmt.* = .{ .expression = .init(expr) };
+ return stmt;
+}
+
+fn equality(self: *Parser) !*const Expr {