Grammar or specification of Bison/Lemon files - grammar

I need to write parser for Bison and Lemon grammar files. I'm looking for specification or grammar of these files format. Any links will be helpful.

It is easy to get a grammar of Bison as it is bootstrapped: just get its parser from the repository.

Related

Standard EBNF grammar of JsonPath

I wan't to implement my own JsonPath library but I can not find standard definition of its grammar. I found https://github.com/kevinbirch/kanabo/blob/master/jsonpath.ebnf but it look like much more complicated. Where can I find the complete version of JsonPath grammar?
The closes thing I can find is the PostgreSQL Bison grammar, and the SQL/JSON proposal. It's not EBNF but it may serve your purpose.
PostgreSQL Bison grammar:
https://github.com/postgres/postgres/blob/0af302af40669d9bc6de7a202e4723fee39d9376/src/backend/utils/adt/jsonpath_gram.y
SQL/JSON proposal (with BNF grammar):
https://www.wiscorp.com/pub/DM32.2-2014-00025r1-sql-json-part-2.pdf

Difference in grammar parsed by JavaCC and ANTLR

JavaCC and Antlr wikipedia page says that both the parser generator works for grammar written in EBNF format. Does it mean that any grammar that can be parsed by JavaCC can also be parsed by ANTLR without modifying the grammar structure? If yes, why do we have a grammar repository for ANTLR (https://github.com/antlr/grammars-v4) ? My current understanding is that some differences do exist between the grammars parsed by JavaCC and ANTLR. Can someone please point out the differences.

Purpose of antlr in xtext

I'm new to Xtext and wondering what's the purpose of antlr is in xtext. As I've understand so far, antlr generate a parser based on the grammar and the parser then deal with the text models. Right?
And what about the other generated stuff like the editor or the ecore. Are there other components behind xtext which generate them?
Xtext needs a parser generator to produce a parser for the language you define. They could have built one of their own. They chose to use ANTLR instead.
I don't know what other third party machinery they might have chosen to use.
I've been hacking one Xtext based plugin and from what I saw I think it works like this:
Xtext has it's own BNF syntax, which is very similar to ANTLR one. In fact its it's subset.
Xtext takes your grammar, and generates the ANTLR one from it(.g file). The generated ANTLR grammar adds specific actions to your BNF rules. The actions code interacts with the Xtext runtime and (maybe) with the Eclipse itself. The .g file is processed using some older version of ANTLR and .java file is generated. This file is then compiled.

Generate EBNF from ANTLR

Anybody know of a tool, that generates EBNF from ANTLR?
ANTLR is already close to EBNF, but for documentation purpose I would like to have a clean EBNF description (without the Code in between).
With antlrworks and this its already nice to get the syntax diagrams:
java -cp antlrworks-1.1.4.jar org.antlr.works.Console -f yql.g -o output/ -sd eps
but it would like to have a bare textual description, preferable text, tex, html, xml, or similar.
I have an online tool that converts foreign grammars to W3C grammar notation. It has an ANTLR3 grammar parser, so maybe this gets close to what you were looking for. W3C notation is also useful for generating syntax diagrams.

Pretty print ANTLR grammar

Some tools output an Antlr grammar in a human-unreadable form, at least with ugly placing of parens and indentation. I'd like to transform the grammar into a more readable (standard?) form. The only reference I found is ANTLR pretty printer which is quite old, and looking at its source, it seems to be removing parts of a grammar rather than pretty print it.
How can I format/pretty print a grammar file?
I know of no tool that does this. The one you mentioned, prettyPrinter, is written in - and seems to handle only - ANTLR v2.x grammars, making it unsuitable for v3 grammars.
If you're going to write your own, I'd recommend using the grammar of ANTLR v3 itself to parse a .g grammar file and emit it in a readable form. Terence Parr has posted the grammar here: http://www.antlr.org/grammar/ANTLR
I just installed an Antlr plugin for Eclipse. It can do a lot more than syntax highlight and code formatting...