Results 1 to 20 of 23

Thread: best way to parsing this line

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: best way to parsing this line

    Let me put it this way - the parser is something that deals with grammar (syntax), not logic (semantics). I suggest you parse your file into some kind of list or tree or whatever else you want and then perform semantic checks or actions on the resulting structure. Of course you can combine the two operations to save time when you can deduce while parsing that the result will be useless (like when the number of items in each line differs). If you wrap that all in a class with different methods performing different tasks, the code should be simple and easily readable.

  2. #2
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: best way to parsing this line

    OK, I could put it in a vector <vector<double> > as you can see before and then check everything (eg. find the number of line, the number of element of a line, the min max values of each single line). All those need to scan the vector of vector from begin to end; so I thought to do this while parsing (but It'll soil the parser). So, read what you have write above, I'm thinking to do one method that while parsing do: push_back into the vector, increment the number of elements, and check for min, max. Are you mean this? With this parser appear more light...thanks
    Regards

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

    Default Re: best way to parsing this line

    There is no single correct way to complete the task. You may do as you see fit depending on what's most important for you.

  4. #4
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: best way to parsing this line

    Yes, but I'm looking for the most elegant......
    Regards

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

    Default Re: best way to parsing this line

    In what terms? According to me the most elegant way is to do it in two passes - one constructs the syntax tree and the other validates and operates on it.

  6. #6
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: best way to parsing this line

    boost spirit is a good parser to use.i've used it for a simple scripting language.
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

Similar Threads

  1. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  2. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16:48
  3. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

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.