How to process syntax errors

Chris Angelico rosuav at gmail.com
Wed Oct 12 11:00:04 EDT 2016


On Thu, Oct 13, 2016 at 12:46 AM, Pierre-Alain Dorange
<pdorange at pas-de-pub-merci.mac.com> wrote:
> Terry Reedy <tjreedy at udel.edu> wrote:
>
>> > Using this function, the code is "compiled".
>> > I do not think this function is often used and most python project
>> > simply use the interpreter (which do a small translation into byte-code
>> > to be faster and check syntax error before running interpretation
>>
>> You seem to be confusing CPython with, for instance, simple BASIC
>> interpreters that tokenized the code, translated keywords to function
>> numbers, and did other 'small translations' before execution.
>>
>> The CPython compiler lexes (tokenizes), ll(1) parses to a syntax tree,
>> does some analysis and transformation of the tree, and translates it to
>> the bytecode for an stack machine.  All done using standard compiler theory.
>
> Yes i'm probably confusing things ; i've not explore Python
> implentation, i'm just an amateur developer.
> But what confuse me, is that Python require "real live" interpratation
> of the code to work properly (or perhaps i also confuse on that but
> Python rely on interpretation of the code to conform to its own
> standard, ie variables can change type during execution...)

Variables don't have types; objects do. A variable in Python always
holds a thing of type 'object', and everything in Python is a subclass
of object. This doesn't stop Python from being compiled - you could do
the exact same thing in C++ or Java.

ChrisA



More information about the Python-list mailing list