Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a BNF grammar available for SQL?

I'd rather not create the grammar myself. I did download a 'grammar' but it is written in a non-standard form for ANTLR or Yacc and it contains lexer statements. It would take me some time to separate the two and to introduce the correct syntax for a parser generator.

like image 896
lostbits Avatar asked Mar 05 '23 12:03

lostbits


1 Answers

There are lots of SQL grammars suitable for parser generators, since most SQL processors use parser generators to produce their parsers. These might or might not serve your needs, depending on which SQL dialect you are interested in, and which parser generator you are planning on using.

Here are a few examples. These are all taken from official code repositories for the respective databases, which I believe avoids the "opinion-based" criterion for avoiding resource requests. There are also many non-official grammars scattered around the internet, particularly on Github, but not all of them are correct or usable.

  • MySQL, using Bison/C++

  • MySQL, from MySQL Workbench, using Antlr 4.5/C++

  • Sqlite3, using Lemon/C

  • PostgresQL, using Bison/C

like image 115
rici Avatar answered Mar 15 '23 03:03

rici