diff options
| author | Baitinq <[email protected]> | 2025-05-11 19:41:27 +0200 |
|---|---|---|
| committer | Baitinq <[email protected]> | 2025-05-11 19:41:27 +0200 |
| commit | 3f8021f3fdd8bbf8187e42e9340734fb806e69ca (patch) | |
| tree | ea85d0db1724bd22733230d169af5f7645b6aedf | |
| parent | Bootstrap: cleanup (diff) | |
| download | pry-lang-3f8021f3fdd8bbf8187e42e9340734fb806e69ca.tar.gz pry-lang-3f8021f3fdd8bbf8187e42e9340734fb806e69ca.tar.bz2 pry-lang-3f8021f3fdd8bbf8187e42e9340734fb806e69ca.zip | |
Feature: Add support for GE and LE comparisons
| -rw-r--r-- | grammar.ebnf | 2 | ||||
| -rw-r--r-- | src/codegen.zig | 2 | ||||
| -rw-r--r-- | src/parser.zig | 24 |
3 files changed, 26 insertions, 2 deletions
diff --git a/grammar.ebnf b/grammar.ebnf index 837de9e..a855e57 100644 --- a/grammar.ebnf +++ b/grammar.ebnf @@ -20,7 +20,7 @@ FunctionArguments ::= Expression ("," Expression)* Expression ::= EqualityExpression | AdditiveExpression -EqualityExpression ::= AdditiveExpression ("==" | "<" | ">") AdditiveExpression +EqualityExpression ::= AdditiveExpression ("==" | "<=" | ">=" | "<" | ">") AdditiveExpression AdditiveExpression ::= MultiplicativeExpression (("+" | "-") MultiplicativeExpression)* diff --git a/src/codegen.zig b/src/codegen.zig index a9597c4..ab34ea8 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -557,6 +557,8 @@ pub const CodeGen = struct { const op: c_uint = switch (exp.typ) { .EQ => llvm.LLVMIntEQ, + .GE => llvm.LLVMIntSGE, + .LE => llvm.LLVMIntSLE, .LT => llvm.LLVMIntSLT, .GT => llvm.LLVMIntSGT, }; diff --git a/src/parser.zig b/src/parser.zig index d5672d0..0318f26 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -96,6 +96,8 @@ pub const Node = union(enum) { pub const EqualityExpressionType = enum { EQ, + GE, + LE, LT, GT, }; @@ -388,7 +390,7 @@ pub const Parser = struct { return ParserError.ParsingError; } - // EqualityExpression ::= AdditiveExpression ("==" | "<" | ">") AdditiveExpression + // EqualityExpression ::= AdditiveExpression ("==" | "<=" | ">=" | "<" | ">") AdditiveExpression fn parse_equality_expression(self: *Parser) ParserError!*Node { errdefer if (!self.try_context) std.debug.print("Error parsing equality expression {any}\n", .{self.peek_token()}); @@ -406,6 +408,26 @@ pub const Parser = struct { } }.parse) != null) { typ = .EQ; + } else if (self.accept_parse(struct { + fn parse(iself: *Parser) ParserError!*Node { + _ = try iself.parse_token(tokenizer.TokenType.LESS); + _ = try iself.parse_token(tokenizer.TokenType.EQUALS); + return try iself.create_node(.{ .PROGRAM = .{ + .statements = &[_]*Node{}, + } }); + } + }.parse) != null) { + typ = .LE; + } else if (self.accept_parse(struct { + fn parse(iself: *Parser) ParserError!*Node { + _ = try iself.parse_token(tokenizer.TokenType.GREATER); + _ = try iself.parse_token(tokenizer.TokenType.EQUALS); + return try iself.create_node(.{ .PROGRAM = .{ + .statements = &[_]*Node{}, + } }); + } + }.parse) != null) { + typ = .GE; } else if (self.accept_token(tokenizer.TokenType.LESS) != null) { typ = .LT; } else if (self.accept_token(tokenizer.TokenType.GREATER) != null) { |