Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!lll-winken!elroy.jpl.nasa.gov!ncar!mephisto!rutgers!cmcl2!phri!sci.ccny.cuny.edu!cucard!sci.ccny.cuny.edu!rpi!zaphod.mps.ohio-state.edu!samsung!cs.utexas.edu!mailrus!usenet.ins.cwru.edu!ncoast!ramsey From: ramsey@ncoast.UUCP Newsgroups: comp.compiler,comp.lang.c Subject: 'C', is it's grammar context sensitive ? Message-ID: Date: 27 Aug 90 07:37:34 GMT Organization: North Coast Public Access *NIX, Cleveland, OH Lines: 57 Hello again ! This question is directed towards the 'C' and compiler gurus out there. I was studying the grammar for the 'C' language and I couldn't help but notice that for declarations the grammar is context sensitive. Look at this here: declaration: declaration-specifiers init-declarator-list_opt; declaration-specifiers: storage-class-specifier declaration-specifiers_opt type-specifier declaration-specifiers_opt type-qualifier declaration-specifiers_opt type-specifier: one of void char short int long float double signed unsigned struct-or-union-specifier enum-specifier typedef-name typedef-name: IDENTIFIER Since the 'typedef-name' is an identifier is impossible to determine that it is a type defintion without looking at the context. I guess that one could do a pre-scan of the source code and build typedef trees but I thought that 'C' was context free grammar. If you try to build a parser using the above grammar, which I did, a declaration tree for following grammar might derive: sometype id; declaration / \ declaration-specifiers init-declarator-list / \ type-specifier NULL / \ typdef-name type-specifier | \ IDENTIFIER = 'sometype' typedef-name | IDENTIFIER = 'id' Instead of: declaration / \ declaration-specifiers init-declarator-list / / \ type-specifier init-declarator NULL / \ | typdef-name NULL declarator | / \ IDENTIFIER = 'sometype' pointer direct-declarator | | NULL IDENTIFIER = 'id' Do you see point? I hope you do. Like I said before the solution to this problem, I believe, is to do a pre-pass to collect typedef definitions or just rearrange the grammar some-kind of adhoc way. I think that the prescan idea is best best it keeps the grammar simple and easy to follow. What do use guys think ?