Questions about MySQLLexer.g4 and MySQLParser.g4 for mysql grammar

410 views
Skip to first unread message

ssarkaray...@gmail.com

unread,
Sep 12, 2016, 4:14:15 PM9/12/16
to antlr-discussion
Hello,

There are two separate files MySQLLexer.g4 and MySQLParser.g4 for grammar specifications of mysql grammar in antlr / grammars-v4. I compiled as

antlr4 MySQLLexer.g4  MySQLParser.g4
javac MySQL*.java

Then I tried :
grun MySQLParser parse -gui ./examples/example1.sql

I got error:
Exception in thread "main" java.lang.ClassCastException: class MySQLParser
at java.lang.Class.asSubclass(java.base@9-ea/Class.java:3656)
at org.antlr.v4.runtime.misc.TestRig.process(TestRig.java:159)
at org.antlr.v4.runtime.misc.TestRig.main(TestRig.java:143)

Then I tried:
grun MySQL parse -gui ./examples/example1.sql
I got error:
No method for rule parse or it has arguments

Can someone please tell me how to use grun with correct syntax for mysql grammar ?

Thanks,
SS


Jim Idle

unread,
Sep 12, 2016, 8:34:49 PM9/12/16
to antlr-discussion
The name of the start rule in the Parser is obviously not 'parse' so work out what the start rule is called and invoke that :)





--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ssarkaray...@gmail.com

unread,
Sep 14, 2016, 12:42:16 PM9/14/16
to antlr-discussion
Yes it worked when I used select_clause as the start rule.  I could not find insert_clause or update_clause 
in the rules for the grammar.  Does anyone know why the mysql grammar is not having everything in mysql 5.6 
syntax?  I am attaching grammars for mysql.  Where can I get the complete grammar for ANTLR4 ?

Regards.
MySQLLexer.g4
MySQLParser.g4

Mike Lischke

unread,
Sep 15, 2016, 1:54:32 PM9/15/16
to antlr-di...@googlegroups.com
> Yes it worked when I used select_clause as the start rule. I could not find insert_clause or update_clause
> in the rules for the grammar. Does anyone know why the mysql grammar is not having everything in mysql 5.6
> syntax? I am attaching grammars for mysql. Where can I get the complete grammar for ANTLR4 ?

The MySQL grammar in the ANTLR grammar repository is a very very simple one. For a complete grammar look here: https://github.com/mysql/mysql-workbench/blob/master/library/mysql.parser/grammar/MySQL.g. This is however written for ANLTR3, so you have to convert it first to ANTLR4. In the same folder is a second grammar without tree rewriting. This one should be quite easy to convert. The main work is to convert the C action code to your target language.

Mike
--
www.soft-gems.net

Reply all
Reply to author
Forward
0 new messages