Re: How to parse C-programs without communication between parser and lexer

Henry Spencer <henry@zoo.toronto.edu>
16 Aug 1996 23:49:02 -0400

          From comp.compilers

Related articles
How to parse C-programs without communication between parser and lexer sodtke@infbssts.ips.cs.tu-bs.de (Detlef Sodtke) (1996-08-15)
Re: How to parse C-programs without communication between parser and l henry@zoo.toronto.edu (Henry Spencer) (1996-08-16)
Re: How to parse C-programs without communication between parser and l scooter@mccabe.com (Scott Stanchfield) (1996-08-19)
How to parse C-programs without communication between parser and lexer ig@estar.msk.su (Ilfak Guilfanov) (1996-08-27)
| List of all articles for this month |

From: Henry Spencer <henry@zoo.toronto.edu>
Newsgroups: comp.compilers
Date: 16 Aug 1996 23:49:02 -0400
Organization: SP Systems, Toronto
References: 96-08-040
Keywords: C, parse

Detlef Sodtke <sodtke@infbssts.ips.cs.tu-bs.de> 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
| henry@zoo.toronto.edu
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.