Mantis - Squeak
Viewing Issue Advanced Details
3616 Compiler minor always 05-13-06 22:29 04-18-10 21:54
nicolas cellier  
nicolas cellier  
closed 3.9  
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:
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

nicolas cellier   
02-23-10 16:41   
See also: [^] [^]
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
nicolas cellier   
04-01-10 20:10   
Fixed in [^]