From 230c0be4ffad3e0339b63b3a2363ea2d9ce3dc67 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Wed, 8 Jan 2025 00:04:17 +0100 Subject: Parser: Prepare for variable statement parsing --- src/parser.zig | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/parser.zig b/src/parser.zig index f55f5a2..7fb6372 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -93,20 +93,38 @@ pub const Parser = struct { } fn parse_statement(self: *Parser) ParserError!*Node { - //TODO: Add support for parsing variable declaration and assignment. Also here we shouldnt parse numbers/identifiers directly - const token = self.peek_token(); + //TODO: Add support for parsing variable declaration and assignment. + const token = self.peek_token() orelse return ParserError.ParsingError; std.debug.print("PARSING: {any}\n", .{token}); - const print_statement = try self.parse_print_statement(); - _ = try self.accept_token(tokenizer.TokenType.SEMICOLON); + //TODO: Cleanup (avoid dupl) + if (token == .PRINT) { + const print_statement = try self.parse_print_statement(); + _ = try self.accept_token(tokenizer.TokenType.SEMICOLON); - const node = try self.allocator.create(Node); - node.* = .{ - .STATEMENT = .{ - .statement = print_statement, - }, - }; - return node; + const node = try self.allocator.create(Node); + node.* = .{ + .STATEMENT = .{ + .statement = print_statement, + }, + }; + return node; + } else { + const variable_statement = try self.parse_variable_statement(); + _ = try self.accept_token(tokenizer.TokenType.SEMICOLON); + + const node = try self.allocator.create(Node); + node.* = .{ + .STATEMENT = .{ + .statement = variable_statement, + }, + }; + return node; + } + } + + fn parse_variable_statement(_: *Parser) ParserError!*Node { + @panic("UNIMPLEMENTED parse_variable_statement"); } fn parse_print_statement(self: *Parser) ParserError!*Node { -- cgit 1.4.1