简体   繁体   中英

Are you aware of any lexical analyzer or lexer in Qt?

Are you aware of any lexical analyzer or lexer in Qt? I need it for parsing text files.

QXmlReader has allows you to define a lexical handler, for plain text you can use QRegExp . If you want a full blown lexical analyzer take a look at Quex (not Qt specific, but is used to generate a C++ code based on your input).

It is kinda interesting how Qt has evolved into an all-compassing framework that makes the programmer that uses it believe that anything that is useful has to start with the letter Q. Very dot-netty. Qt is just a class library that runs on top of the language, it doesn't preclude using everyday libraries that get a job done. Especially when that's a library that has little to do with presenting a user interface, the job that Qt does so well.

There are many libraries that get lexical analysis and parsing done well. That starts with Lex and Yacc, Flex and Bison next, etcetera. You only have to Qt enable it for error messages, they readily support that.

If you can use it... (it's quite complex if you ask me!) there is the Spirit library from boost.

This can be used "dynamically" in the sense that it does not generate other files that you have to then compile to run your parser.

http://www.boost.org/doc/libs/1_48_0/libs/spirit/doc/html/spirit/lex.html

But it's complex (to my point of view) since even just the #include don't always work right (if you include them in the wrong order or the documentation may not match the tutorial, I'm not too sure.) Yet, I see many people using it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM