Interesting quirks with parsing C
I guess you never really understand something until you try to teach it. I am recently putting together a C parser and am working through a standards compliant specification for the C grammar. Today I got to the part about typedefs.
I was very surprised to understand that grammatically typedef
is just a normal type storage class specifier like extern
or static
.
Example:
typedef int x;
is much similar to
static int x;
There is one nitpick with this that needs to be mentioned though. typedef
affects the parsing of following C code. Any bound typedef becomes a valid type specifier, which potentially affects how code is parsed. This means that C grammar can only be parsed in one direction from left to right.
The more you know.