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 stringsEqual(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", .{stringsEqual("cat", "cat")}); -> true. print("{}\n", .{stringsEqual("cat", "dog")}); -> false.
We'll use stringsEqual everywhere we need to check for keywords like "var", "if", "while".
(The implementation is already in the problem text.)