Open
Description
The current parser cannot fully disambiguate some expressions that may both be a type and an expression:
-
In
sizeof(A[10])
,A
can be a type and the expression evaluates to the size of an array of 10A
, orA
is a global constant array and the expression is the size of an element of this array. -
when parsing statements, an imperfect heuristic is used to distinguish declarations from expressions:
a * b;
could be a multiplication whose result is not used or a definition ofb
as a pointer toa
. Case could be used to disambiguate, but I would prefer not to have to rely on case alone.
There is a simple solution to this problem: we could perform 2 full passes on every source file:
- the first pass would serve only to detect type names: it would parse only
type
definitions for type names and would use an accelerated tokenizer to parse other statements and bracketed contents. This should be very fast. - the second pass would perform the current parsing, but identifiers would no longer be ambiguous, type names would be known and this would simplify the parsing as well as the analysis phases.
Metadata
Metadata
Assignees
Labels
No labels