I'm working on SQL [intrusion detection system (IDS)](http://en.wikipedia.org/wiki/Intrusion_detection_system) and I need do parse incoming SQL queries. Writing own SQL parser is a long term task and it will never exactly reflect the logic used in native parser.
I found out that MySQL has a lexical analyzer with main source file `sql/sql_lex.cc` and a syntax analyzer built with bison from `sql/sql_yacc.y`. I am really interested in reusing this robust solutions. I am building my IDS in C/C++, so I am looking for some way to connect MySQL parser with my detection system.

I was wondering if It is possible to reuse the MySQL parser (lexical+syntax analyzer) to get the structure of SQL query in some logical form e.g. syntax tree. Would it be possible? Are there some related text, tutorials or projects?

Thanks