C not LALR(1) & compiler bugs
ekrell at mit-bugs-bunny.arpa
ekrell at mit-bugs-bunny.arpa
Sun Jan 26 03:43:07 AEST 1986
> C's grammar is CONTEXT SENSITIVE !? Can it be ?!
First of all, the term "context sensitive" is incorrect.
C's grammar is context free since every production in the grammar has
exactly one non-terminal in its left hand side. The problem is the grammar
is ambiguous, i.e., some programs have more than one parse tree.
This is nothing out of the ordinary. Lots of languages have ambiguous
"official" grammars. Even Ada does. For instance, is A(1) a reference
to element 1 of an array A or is it a call to function A with 1 being
an argument ??. You can't distinguish between the two syntactically.
Please note that these two examples are not an indication of the language
being ambiguous, only that a particular grammar is ambiguous.
You can easily solve these two ambiguities by changing the grammar.
In the Ada example, you simply don't distinguish in the grammar
between array references and function calls and let the semantic
phase do the required checking.
--
Eduardo Krell UCLA Computer Science Department
ekrell at ucla-locus.arpa ..!{sdcrdcf,ihnp4,trwspp,ucbvax}!ucla-cs!ekrell
More information about the Comp.lang.c
mailing list