Skip to content

Conversation

jserv
Copy link
Collaborator

@jserv jserv commented Aug 18, 2025

The parser would crash with "Unexpected token" when a pointer dereference assignment (e.g., *p = 0) appeared immediately after a pointer declaration in the same block. This is a common C pattern that was blocking normal code compilation.

The issue occurred because the parser tried to interpret *p as a type declaration when it appeared after a pointer declaration like int *p = &x;. The ambiguity between * as a type modifier versus a dereference operator caused the crash.

This fix adds lookahead logic to check if the identifier after * is a known type. Only if it is a type will the statement be treated as a declaration; otherwise it is handled as a pointer dereference.

Summary by Bito

This pull request fixes a critical bug in the parser related to pointer dereference assignments after declarations by implementing additional lookahead logic. It ensures correct parsing behavior and adds new test cases to validate various pointer dereference scenarios, enhancing robustness.

The parser would crash with "Unexpected token" when a pointer
dereference assignment (e.g., '*p = 0') appeared immediately after a
pointer declaration in the same block. This is a common C pattern that
was blocking normal code compilation.

The issue occurred because the parser tried to interpret '*p' as a type
declaration when it appeared after a pointer declaration like
"int *p = &x;". The ambiguity between * as a type modifier versus a
dereference operator caused the crash.

This fix adds lookahead logic to check if the identifier after '*' is a
known type. Only if it is a type will the statement be treated as a
declaration; otherwise it's handled as a pointer dereference.
@jserv jserv merged commit 5b9dfe7 into master Aug 18, 2025
12 checks passed
@jserv jserv deleted the fixes branch August 18, 2025 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant