C not LALR(1) & compiler bugs

richw at ada-uts.UUCP richw at ada-uts.UUCP
Tue Feb 4 02:53:00 AEST 1986


Some clarifications:

Whether the ambiguity pointed out in H&S causes C's grammar to
be context sensitive deserves to be questioned.  My faint recollection
of what it technically means to be context sensitive doesn't seem
to apply (i.e. more the one terminal and/or non-terminal on the
left-hand-side of a production?).

However, whether or not H&S is correct in using the term "context-
sensitive", there IS a point to be made!  By simply looking at

    A (*B) ;

the parser CAN generate A (sub-) tree for that statement/declaration.
That is, the parser WILL still only recognize strings in the language
for C (where language is defined in the more formal sense of being
a possibly-infinite set of strings).  HOWEVER, the tree that is built
for this statement/declaration contains almost no semantic information.
Contrast it against the sub-tree built for

    if (<conditional-expression>)
        <statement>
    else
        <statement>

After parsing that, the language processor KNOWS that that is an IF
statement.  However, after parsing, the language processor needs to
look at PREVIOUS information (context, if you like) to figure out if

    A (*B) ;

is a statement (i.e. procedure call) or a variable declaration.
There's a big difference between the two interpretations...

My apologies for probably using the wrong terminology, but remember
that it was quoted from H&S (i.e. how to pawn off blame for a mistake).

-- Rich



More information about the Comp.lang.c mailing list