title: Reusing MySQL parser
body: <p>I'm working on SQL <a href="http://en.wikipedia.org/wiki/Intrusion_detection_system" rel="noreferrer">intrusion detection system (IDS)</a> 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 <code>sql/sql_lex.cc</code> and a syntax analyzer built with bison from <code>sql/sql_yacc.y</code>. 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.</p>
  
  <p>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?</p>
  
  <p>Thanks</p>