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
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
Search the forum (and/or Google) for "finite state machine".
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.
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
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
You should start from .h file and define the interface of your class.
Here's a template:
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.Qt Code:
#include <QString> class RegExp { public: RegExp( const RegExp & regExp ); RegExp & operator=( const RegExp & regExp ); ... };To copy to clipboard, switch view to plain text mode
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
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?![]()
Bookmarks