Python grammar..
Joshua Marshall
jmarshal at mathworks.com
Thu Jun 14 10:34:54 EDT 2001
Remco Gerlich <scarblac at pino.selwerd.nl> wrote:
> Joshua Marshall <jmarshal at mathworks.com> wrote in comp.lang.python:
>
>> Choose a parsing rule and use parens to group things differently.
>> Python (and many other languages) already need parens to do this for
>> binary operators ("1-2-3" parses as "(1-2)-3").
>>
>> So you'd probably have to write "Spam(scramble(eggs), ham)" as
>> "Spam (scramble eggs) ham".
> Why wouldn't that parse as (Spam (scramble eggs)) (ham) ?
It parses however you define the parsing rule. Since Python functions
can take multiple arguments, I think it's more useful to include as
many arguments as you can when parsing function applications.
> If you're going to make the parentheses mandatory everywhere you've just
> taken a step back to Lisp...
Well, first of all Python _does_ currently require parens for every
function call. This alternate syntax would remove the need for some
of those.
And given the parsing rule you imply with:
"Spam (scramble eggs) ham" => "(Spam (scramble eggs)) (ham)"
no amount of parens would yield an application with more than one
argument.
All this said, there are probably other problems that would come up if
you tried to graft syntax like this onto the language.
More information about the Python-list
mailing list