python bytecode grammar

Diez B. Roggisch deets at web.de
Fri Jun 10 16:46:32 CEST 2005


M1st0 wrote:
> Ops yes is BNF :P Bacus Normal Form if I am not wrong...
> 
> However......
> 
> I'am tryng to recognizing patterns in a bytecoded file in orderd to
> optimize...
> 
> But I would like to "parse"  i.e reconstruct it in something like a
> tree..
> in order to apply rules on a tree recursively.

But bytecode is like assembly - there is no tree-structure. A opcode is 
followed by a number of arguments, and oopcodes are in a seqence.

However the bytecode is _generated_ from the AST somehow. Maybe you can 
work on that. Also take a look at psyco, it already does optimizations 
for numeric calculations.

Besides: I serously doubt you can do much optimization on the 
bytecodelevel itself, as it is very highlevel. The optimization efforts 
like in psyco don't alter bytecode - they replace it....

Diez



More information about the Python-list mailing list