A
Arthur J. O'Dwyer
Well, I'm trying to write that program that was requested
a few weeks back, the one that could take struct definitions
and create portable functions to read and write those
structs. Hence the 'savestruct' in the subject line.
I cannot for the life of me figure out how to parse C
declarations correctly! I've come up with an intermediate
format that I'd really like to keep, if at all possible,
which involves making a linked list (or tree, in the case
of functions) that looks something like this:
int (*p)[5]; becomes
is_a: pointer to
down: --.
|
`--> is_a: array of
down: --.
|
`--> is_a: signed int
down: (NULL)
The problem I'm having is parsing declarations using
as little look-ahead as possible; with one token of
look-ahead, I have managed to parse *either*
int (*p)[5]; correctly, *or*
int p[3][4]; correctly,
but whatever I try ends up messing up one of those
two cases.
Does anyone here already have a nice parser that
generates this kind of tree format, or think it's
trivial enough to kindly explain to me either here
or offline?
My current effort is posted complete at
http://www.contrib.andrew.cmu.edu/~ajo/struct.html
TIA,
-Arthur
a few weeks back, the one that could take struct definitions
and create portable functions to read and write those
structs. Hence the 'savestruct' in the subject line.
I cannot for the life of me figure out how to parse C
declarations correctly! I've come up with an intermediate
format that I'd really like to keep, if at all possible,
which involves making a linked list (or tree, in the case
of functions) that looks something like this:
int (*p)[5]; becomes
is_a: pointer to
down: --.
|
`--> is_a: array of
down: --.
|
`--> is_a: signed int
down: (NULL)
The problem I'm having is parsing declarations using
as little look-ahead as possible; with one token of
look-ahead, I have managed to parse *either*
int (*p)[5]; correctly, *or*
int p[3][4]; correctly,
but whatever I try ends up messing up one of those
two cases.
Does anyone here already have a nice parser that
generates this kind of tree format, or think it's
trivial enough to kindly explain to me either here
or offline?
My current effort is posted complete at
http://www.contrib.andrew.cmu.edu/~ajo/struct.html
TIA,
-Arthur