[Python-Dev] add new lambda syntax (original) (raw)

Pynix Wang pynix.wang at gmail.com
Sat Jun 29 09:05:28 CEST 2013


http://aruld.info/lambda-expressions-in-java-8-adopts-c-style-syntax/

Lambda expressions in Java 8 adopts C# style syntax.

On Sat, Jun 29, 2013 at 1:39 AM, Thomas Wouters <thomas at python.org> wrote:

On Fri, Jun 28, 2013 at 7:01 PM, Amaury Forgeot d'Arc <amauryfa at gmail.com>wrote: 2013/6/28 Pynix Wang <pynix.wang at gmail.com>

I want use coffeescript function syntax to write python lambda expression so I modified the Grammar file.

_ _atom: ('(' [yieldexpr|testlistcomp|vararglist] ')' |_ _'[' [testlistcomp] ']' |_ _'{' [dictorsetmaker] '}' |_ _NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')_ _trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME | '->' text_ _ but when I write _ _(x,y=1)->x+y_ _ the parser doesn't go into vararglist.

This grammar is not LL(1) anymore (it's probably LALR now) when seeing "x", it has the choice between testlistcomp and vararglist, and the first one is picked. Python's parser generator only supports LL(1) grammars. Indeed. You may be able to make this work, but you'd have to fold the bits of vararglist you need into testlistcomp, then reject invalid syntax that matches the grammar (like "(x=expr for ...)" or "((x+1)=expr)" or "(*foo=1)") in the compiler. Something like (untested): testlistcomp: (test|starexpr) ['=' test]( compfor | (','_ _(test|starexpr) ['=' test])* [','] ) -- Thomas Wouters <thomas at python.org> Hi! I'm an email virus! Think twice before sending your email to help me spread! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130629/8f592588/attachment.html>



More information about the Python-Dev mailing list