-
Notifications
You must be signed in to change notification settings - Fork 223
Description
Consider:
X is sum taking product taking a, b, product taking c, d.
At a purely grammatical level, this syntax is ambiguous between:
x = sum(product(a,b), product(c,d))x = sum(product(a,b,product(c,d))x = sum(product(a,b,product(c),d)x = sum(product(a), b, product(c), d)
One solution here is define the grammar in terms of functions with specific parameter counts, so the parser knows that product takes exactly two arguments and disambiguates accordingly. (This would mean explicitly supporting zero args, one arg, two args, three args, and so on, so we'd need to decide an arbitrary upper limit for the maximum number of arguments a program can take, and default/optional arguments or params style arguments-as-a-list would never be supported.)
Another solution would be to prohibit function calls inside function calls. I don't like that.
A third solution would be to use another character - the semi-colon ;, say - to denote the end of an argument list:
sum taking product taking a; b, product taking c, d.
(equivalent to sum(product(a), b, product(c,d))
sum taking product taking a, b; product taking c; d.
(equivalent to sum(product(a,b), product(c), d)
sum taking product taking a, b, product taking c; d
(equivalent to sum(product(a,b,product(c),d)
I'm favouring the third option here - and I suspect there might be other scenarios (nested lists?) where this syntax proved useful.
Thoughts?