We need to compare strings. We're not going to use std.mem.eql -- we'll write our own. It's five lines and we'll need something like it in our self-hosted compiler anyway.
fn streq(a: []const u8, b: []const u8) bool {
if (a.len != b.len) {
return false;
}
for (a, b) |ca, cb| {
if (ca != cb) {
return false;
}
}
return true;
}
Test it in main: print("{}\n", .{streq("cat", "cat")}); -> true. print("{}\n", .{streq("cat", "dog")}); -> false.
We'll use streq everywhere we need to check for keywords like "var", "if", "while".