programming puzzle (silly)

Doug Gwyn gwyn at smoke.BRL.MIL
Tue Mar 14 11:56:19 AEST 1989


In article <218 at umigw.MIAMI.EDU> steve at umigw.miami.edu (steve emmerson) writes:
>In article <24820 at amdcad.AMD.COM> tim at amd.com (Tim Olson) opines that the
>expression "n&&m*=n--" is incorrect C:
>I belive the correctness of a expression is determined by whether or not
>the expression can be *generated from* the grammer's production rules; not
>whether or not a given implementation of a compiler can parse it.

Right.

>The given expression is correct C as it can be generated by the following
>rules:

I didn't much like your particular production.  Using the pANS grammar,
the conclusion that the parse is NOT effectively "(n&&m) *= n--" is a
correct deduction; the key point is that "n&&m" cannot possibly be parsed
as anything that is allowed as the left operand of the assignment
expression (called a "unary expression" in the pANS grammar).  However,
the grammar does not support the production you gave, either.  At least
one set of parentheses would have to be added to obtain a valid
expression.  The phrase-structure grammar does not in general allow
arbitrary expressions as operands, only limited classes of expressions.



More information about the Comp.lang.c mailing list