Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site utah-gr.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!utah-cs!utah-gr!donn From: donn@utah-gr.UUCP (Donn Seeley) Newsgroups: net.lang.c Subject: Re: Re: Other 'significant' blanks Message-ID: <1275@utah-gr.UUCP> Date: Thu, 13-Dec-84 10:14:40 EST Article-I.D.: utah-gr.1275 Posted: Thu Dec 13 10:14:40 1984 Date-Received: Sat, 15-Dec-84 00:38:01 EST References: <4757@utzoo.UUCP> <10246@watmath.UUCP> Organization: CS Dept., University of Utah Lines: 33 From: Henry Spencer (henry@utzoo.UUCP): K&R actually says explicitly that (e.g.) "+=" is two tokens; hence space between them is allowable (section 7.14). However, practically no C compilers other than the original Ritchie compiler have done it this way. One reason for this is that it makes the language non-LALR(1), so all the yacc-based parsers croak. ... It may be the case that YACC parsers can't correctly handle '+=' as two tokens, but it's incorrect to say that they don't try to. The PCC (which has a YACC parser and is the basis of many specific C compilers) considers '+=' to be two tokens and avoids problems most of the time by using the rule 'shift when there is a shift-reduce conflict.' Last time I checked on our 4.2 BSD PCC, there were 7 shift-reduce conflicts... Precedence is also used to resolve conflicts. (I should note that '=+', the old style assignment operator, IS considered a single token by the PCC.) Apart from the fact that the PCC allows space between the arithmetic operator and the equals sign, you can also see the 'two-token' effect by comparing the following two statements: a && b += c; a && b = c; The first statement is parsed as 'a && (b += c)' because the PCC sees a '+' as the token following the 'b', and a '+' is higher in precedence than '&&', so it shifts; the 'two-token' effect prevents the compiler from noticing that the precedence of an assignment operator is lower than '&&'. The second statement parses as '(a && b) = c' and earns an error because 'a && b' is not an lvalue. Donn Seeley University of Utah CS Dept donn@utah-cs.arpa 40 46' 6"N 111 50' 34"W (801) 581-5668 decvax!utah-cs!donn