From mboxrd@z Thu Jan 1 00:00:00 1970 From: erik quanstrom Date: Fri, 30 Oct 2009 14:28:52 -0400 To: 9fans@9fans.net Message-ID: <332ccdbfcadf7769acbbd00931f5cde4@brasstown.quanstro.net> In-Reply-To: <> References: <> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: Re: [9fans] hoc's behaviour, unary operators Topicbox-Message-UUID: 94c57b24-ead5-11e9-9d60-3106f5b1d025 > Python handles correctly e.g. 2-----7, 2+-+-7, 2+++-7,... > C-compiler that I use in my linux, gcc, is ok for a+-b and a-+b, also > for a+-+-b, but not for a++b or a--b or any alike. you're confusing tokens and productions. the c tokenizer has the following rules -- -> DEC ++ -> INC + -> PLUS - -> MINUS therefore the string "a++b" can't be valid, since the tokens the parser sees are "a" INC "b". that's not kosher c. way back when in primoridal c, there were no seperate tokens for INC and DEC, they were productions in the parser and goofiness like you describe was allowed. i'll leave as an excersize why k&r thought that making -- and ++ tokens was worth while. also, this is a very long discussion for a one-line fix. if you care, please apply this largely do-nothing patch to your hoc: ; diffy -c /sys/src/cmd/hoc/hoc.y /n/dump/2009/1030/sys/src/cmd/hoc/hoc.y:98,103 - /sys/src/cmd/hoc/hoc.y:98,104 | expr '%' expr { code(mod); } | expr '^' expr { code (power); } | '-' expr %prec UNARYMINUS { $$=$2; code(negate); } + | '+' expr %prec UNARYMINUS { $$=$2; } | expr GT expr { code(gt); } | expr GE expr { code(ge); } | expr LT expr { code(lt); } - erik