<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jun 28, 2013 at 7:01 PM, Amaury Forgeot d'Arc <span dir="ltr"><<a href="mailto:amauryfa@gmail.com" target="_blank">amauryfa@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">2013/6/28 Pynix Wang <span dir="ltr"><<a href="mailto:pynix.wang@gmail.com" target="_blank">pynix.wang@gmail.com</a>></span><br>
<div class="gmail_extra"><div class="gmail_quote"><div><div class="h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div dir="ltr">I want use coffeescript function syntax to write python lambda expression so I modified the Grammar file.<div><br></div><div>```</div><div><div>atom: ('(' [yield_expr|testlist_comp|vararglist] ')' |</div>


<div>       '[' [testlist_comp] ']' |</div><div>       '{' [dictorsetmaker] '}' |</div><div>       NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False')</div>


<div>trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME | '->' text<br></div><div>```</div><div><br></div><div>but when I write</div><div>```</div>
<div>(x,y=1)->x+y</div><div>```</div><div>the parser doesn't go into vararglist.</div></div></div></blockquote><div><br></div></div></div><div>This grammar is not LL(1) anymore (it's probably LALR now)<br></div>
<div>when seeing "x", it has the choice between testlist_comp and vararglist,</div>
<div>and the first one is picked.</div><div>Python's parser generator only supports LL(1) grammars.</div></div></div></div></blockquote><div><br></div><div style>Indeed. You may be able to make this work, but you'd have to fold the bits of vararglist you need into testlist_comp, 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):</div>
<div style><br></div><div style>testlist_comp: (test|star_expr) ['=' test]( comp_for | (',' (test|star_expr) ['=' test])* [','] ) </div></div><div><br></div>-- <br>Thomas Wouters <<a href="mailto:thomas@python.org" target="_blank">thomas@python.org</a>><br>
<br>Hi! I'm an email virus! Think twice before sending your email to help me spread!
</div></div>