title: Parsing mysql using ANTLR4 simple example
body: <p>I am using mysql grammar from here: <a href="https://github.com/antlr/grammars-v4/tree/master/mysql" rel="nofollow noreferrer">https://github.com/antlr/grammars-v4/tree/master/mysql</a> and have generated java files using Maven. Now, I was trying to parse a query but I am not getting how to do so.  </p>
  
  <p>I basically want to 'get' all the different components of a query, like the list columns selected, where conditions, sub queries, table names, etc. But I have no idea how to proceed. I have written below code as of now. Can someone please suggest with a simple example so that I can understand the usage and take up more complex tasks? Here is my code:  </p>
  
  <pre><code>public static void main( String[] args )
  {
      String sql="select cust_name from database..table where cust_name like 'Kash%'";
      ANTLRInputStream input = new ANTLRInputStream(sql);
      MySqlLexer mySqlLexer = new MySqlLexer(input);
      CommonTokenStream tokens = new CommonTokenStream(mySqlLexer);
      MySqlParser mySqlParser = new MySqlParser(tokens);
  
      ParseTree tree = mySqlParser.dmlStatement();
      ParseTreeWalker walker = new ParseTreeWalker();
      MySqlParserBaseListener listener=new MySqlParserBaseListener();
      ParseTreeWalker.DEFAULT.walk(listener, tree);
  
  
      System.out.println(?);
  }  
  </code></pre>
  
  <p>Using the above code, I am getting the following output:  </p>
  
  <pre><code>line 1:11 no viable alternative at input '_'
  (dmlStatement _ . . _ 'Kash%')
  </code></pre>
  
  <p>Thanks For Help :)  </p>