|How to parse C-programs without communication between parser and lexer firstname.lastname@example.org (Detlef Sodtke) (1996-08-15)|
|Re: How to parse C-programs without communication between parser and l email@example.com (Henry Spencer) (1996-08-16)|
|Re: How to parse C-programs without communication between parser and l firstname.lastname@example.org (Scott Stanchfield) (1996-08-19)|
|How to parse C-programs without communication between parser and lexer email@example.com (Ilfak Guilfanov) (1996-08-27)|
|From:||Henry Spencer <firstname.lastname@example.org>|
|Date:||16 Aug 1996 23:49:02 -0400|
|Organization:||SP Systems, Toronto|
Detlef Sodtke <email@example.com> writes:
>The main problem is to distinguish the typedefnames...
>In our implementation we can't do it this way. We have to lex the whole
>C-program before the parser starts to work. So the parser is not able to
>write in a hashtable...
As our moderator already noted, taken literally, this problem really is
unsolvable -- you *must* parse the input to determine which names are
being declared as type names. Because of complications like block
structure, no simple heuristic will suffice.
It is quite possible to lex the whole input *if* you don't insist on
distinguishing type names from other names at that point. Then you can
have the front end of the parser cheat slightly, doing a lookup and
turning names into type names at the last instant before the parser
sees them. I've done that.
It is somewhat painful to parse C properly if the parser can't tell which
names are type names. At the very least, you'll need a fairly powerful
bottom-up parser -- a top-down parser needs excessive amounts of lookahead
to figure out something like `sizeof ( x *' if it doesn't know whether `x'
is a type name.
| Henry Spencer
Return to the
Search the comp.compilers archives again.