diff options
| author | Baitinq <[email protected]> | 2025-05-19 23:12:24 +0200 |
|---|---|---|
| committer | Baitinq <[email protected]> | 2025-05-19 23:12:24 +0200 |
| commit | 65d7ae71c822fd4adcd098c4c1f7753fa28e34d3 (patch) | |
| tree | 21d5ecf72da96038c7891750661e7964f7b44e79 | |
| parent | Bootstra: Tokenizer: Allocate more memory for tokens (diff) | |
| download | pry-lang-65d7ae71c822fd4adcd098c4c1f7753fa28e34d3.tar.gz pry-lang-65d7ae71c822fd4adcd098c4c1f7753fa28e34d3.tar.bz2 pry-lang-65d7ae71c822fd4adcd098c4c1f7753fa28e34d3.zip | |
Feature: Add support for !=
| -rw-r--r-- | grammar.ebnf | 2 | ||||
| -rw-r--r-- | src/bootstrap/tokenizer.src | 6 | ||||
| -rw-r--r-- | src/codegen.zig | 1 | ||||
| -rw-r--r-- | src/parser.zig | 13 |
4 files changed, 17 insertions, 5 deletions
diff --git a/grammar.ebnf b/grammar.ebnf index 15de75f..bd38952 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/bootstrap/tokenizer.src b/src/bootstrap/tokenizer.src index d8f868e..34e2b2e 100644 --- a/src/bootstrap/tokenizer.src +++ b/src/bootstrap/tokenizer.src @@ -305,7 +305,7 @@ let tokenizer_next = () => *i8 { }; let maybe_int = tokenizer_accept_int_type(); - if !(maybe_int == null) { + if maybe_int != null { let t = malloc(1000); sprintf(t, "int:%d", *maybe_int); @@ -313,7 +313,7 @@ let tokenizer_next = () => *i8 { }; let maybe_char = tokenizer_accept_char_type(); - if !(maybe_char == null) { + if maybe_char != null { let t = malloc(1000); sprintf(t, "char:%d", *maybe_char); @@ -321,7 +321,7 @@ let tokenizer_next = () => *i8 { }; let maybe_string = tokenizer_accept_string_type(); - if !(maybe_string == null) { + if maybe_string != null { let t = malloc(1000); sprintf(t, "string:%s", maybe_string); diff --git a/src/codegen.zig b/src/codegen.zig index 7cfaa04..9139475 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -619,6 +619,7 @@ pub const CodeGen = struct { const op: c_uint = switch (exp.typ) { .EQ => llvm.LLVMIntEQ, + .NE => llvm.LLVMIntNE, .GE => llvm.LLVMIntSGE, .LE => llvm.LLVMIntSLE, .LT => llvm.LLVMIntSLT, diff --git a/src/parser.zig b/src/parser.zig index 6e07491..510726f 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -99,6 +99,7 @@ pub const Node = union(enum) { pub const EqualityExpressionType = enum { EQ, + NE, GE, LE, LT, @@ -409,7 +410,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()}); @@ -429,6 +430,16 @@ pub const Parser = struct { typ = .EQ; } else if (self.accept_parse(struct { fn parse(iself: *Parser) ParserError!*Node { + _ = try iself.parse_token(tokenizer.TokenType.BANG); + _ = try iself.parse_token(tokenizer.TokenType.EQUALS); + return try iself.create_node(.{ .PROGRAM = .{ + .statements = &[_]*Node{}, + } }); + } + }.parse) != null) { + typ = .NE; + } 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 = .{ |