Mantis - Squeak
Viewing Issue Advanced Details
3616 Compiler minor always 05-13-06 22:29 04-18-10 21:54
nicolas cellier  
nicolas cellier  
normal  
closed 3.9  
fixed  
none    
none trunk  
0003616: Enhancement of syntax : allow $- not only as first binary selector
Current syntax does not allow $- in binary selector except in first position.
Original ST-80 aim was to avoid ambiguity caused by negated literal numbers, like in:
    x--2
Based on this rule: spaces put around a binary selector should not be significative. In other words, spaces should not be mandatory.
Thus x - -2 sould give same resulta as x--2.

If we add a simple precedence rule: after first position, $- is not attached to the binary selector if it is immediately preceding a digit, then we can allow $- to appear anywhere.

Of course, grammar is more complex, you have to check two characters ahead, but that's already the case...

I provide a very light patch, only Scanner>>xBinary need being changed
Note that a separator is allowed in Squeak between the $- and following digit.
You can evaluate (- 2) and (1 - - 1).

This is not the case in VW ST-80 cousin...

Separator are simply ignored here, and a literal value is reconstituted...
With such rules, we could have (1 000) being interpreted (1000).
But that does not work inside array literal quotes #(- 2) is not #(-2).
So i do not much like this extension. It contributes to make the space rule less clear...

This behaviour is implemented in Parser>>primaryExpression.
I did not change it but just remind it.
 Compiler-Kernel-BinaryMinusEnhancement.1.cs [^] (450 bytes) 05-13-06 22:32

Notes
(0013514)
nicolas cellier   
02-23-10 16:41   
See also:
http://lists.squeakfoundation.org/pipermail/squeak-dev/2006-May/103873.html [^]
http://blog.3plus4.org/2007/05/06/whats-a-binary-selector/ [^]
(0013516)
nicolas cellier   
02-24-10 01:09   
Note: factoring -2 handling into scanToken leads to much simpler code, but it prevents code like ^x-1 to compile...

Forbidding (- 2) in primaryExpression by testing token positions (hereMark hereEnd mark...) is very hard due to the funky positions returned.
It is necessary to correct first these positions according to the values of the two steps ahead:
aheadChar then hereChar
(0013614)
nicolas cellier   
04-01-10 20:10   
Fixed in http://source.squeak.org/trunk/Compiler-nice.120.mcz [^]