Full details of Grammar-Kit BNF format?

Is there a good description somewhere for the BNF format used by Grammar-Kit? I can see general documentation for Grammar-Kit and the tutorials for creating language plugins but many of them just gloss over the BNF part.

Specifically I'm investigating if it might be possible to make an IntelliJ parser for either Mercury or Oxygene. The difficulty is that Mercury has a fairly complex set of operators ( http://www.mercurylang.org/information/doc-release/mercury_ref/Builtin-Operators.html#Builtin-Operators ) and none of the example grammars in the tutorials show how to deal with precedence, and only one example briefly and incidentally mentions how to do associativity. Do we have to do it old-school and have a separate parser rule for every level of precedence?

Thanks!

3 comments

I've added a section for compact expression parsing with priorities to the HOWTO page (section 2.4) https://github.com/JetBrains/Grammar-Kit/blob/master/HOWTO.md

0

I am also trying to write a language plugin... It appears that the grammar-kit can auto-generate jFlex code from the bnf files directly.  The tutorial that I have been working through http://confluence.jetbrains.com/display/IntelliJIDEA/Custom+Language+Support seems to hand write the jFlex file.  What is the better way to gow, write the jFlex code by hand or auto-genenerate it from the bnf file?

Thanks.

0

Grammar-Kit can generate only basic single-state JFlex lexer so I use this functionality as a quick start only.
The generated flex will work out-of-the-box only for very simple cases.

The best steps I know:

1. write a BNF with "regexp:" tokens and verify it mostly works in Live Preview
2. generate JFlex lexer and add more complexity and states and fix macros if needed
3. generate java lexer from jflex (context menu item) and prepare ParserDefinition and start writing ParsingTests

0

Please sign in to leave a comment.