[EMAIL PROTECTED] (Michael O'Donnell) writes:

> struct mysteryStruct  {
>     struct mysteryStruct *next;
>     int                   dontCare;
> };
> 
> typedef struct mysteryStruct mystery;
> 
> mystery *nextMystery;                /* Pointer declaration - no problem */
> mystery  mysteryPool[ 200 ];            /* Array of structs - no problem */
> 
> mystery *                                  /* Function type - no problem */
> problem(
>     mystery *mystery )             /* Parameter declaration - no problem */
> {
>     mystery *hosed;        /* Auto variable declaration - choke and die! */

The problem here is that this last line is grammatically ambiguous.
I'll get back to this in a second...

Is this a variable declaration, as you claim, or is this a statement
without any side effects (multiply the *variable* "mystery" and the
(currently undefined) variable "hosed" and then throw the result
away).


Back to grammatical ambiguity...

The root of the problem here is C's "typedef" facility.  While this
facility is genuinely useful, it does come with certain implications.
One of these implications is that the presence of "typedef" in C's
grammer makes the actual formal grammer for C "context-sensitive"
(and, if you're familiar with compiler theory, this further implies
that the grammar for C is not LALR(1)). The fact that C's grammer is
context-sensitive implies that there are certain ambiguous cases that
the compiler won't be able to sort out what you were trying to direct
it to do.  

Your example is one of those ambiguous cases.

(as a side-note, if you look at the grammar of Java, it is obvious that
the designers deliberately did *not* include "typedef" in the language
because they wanted to keep this ambiguity out of the language, and
they wanted to keep the grammar LALR(1) as well....)


I hope this helps,

--kevin
-- 
Perl's grammar can not be reduced to BNF. The work of parsing perl is
distributed between yacc, the lexer, smoke and mirrors.
-- Chaim Frenkel


*****************************************************************
To unsubscribe from this list, send mail to [EMAIL PROTECTED]
with the text 'unsubscribe gnhlug' in the message body.
*****************************************************************

Reply via email to