<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 22, 2013 at 7:29 AM, Benjamin Peterson <span dir="ltr"><<a href="mailto:benjamin@python.org" target="_blank">benjamin@python.org</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">2013/11/22 anatoly techtonik <<a href="mailto:techtonik@gmail.com">techtonik@gmail.com</a>>:<br>


<div><div class="h5">> On Fri, Nov 15, 2013 at 5:43 PM, Benjamin Peterson <<a href="mailto:benjamin@python.org">benjamin@python.org</a>> wrote:<br>
>> 2013/11/15 anatoly techtonik <<a href="mailto:techtonik@gmail.com">techtonik@gmail.com</a>>:<br>
>>> On Tue, Nov 12, 2013 at 5:08 PM, Benjamin Peterson <<a href="mailto:benjamin@python.org">benjamin@python.org</a>> wrote:<br>
>>>> 2013/11/12 anatoly techtonik <<a href="mailto:techtonik@gmail.com">techtonik@gmail.com</a>>:<br>
>>>>> On Sun, Nov 10, 2013 at 8:34 AM, Benjamin Peterson <<a href="mailto:benjamin@python.org">benjamin@python.org</a>> wrote:<br>
>>>>>> 2013/11/10 anatoly techtonik <<a href="mailto:techtonik@gmail.com">techtonik@gmail.com</a>>:<br>
>>>>>>> <a href="http://hg.python.org/cpython/file/1ee45eb6aab9/Parser/Python.asdl" target="_blank">http://hg.python.org/cpython/file/1ee45eb6aab9/Parser/Python.asdl</a><br>
>>>>>>><br>
>>>>>>> In Assign(expr* targets, expr value), why the first argument is a list?<br>
>>>>>><br>
>>>>>> x = y = 42<br>
>>>>><br>
>>>>> Thanks.<br>
>>>>><br>
>>>>> Speaking of this ASDL. `expr* targets` means that multiple entities of<br>
>>>>> `expr` under the name 'targets' can be passed to Assign statement.<br>
>>>>> Assign uses them as left value. But `expr` definition contains things<br>
>>>>> that can not be used as left side assignment targets:<br>
>>>>><br>
>>>>>     expr = BoolOp(boolop op, expr* values)<br>
>>>>>          | BinOp(expr left, operator op, expr right)<br>
>>>>>          ...<br>
>>>>>          | Str(string s) -- need to specify raw, unicode, etc?<br>
>>>>>          | Bytes(bytes s)<br>
>>>>>          | NameConstant(singleton value)<br>
>>>>>          | Ellipsis<br>
>>>>><br>
>>>>>          -- the following expression can appear in assignment context<br>
>>>>>          | Attribute(expr value, identifier attr, expr_context ctx)<br>
>>>>>          | Subscript(expr value, slice slice, expr_context ctx)<br>
>>>>>          | Starred(expr value, expr_context ctx)<br>
>>>>>          | Name(identifier id, expr_context ctx)<br>
>>>>>          | List(expr* elts, expr_context ctx)<br>
>>>>>          | Tuple(expr* elts, expr_context ctx)<br>
>>>>><br>
>>>>> If I understand correctly, this is compiled into C struct definitions<br>
>>>>> (Python-ast.c), and there is a code to traverse the structure, but<br>
>>>>> where is code that validates that the structure is correct? Is it done<br>
>>>>> on the first level - text file parsing, before ASDL is built? If so,<br>
>>>>> then what is the role of this ADSL exactly that the first step is<br>
>>>>> unable to solve?<br>
>>>><br>
>>>> Only valid expression targets are allowed during AST construction. See<br>
>>>> set_expr_context in ast.c.<br>
>>><br>
>>> Oh my. Now there is also CST in addition to AST. This stuff -<br>
>>> <a href="http://docs.python.org/devguide/" target="_blank">http://docs.python.org/devguide/</a> - badly needs diagrams about data<br>
>>> transformation toolchain from Python source code to machine<br>
>>> execution instructions. I'd like some pretty stuff, but raw blogdiag<br>
>>> hack will do the job <a href="http://blockdiag.com/en/blockdiag/index.html" target="_blank">http://blockdiag.com/en/blockdiag/index.html</a><br>
>>><br>
>>> There is no set_expr_context in my copy of CPython code, which<br>
>>> seems to be some alpha of Python 3.4<br>
>><br>
>> It's actually called set_context.<br>
><br>
</div></div>> Ok. So what is the process?<br>
><br>
>  SOURCE --> TOKEN STREAM --> SENTENCE STREAM --> CST --><br>
> --> AST --> BYTECODE<br>
><br>
> Is that right?<br>
<br>
I don't know what sentence stream is, but otherwise looks right.</blockquote><div><br></div><div>If you want more of an overview: <a href="http://pyvideo.org/video/2331/from-source-to-code-how-cpythons-compiler-works">http://pyvideo.org/video/2331/from-source-to-code-how-cpythons-compiler-works</a> </div>

</div></div></div>