1

I am trying to gather information with regards to the grammar of PostgreSQL (and, in the future, other database systems) to be used in a website (frontend Angular, backend Java). It seems that the grammar rules are contained in the file gram.y (https://github.com/postgres/postgres/blob/master/src/backend/parser/gram.y).

My question is the following: can I parse this grammar in both Java and Javascript, and how would I go about this? Having a single grammar file which can be read by Jison (http://zaa.ch/jison/docs/) or JavaCC (https://javacc.org/) would be ideal, as I would have a single truth. Basing myself on the source code of postgres itself would be as well a bonus, as I would have access to the various versions of the database.

  • Near duplicate: https://stackoverflow.com/questions/33416547/how-to-list-lex-yacc-or-flex-bison-patterns – rici Aug 10 '18 at 19:29
  • As far as I understand it, `bison -v gram.y` outputs a C parser. But it is unclear to me how I would go about extracting the rules and actually using it in a java/javascript environment. So, I'm not sure why this is a near duplicate of the question you posted? In any case, apparently bison can output java code too, but that fails for the `gram.y` file of postgres in my case. – Joachim Nielandt Aug 11 '18 at 19:50
  • 1
    The point of `bison -v` is not the parser, but rather the grammar output in the `.output` file, which can easily be modified to jison or Java CUP format. That's what the question and answer are about; perhaps they are worth rereading with that in mind. The answer doesn't say "of course, you will still need to do some coding" (because there's no automatic way to turn the actions written in C into another language), which is why I didn't mark it as a duplicate. – rici Aug 11 '18 at 20:27
  • Apologies, the `gram.output` file went under my radar. It seems that the `.output` file is indeed the way to go, although I'm not completely sure at this point whether it's *easy* to modify it to jison or java cup :). I have some reading to do... Thanks for pointing me in the right direction! – Joachim Nielandt Aug 11 '18 at 20:45

1 Answers1

0

see https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form

javacc supports bnf, I am not sure about jison

chris
  • 398
  • 2
  • 11
  • 2
    Well, I would like to avoid having to build my own BNF productions for a mammoth such as postgres, not to mention having to take into account the various versions of the platform. If you would know where to find a parseable BNF ruleset, however, that would be great. – Joachim Nielandt Aug 11 '18 at 19:53