nlsandler / writing-a-c-compiler-tests

Test cases for Writing a C Compiler
https://nostarch.com/writing-c-compiler
Other
170 stars 24 forks source link

Add earlier non-extra credit test to catch lexing error where ident starts with a keyword #36

Closed johnvtan closed 3 months ago

johnvtan commented 4 months ago

I found a bug in my lexer where I wasn't properly lexing idents that started with a keyword, e.g. return_a or int_b. I didn't catch this until running the Chapter 7 parsing tests with --goto enabled because those tests use labels like return_a.

I think it would make sense for this test to go in Chapter 5, where variables are introduced. Having a test with a variable named return_5 or void_a probably would have caught this bug too.

nlsandler commented 4 months ago

Good catch - I agree that having a test with a variable name like return_5 in Chapter 5 makes sense.

Were you lexing identifiers like return_a into two tokens, a keyword plus an identifier?

nlsandler commented 3 months ago

Just merged a PR with an additional test that should cover this, but feel free to reopen if this new test wouldn't have caught your bug or there are other related edge cases you think should be covered!