Path: utzoo!attcan!uunet!mcvax!hp4nl!ruuinf!piet From: piet@ruuinf (Piet van Oostrum) Newsgroups: comp.lang.c Subject: Re: YACC grammar for C language Message-ID: <976@ruuinf.UUCP> Date: 13 Jan 89 16:44:36 GMT References: <175@calmasd.GE.COM> <1183@goofy.megatest.UUCP> Sender: piet@ruuinf.UUCP Reply-To: piet@ruuinf (Piet van Oostrum) Organization: Dept of Computer Science, University of Utrecht, Holland Lines: 28 In-reply-to: djones@megatest.UUCP (Dave Jones) In article <1183@goofy.megatest.UUCP>, djones@megatest (Dave Jones) writes: ` `I'll show you how I did it. I'm not too happy with the solution. `If you can think of a better way, please show me. I peeked into pcc `to see how they did it. Believe me, you don't even want to know. (Gack.) ` `....... ` ` struct_specifier ` : ntd STRUCT td IDENTIFIER '{' struct_declaration_list '}' ` { $$=tree(N_StructIDDef); } ` The best way to do this is: 1. Have different tokens for IDENTIFIER and TYPEDEF names. 2. in every context where a typedef name may be used as a normal identifier (e.g. in field names, declarations, parameters, enum lists) use the nonterminal identifier. 3. add the production rule: identifier: IDENTIFIER | TYPEDEF { $$=detypedef($1); }; You use IDENTIFIER or TYPEDEF in those rules where identifier would be ambiguous. This is the way I find most logical, and not surprisingly this is the way gcc does it. (If you want to see a good compiler look at gcc :=}.) -- Piet van Oostrum, Dept of Computer Science, University of Utrecht Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands Telephone: +31-30-531806. piet@cs.ruu.nl (mcvax!hp4nl!ruuinf!piet)