diff options
| author | Baitinq <[email protected]> | 2025-04-01 23:46:55 +0200 |
|---|---|---|
| committer | Baitinq <[email protected]> | 2025-04-01 23:47:14 +0200 |
| commit | d4ec81f8453ecc5ded0d2c2843c952ab27d19642 (patch) | |
| tree | 89af68c5f2b9c5552e95c70d6f2fba44b3d1d7a2 /src/parser.zig | |
| parent | Evaluator: Remove evaluator (diff) | |
| download | pry-lang-d4ec81f8453ecc5ded0d2c2843c952ab27d19642.tar.gz pry-lang-d4ec81f8453ecc5ded0d2c2843c952ab27d19642.tar.bz2 pry-lang-d4ec81f8453ecc5ded0d2c2843c952ab27d19642.zip | |
Feature: Start adding support for assigning to pointers with arithmetic
Diffstat (limited to 'src/parser.zig')
| -rw-r--r-- | src/parser.zig | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/parser.zig b/src/parser.zig index a40c811..4f607be 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -16,8 +16,8 @@ pub const Node = union(enum) { ASSIGNMENT_STATEMENT: struct { is_declaration: bool, is_dereference: bool, - name: []const u8, - expression: *Node, + lhs: *Node, + rhs: *Node, }, FUNCTION_CALL_STATEMENT: struct { expression: *Node, @@ -154,7 +154,7 @@ pub const Parser = struct { }); } - // AssignmentStatement ::= ("let")? ("*")? IDENTIFIER EQUALS Expression + // AssignmentStatement ::= ("let")? ("*")? Expression EQUALS Expression fn parse_assignment_statement(self: *Parser) ParserError!*Node { errdefer if (!self.try_context) std.debug.print("Error parsing assignment statement {any}\n", .{self.peek_token()}); @@ -168,18 +168,18 @@ pub const Parser = struct { is_dereference = true; } - const identifier = try self.parse_token(tokenizer.TokenType.IDENTIFIER); + const lhs = try self.parse_expression(); _ = try self.parse_token(tokenizer.TokenType.EQUALS); - const expression = try self.parse_expression(); + const rhs = try self.parse_expression(); return self.create_node(.{ .ASSIGNMENT_STATEMENT = .{ .is_declaration = is_declaration, .is_dereference = is_dereference, - .name = try self.arena.dupe(u8, identifier.type.IDENTIFIER), - .expression = @constCast(expression), + .lhs = lhs, + .rhs = rhs, }, }); } @@ -200,8 +200,15 @@ pub const Parser = struct { .ASSIGNMENT_STATEMENT = .{ .is_declaration = true, .is_dereference = false, - .name = try self.arena.dupe(u8, identifier.type.IDENTIFIER), - .expression = @constCast(typ), + .lhs = try self.create_node(.{ + .PRIMARY_EXPRESSION = .{ + .IDENTIFIER = .{ + .name = try self.arena.dupe(u8, identifier.type.IDENTIFIER), + .type = null, + }, + }, + }), + .rhs = @constCast(typ), }, }); } |