mysql parser/grammer is not working

54 views
Skip to first unread message

Snowy

unread,
Nov 20, 2016, 10:29:49 AM11/20/16
to antlr-discussion

Just trying out mysql grammer and it's not parsing a simple SQL as expected. Did I do any mistake? My goal is to get the table name and columns names identified by the parser. Using ANTLR version 4.5.3

import com.my.MySQLLexer;
import com.my.MySQLParser;
import org.antlr.v4.runtime.*;
import java.io.StringReader;
public class ANTLRDemo {
  public static void main(String[] args) throws Exception {
    CharStream stream = new ANTLRInputStream(new StringReader("SELECT * FROM TAB1;"));

    MySQLLexer m = new MySQLLexer(stream);

    CommonTokenStream tokens = new CommonTokenStream(m);

    MySQLParser p1 = new MySQLParser(tokens);

    p1.getBuildParseTree();
    p1.expression();

    System.out.println("p1 = " + p1.table_name().getText() + " -->> " + p1.column_list().getText());


  }
}

Mike Lischke

unread,
Nov 20, 2016, 10:44:06 AM11/20/16
to antlr-di...@googlegroups.com
This grammar is extremely simple and does not even cover the * operator. For a complete grammar see MySQL Workbench: https://github.com/mysql/mysql-workbench/blob/master/library/mysql.parser/grammar/MySQL.g. This grammar is still for ANTLR3 (and the C runtime), so you need some rework of it to make it work with ANLTR4 (mostly remove all tree rewriting and convert the action code).

I'm working on a full MySQL grammar for ANTLR4, which will be released with the next MySQL Workbench version (still some months away).


Reply all
Reply to author
Forward
0 new messages