antlr4 sql grammar
Asked Answered
J

4

19

Does ANTLR4 have a sql grammar available? If so, where can I find it?

There is a link from the ANTLR wiki, but the link is broken: grammar list

Johny answered 22/1, 2013 at 17:22 Comment(0)
R
28

No, at the time of this writing, there is no v4 SQL grammar.

All v4 grammar will be put into the following Github repository (as far as I can remember from the ANTLR mailing list): https://github.com/antlr/grammars-v4

The v3 grammars here now: http://antlr3.org/grammar/list.html

EDIT - April 2018

There is now a user contributed MySQL grammar here: [dead link removed]

EDIT - February 2020

MySQL, T-SQL, PL/SQL, and SQLite grammars are all available here: https://github.com/antlr/grammars-v4/tree/master/sql

Rob answered 22/1, 2013 at 18:34 Comment(4)
I found the v3 grammars here: http://antlr3.org/grammar/list.htmlJohny
@Chris, yeah, I saw Sam/280Z28 mention this in your other question but forgot to update this answer. Thanks.Rob
There is a sqlite grammar out there, which is somewhat close.Sinecure
I can see mysql grammar in ANTLR v4 here: github.com/antlr/grammars-v4/tree/master/mysqlVyborg
K
8

Currently, there are plenty of sql grammars for v4 as well:

  1. MySQL
  2. PL/SQL
  3. T-SQL (Microsoft SQL Server) by KvanTTT
Knuth answered 26/3, 2016 at 19:25 Comment(0)
F
3

As of Feb/6/2017, there is ANTLR4 file for t-sql, but it is community maintained, and not complete, I found many SQL statements valid to SQLServer but not able to be parsed by this grammar.

Fadiman answered 6/2, 2017 at 21:30 Comment(0)
A
1

As mentioned by the other users, there are SQL grammars available online but they are not complete. I would suggest that the best way would be to use the incomplete grammar and add the grammar that is not present on the top of it as and when you require. For example, If you require translation for join clause and that is not present, then just add it on the top of it. Just make sure that the grammar you write does not break any existing grammar

This is what I did in my internship where I had to make a tool to convert SAS scripts to python. SAS being proprietary, it's grammar was not available. So we built everything from scratch.

Arv answered 1/8, 2018 at 16:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.