diff options
| author | Baitinq <[email protected]> | 2025-01-18 23:34:35 +0100 |
|---|---|---|
| committer | Baitinq <[email protected]> | 2025-01-18 23:34:35 +0100 |
| commit | 8324d20970d0f38d1add50da51daa7011c5d1920 (patch) | |
| tree | 8f8995827dce38bb5a9a57b753178f36935e4c85 /src/parser.zig | |
| parent | Feature: Add basic support for if statements (diff) | |
| download | interpreter-8324d20970d0f38d1add50da51daa7011c5d1920.tar.gz interpreter-8324d20970d0f38d1add50da51daa7011c5d1920.tar.bz2 interpreter-8324d20970d0f38d1add50da51daa7011c5d1920.zip | |
Feature: Add support for substraction
Diffstat (limited to 'src/parser.zig')
| -rw-r--r-- | src/parser.zig | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/parser.zig b/src/parser.zig index 81006f8..36f7437 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -48,6 +48,7 @@ pub const Node = union(NodeType) { }, }, ADDITIVE_EXPRESSION: struct { + addition: bool, lhs: *Node, rhs: *Node, }, @@ -216,15 +217,18 @@ pub const Parser = struct { return ParserError.ParsingError; } - // AdditiveExpression ::= PrimaryExpression ("+" AdditiveExpression) + // AdditiveExpression ::= PrimaryExpression (("+" | "-") AdditiveExpression) fn parse_additive_expression(self: *Parser) ParserError!*Node { errdefer if (!self.try_context) std.debug.print("Error parsing additive expression\n", .{}); const lhs = try self.parse_primary_expression(); - if (self.accept_token(tokenizer.TokenType.PLUS) != null) { + const plus = self.accept_token(tokenizer.TokenType.PLUS); + const minus = self.accept_token(tokenizer.TokenType.MINUS); + if (plus != null or minus != null) { const rhs = try self.parse_additive_expression(); return self.create_node(.{ .ADDITIVE_EXPRESSION = .{ + .addition = plus != null, .lhs = lhs, .rhs = rhs, } }); |