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());
}
}