[Swift-devel] app syntax ambiguity
Mihael Hategan
hategan at mcs.anl.gov
Sun Dec 16 11:57:20 CST 2007
On Sun, 2007-12-16 at 13:38 +0000, Ben Clifford wrote:
> Expressions have been mostly self delimiting, which is useful in the app{}
> block syntax where there are no delimiters between the parameters of an
> application. For example, given the input: 21*33 14*96 that can be parsed
> as two expressions, the first one 21*33 and the second one 14*96.
>
> The sequence of tokens for this coming out of the lexer is: 21 * 33 14 *
> 96
>
> There's some ambiguity when it comes to unary +/- eg 21 -33 could be
> either a single expression (21-33) or two expressions 21 and -33.
Would we be ok (from an aesthetic/usability) perspective with commas as
separators there? Or even with representing the args as an array?
If not, then I think the unary operators should have precedence and if
the user wants to have a single expression, parentheses can be used
(e.g. (21-33) (14+16))
>
> However, no one has commented on having trouble with this before.
>
> Putting in multi-dimensional array support adds more ambiguity along the
> same lines, this time interacting with array literals.
>
> i[1][2] might mean two parameters i[1] and an array literal [2] or it
> might mean one parameter accessing a multidimensional array i[1][2].
Or both? As in multidimensional arrays are arrays of arrays. What we
want, I'm guessing, is the possibility to easily pass i[1] as an array
parameter instead of using something like i[i, *].
>
> Changing the syntax used to specify array literals would resolve this, as
> would putting in specific delimiters in the app block. The former is
> probably the least intrusive in terms of already written user scripts.
>
More information about the Swift-devel
mailing list