I'm very new in Python and I have to write an file interpretor (first ex from university).
The file looks like:

joker NAME_OF_BLOCK bla bla {
    block_field abv : bit : R ;
    block_field acd : byte : RW ;
    block_field zza : bit : R ;
    block_field aw : bit : R ;
    block_field atr : bits:5 : RW;

joker NAME_OF_BLOCK1 bla bla {
    block_field acgfhd : byte : RW ;
    block_field xc : bit : R ;
    block_field dsz : bits:5 : RW;
    block_field mnb : bits:2 : R ;

each block size ({...}) contains exactly 16 bits (byte = 8 bits).
I need to implement the following psaudo code (I wrote it):

    fin = open file("/usr/file" , 'r')
    until fin != eof
        until current line ain't starts with "joker"
            read next line
        block_name = second word in line (NAME_OF_BLOCK | NAME_OF_BLOCK1)
        indexer = 15
        while indexer != 0 and line ain't starts with '}'
            line_length = parse_line_length() -> will give me 1 for bit, 8 for byte, x for bits:x
            if line contains RW
                echo "blocker_range["indexer ":" indexer+1-line_length "]; //"block_name
            indexer -= line_length

so final result should look like:
blocker_range[14:7]; //NAME_OF_BLOCK
blocker_range[4:0]; //NAME_OF_BLOCK
blocker_range[15:8]; //NAME_OF_BLOCK1
blocker_range[6:2]; //NAME_OF_BLOCK1

Any help will be appreciated!
Thanks :)

Edited 4 Years Ago by sarelnet: inline -> code

Pseudo code is an excellent starting point !

post the file first, so that i can develop the program.

and to read a line with a paritcular string in python, we use startswith(str) function.

for line in readlines():

if line.startswith("joker"):


Thanks for helping.
I'll try to continue myself from this point.
If something goes wrong - I'll contact you.

Thanks again

This article has been dead for over six months. Start a new discussion instead.