Results 1 to 13 of 13

Thread: Parse Text File with Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Parse Text File with Qt

    Quote Originally Posted by rhf417 View Post
    Is there an easier way? For example, will QRegExp be capable of doing my job?
    Bits of the task certainly. However, matching whole, nested compund structures where deelimiters must be balanced rapidly becomes very difficult.
    I do not want to parse the text file from scratch (e.g. use QFile and QString). I am interested in QLALR. But it is hard to start with QLALR due to the poor documentations.
    Traditional lex/yacc is powerful. However, it requires additional learning process for a person (like me) who never use it before. I am not sure whether it is worth learning lex/yacc for this simple job I have.
    Fair call on the QLALR documentation... there's a high level of assumed knowledge in the examples that are around. You might like the better documented GOLD Parsing System.

    I think the effort of learning lex/yacc, or the theory of operation, is well worth it for the potential to help in many future projects. However, time and effort required to learn this must be offset by your circumstance. Are you parsing one file, or thousands? Are they very variable (numbers of net-lists etc.)? Is the grammar we can see only a subset of a larger possible grammar?

  2. The following user says thank you to ChrisW67 for this useful post:

    rhf417 (17th May 2010)

  3. #2
    Join Date
    Jun 2009
    Posts
    11
    Thanks
    5

    Default Re: Parse Text File with Qt

    I did some research on the parser generator these days and found a good tool - "Visual Parser++" which is easy to learn. I am working under windows and C++. I feel that Visual Parser++ is very convenient to use. I have parsed my text file with it successfully. The only drawback is that there will be no support since Sandstone does not exist anymore.

    Basically, the text file shown above is the only file I need to handle. I only need to parse one file at a time, not thousand of them. The grammar you can see here is not all, but the rest are very similar. I would like to spend more time to learn Lex/Yacc and QLALR later, but not now, I guess.

    For me, tbscope's method is the one I would like to apply to my current project. It looks quite straightforward and does not require any additional tools. Thank you very much. Thanks all for all the valuable advices.

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Parse Text File with Qt

    Quote Originally Posted by rhf417 View Post
    Basically, the text file shown above is the only file I need to handle. I only need to parse one file at a time, not thousand of them.
    It's not the number of files you wish to parse at a time that may be a problem. The problem is you may want to parse different files (with different contents) in general.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #4
    Join Date
    Jun 2009
    Posts
    11
    Thanks
    5

    Default Re: Parse Text File with Qt

    Quote Originally Posted by wysota View Post
    It's not the number of files you wish to parse at a time that may be a problem. The problem is you may want to parse different files (with different contents) in general.

    I understand. If there are many different types of files to parse, a parser generator would be the better choice.

  6. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Parse Text File with Qt

    Be careful and do your research. I've fallen into this trap before - build a parser for the files I had that worked brilliantly. Then, a month later I had some more files and it only parsed one of them correctly. I didn't then have the time to fix the program properly to parse them all, so hacked it up to make it work. Do that a few times and you have a nightmare of an application to maintain or a range of application that parse different variations.

    Its so much easier to do it right from the beginning.

  7. #6
    Join Date
    Jan 2013
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Parse Text File with Qt

    Does anyone know where to find an old copy of Visual Parse++? It is a great tool to teach parsing. We have been searching for it, and all we can find are URLs that point to the no longer existing Sandstone site.

Similar Threads

  1. parse items of QTreeWidget into file/QSettings
    By Mystical Groovy in forum Qt Programming
    Replies: 3
    Last Post: 8th November 2009, 17:52
  2. Best way to load and parse an HTML file ??
    By tuthmosis in forum Qt Programming
    Replies: 8
    Last Post: 23rd August 2008, 12:06
  3. Replies: 13
    Last Post: 21st June 2006, 22:22
  4. How to parse this XML file ?
    By probine in forum Qt Programming
    Replies: 7
    Last Post: 4th April 2006, 10:05
  5. Parse a pickle file
    By karye in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2006, 18:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.