Path: utzoo!attcan!uunet!ncrlnk!ncrcae!hubcap!gatech!ncar!umigw!steve From: steve@umigw.MIAMI.EDU (steve emmerson) Newsgroups: comp.lang.c Subject: Re: programming puzzle (silly) Summary: it's correct C Message-ID: <218@umigw.MIAMI.EDU> Date: 13 Mar 89 14:40:31 GMT References: <24820@amdcad.AMD.COM> Reply-To: steve@umigw.miami.edu (steve emmerson) Distribution: na Organization: University of Miami Lines: 36 In article <24820@amdcad.AMD.COM> tim@amd.com (Tim Olson) opines that the expression "n&&m*=n--" is incorrect C: >Interesting -- the program *is* incorrect, because && has higher >precedence than *= so it is parsed as: > > (n&&m) *= n-- > >which is illegal because (n&&m) is not an lvalue. 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. The given expression is correct C as it can be generated by the following rules: expresion -> expression1 binop expression2 expression1 -> identifier -> n binop -> && expression2 -> lvalue asgnop expression lvalue -> identifier -> m asgnop -> *= expression -> lvalue-- -> identifier-- -> n-- Thus, expression -> n && m *= n-- Precedence rules are needed only when there is more than one way to generate a given expression and (consequently) more than one way to parse it. They appear to be unnecessary for the above expression. -- Steve Emmerson Inet: steve@umigw.miami.edu [128.116.10.1] SPAN: miami::emmerson (host 3074::) emmerson%miami.span@star.stanford.edu UUCP: ...!ncar!umigw!steve emmerson%miami.span@vlsi.jpl.nasa.gov "Computers are like God in the Old Testament: lots of rules and no mercy"