My problem is :
I want to write a application aim to translate some information within a special formatted text to a custom struct. The organism like brackets is allowed in the text.
For example, we can use M31 to open a section ,and use M30 to close the section. Within each section another some sections(also opened by M31 and closed by M30) can exist. And these inner sections was parallel.

Below is a practical example:

Qt Code:
  1. M31 //Open the outerest level section, we can call it the first level section
  2.  
  3. M31 //Open the second level section, which is included in the first level section.
  4. M31 //Open the third level section, which is included in the second level section.
  5. some operate code // Some codes belong to the third level section.
  6. M30 //Close the third level section.
  7. some operate code //Codes belong to the second level section. And more important
  8. is these codes will make some changes on the result of the
  9. third level codes. This is where is my problem. I can not figure
  10. out how to deal with this relationship.
  11. M30 //Close the second level section.
  12.  
  13. M31 //Open another second level section, which is parallel with the existing second
  14. level section.
  15. M31
  16. some operate code
  17. M30
  18. some operate code
  19. M30 //Close the second parallel second level section.
  20. some operate code //The codes belong to the outerest level section(the first level
  21. section). And these codes will also make some changes on
  22. the results of the two inner second level sections.
  23. M30 //Close the outerest section(the first level section).
To copy to clipboard, switch view to plain text mode 


I want to use somethind like List or Stack to solve the problem. But when I try to recognize which is the level of the operate codes within a section, I have some problems. Because the codes of outter section will be excuted after the codes of inner section. So it is very important to recognize WHICH level the codes are belong to.

Thanks a lot!