Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.misc Subject: Re: Language Design, or: is C's Grammar Context Free Keywords: BNF, Grammars, Silliness Message-ID: <16591@mimsy.UUCP> Date: 28 Mar 89 18:39:32 GMT References: <5200040@m.cs.uiuc.edu> <12443@watdragon.waterloo.edu> <12778@watdragon.waterloo.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 37 >In article <16559@mimsy.UUCP> I included the throwaway% line: >>... At least, this is the only explanation I can see that we never > ^^^^^^^^^^^^^^^^^^^^^^^^^^ >>argue whether Pascal's grammar is context free. ----- % cf. Webster: `throw.away \'thro--*-.wa-\ n : a handbill or circular distributed free'; applied to writing (especially comic writing), it refers to a line with similar worth. ----- In article <12778@watdragon.waterloo.edu> akwright@watdragon.waterloo.edu (Andrew K. Wright) writes: >The difference I see is that a C grammar that accepts undeclared typedef >names destroys more of the structure of the grammar than a Pascal >grammar that accepts undeclared variable names. Consider the following >C expression: > > x = (a)(b); > >If "a" is a typedef name, then the right side is a cast. If "a" is >not a typedef name, then the right side is a function call. >I dont believe similar situations exist for Pascal (corrections welcome). I am not sure what you mean by `destroys more of the structure of the grammar'. It is ambiguous, and in particular it is an ambiguity of an uncomfortable sort, quite unlike the shift/reduce ambiguity for if/then/else which everyone resolves by taking the shift. Yacc permits this reduce/ reduce conflict, but resolves it by taking the first grammar rule; we want the parser to take the *appropriate* grammar rule, which is sometimes the first and sometimes not. So yacc unaided will not produce a deterministic parser that does what we want. BUT all this applies to constructing a deterministic LALR(1) parser, which is not at all the same thing as having a context free grammar! -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris