> 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