Results 1 to 9 of 9

Thread: reg expression

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

    Default reg expression

    Hi,
    I have a regular expression. I had to write the .h and .cpp to rappresent it! THen I have to write a parser for it. Any suggests? Do anyone know any "good" link for same code examples in C++?

    thanks
    Regards

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

    Default Re: reg expression

    Search the forum (and/or Google) for "finite state machine".

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: reg expression

    When it comes to parsing the Dragon Book is one of the best books. Introduction to Automata Theory, Languages, and Computation by J. Hopcroft and J. Ullman covers the theoretical side of regular expressions and Mastering Regular Expressions by J. Friedl a presents practical approach (but after reading this one you will only know how to use them, not how to code your own regexp engine).

    Check QRexExp sources to see an example implementation.

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

    Default Re: reg expression

    I read dragon book but at the moment my problem is the simple class to rappresent a SIMPLE reg. expression. So QregExpr is very difficulty for me. I'm reading it but I think I need a simpler example to start. I can't write the class because I don't understand what "rappresent regular expression with class" means....thanks
    Last edited by mickey; 4th July 2007 at 17:34.
    Regards

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: reg expression

    Quote Originally Posted by mickey View Post
    I can't write the class because I don't understand what "rappresent regular expression with class" means
    Probably you have to write a class similar to QRegExp.

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

    Default Re: reg expression

    hi, I can't understand that class so well because it uses many unknows qt methods. Leave out the problem of code a Parser. now, to write .h and .cpp to rappresent a reg expression (that include: characters, list symbol [c1-c2], and '|' symbol). How can I represent it? (Maybe should I code an lexycal analizer or a symbol table?. )
    Regards

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: reg expression

    Quote Originally Posted by mickey View Post
    now, to write .h and .cpp to rappresent a reg expression (that include: characters, list symbol [c1-c2], and '|' symbol). How can I represent it?
    You should start from .h file and define the interface of your class.

    Here's a template:
    Qt Code:
    1. #include <QString>
    2.  
    3. class RegExp
    4. {
    5. public:
    6. RegExp( const QString & regExp );
    7. RegExp( const RegExp & regExp );
    8. RegExp & operator=( const RegExp & regExp );
    9. ...
    10. };
    To copy to clipboard, switch view to plain text mode 
    So far it allows you to create and copy regular expression objects. Now you have to add one or more methods that will allow you to use it.

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

    Default Re: reg expression

    excuse me: then then problem of to treat symbols '|' and '[list] and '*' (kleene star) is here, in this stage or only in the parser stage? I thought I need treat those symbols in definition of reg expression. And this is what I can't understand (how to treat only | for example)
    thanks
    Regards

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: reg expression

    Quote Originally Posted by mickey View Post
    I thought I need treat those symbols in definition of reg expression. And this is what I can't understand (how to treat only | for example)
    IMO this should be hidden in the implementation. If you want to use an object that represents a regular expression you are not interested in the structure of that expression (for example whether it contains | and where) , but whether given string matches it or not. Therefore the interface of your class should contain methods that will allow you to use regular expressions and the parser, automaton and other stuff should be hidden in .cpp file.

    PS. Kleene's star in Polish is called "operator tranzytywnego domknięcia konkatenacji". Great name, isn't it?

Similar Threads

  1. Regular Expression for QDate [YYYY/MM/DD] format
    By bera82 in forum Qt Programming
    Replies: 6
    Last Post: 3rd August 2019, 09:40
  2. How to get a QString from a file (use regular expression)
    By fengtian.we in forum Qt Programming
    Replies: 16
    Last Post: 31st May 2007, 11:06

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.