[Python-Dev] Any grammar experts?

Neil Girdhar mistersheik at gmail.com
Sun Jan 25 04:31:26 CET 2015


Thanks, I had tried it and got the ambiguities, but I wasn't sure if those
would disappear with editing some peripheral file.

Yes, you're right about the set branch.

Thank you,

Neil

On Sat, Jan 24, 2015 at 10:29 PM, Guido van Rossum <guido at python.org> wrote:

> Have you tried it yet?
>
> I think you have to inline dictpopulator, because dictpopulator can start
> with the same tokens as test, and the parser doesn't backtrack. So it
> wouldn't know how to decide whether to take the dictpopulator branch or the
> set branch. If you inline it, the parser will know, because it does
> something clever within the rule.
>
> As-is, I get a lot of errors from pgen about ambiguity. This one seems to
> work (but you still have to adjust the code generator of course):
>
> dictorsetmaker: ( ((test ':' test | '**' test) (comp_for | (',' (test ':'
> test | '**' test))* [','])) |
>                    (test (comp_for | (',' test)* [','])) )
>
> Also I presume you want a similar treatment for the set branch (replace
> both tests with (test | '*' test).
>
> Good luck! There's plenty of code to crib from for the code generation.
>
> --Guido
>
> On Sat, Jan 24, 2015 at 6:10 PM, Neil Girdhar <mistersheik at gmail.com>
> wrote:
>
>> To finish PEP 448, I need to update the grammar for syntax such as
>>
>> {**x for x in it}
>>
>> and
>>
>> {1:2, 3:4, **a}
>>
>> It's been a long time since I've looked at grammars and I could really
>> use the advice of an expert.  I'm considering replacing:
>>
>> dictorsetmaker: ( (test ':' test (comp_for | (',' test ':' test)* [',']))
>> |
>>                   (test (comp_for | (',' test)* [','])) )
>>
>> with:
>>
>> dictpopulator: test ':' test | '**' test
>> dictorsetmaker: ( (dictpopulator (comp_for | (',' dictpopulator)* [',']))
>> |
>>                    (test (comp_for | (',' test)* [','])) )
>>
>> Am I headed in the right direction?  Of course I will need to edit
>> parsermodule.c and ast.c.
>>
>> Best,
>>
>> Neil
>>
>> _______________________________________________
>> Python-Dev mailing list
>> Python-Dev at python.org
>> https://mail.python.org/mailman/listinfo/python-dev
>> Unsubscribe:
>> https://mail.python.org/mailman/options/python-dev/guido%40python.org
>>
>>
>
>
> --
> --Guido van Rossum (python.org/~guido)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150124/64105c70/attachment.html>


More information about the Python-Dev mailing list