All Projects → BNFC → Bnfc

BNFC / Bnfc

BNF Converter

Projects that are alternatives of or similar to Bnfc

jsoncat
Json pretty-print parser based on a recursive lexical analyser
Stars: ✭ 26 (-93.09%)
Mutual labels:  pretty-print
Javascript-Explorer-Callgraph
Call graph based on Abstract Syntax Tree in Javascript
Stars: ✭ 33 (-91.22%)
Mutual labels:  abstract-syntax-tree
Rascal
The implementation of the Rascal meta-programming language (including interpreter, type checker, parser generator, compiler and JVM based run-time system)
Stars: ✭ 284 (-24.47%)
Mutual labels:  parser-generator
eq
jq, but for EDN.
Stars: ✭ 23 (-93.88%)
Mutual labels:  pretty-print
tsquery-playground
Playground for TSQuery
Stars: ✭ 30 (-92.02%)
Mutual labels:  abstract-syntax-tree
DataAnalyzer.app
✨🚀 DataAnalyzer.app - Convert JSON/CSV to Typed Data Interfaces - Automatically!
Stars: ✭ 23 (-93.88%)
Mutual labels:  parser-generator
leftry
Leftry - A left-recursion enabled recursive-descent parser combinator library for Lua.
Stars: ✭ 32 (-91.49%)
Mutual labels:  parser-generator
Tslog
📝 tslog - Expressive TypeScript Logger for Node.js.
Stars: ✭ 321 (-14.63%)
Mutual labels:  pretty-print
ast-builder
Build your ASTs directly from code
Stars: ✭ 18 (-95.21%)
Mutual labels:  abstract-syntax-tree
inmemantlr
ANTLR as a libray for JVM based languages
Stars: ✭ 87 (-76.86%)
Mutual labels:  parser-generator
DAGE
Desktop Antlr Grammar Editor
Stars: ✭ 19 (-94.95%)
Mutual labels:  parser-generator
Covfefe
A parser for nondeterministic context free languages
Stars: ✭ 49 (-86.97%)
Mutual labels:  parser-generator
bison
GNU Bison
Stars: ✭ 144 (-61.7%)
Mutual labels:  parser-generator
YaccConstructor
Platform for parser generators and other grammarware research and development. GLL, RNGLR, graph parsing algorithms, and many others are included.
Stars: ✭ 36 (-90.43%)
Mutual labels:  parser-generator
Intellij Plugin V4
An IntelliJ plugin for ANTLR v4
Stars: ✭ 318 (-15.43%)
Mutual labels:  parser-generator
Caribay
A PEG Parser Generator with Semi-Automatic Error Recovery based on LPeg(Label)
Stars: ✭ 14 (-96.28%)
Mutual labels:  parser-generator
karma-jasmine-diff-reporter
Diff and pretty print for failed tests
Stars: ✭ 31 (-91.76%)
Mutual labels:  pretty-print
Javaparser
Java 1-15 Parser and Abstract Syntax Tree for Java, including preview features to Java 13
Stars: ✭ 3,972 (+956.38%)
Mutual labels:  abstract-syntax-tree
Plex
a parser and lexer generator as a Rust procedural macro
Stars: ✭ 326 (-13.3%)
Mutual labels:  parser-generator
intellij-javacc
JavaCC and JJTree grammar support for the IntelliJ Platform
Stars: ✭ 31 (-91.76%)
Mutual labels:  parser-generator

Hackage version Hackage CI BNFC on Stackage Nightly Stackage LTS version Build status Documentation status

The BNF Converter

What is the BNF Converter?

The BNF Converter (bnfc) is a compiler construction tool generating a compiler front-end from a Labelled BNF grammar. It is currently able to generate Haskell, Agda, C, C++, Java, and OCaml, as well as XML representations.

Given a Labelled BNF grammar the tool produces:

  • an abstract syntax implementation
  • a case skeleton for the abstract syntax in the same language
  • an Alex, Ocamllex, JLex, or Flex lexer generator file
  • a Happy, Ocamlyacc, Menhir, ANTLR, CUP, or Bison parser generator file
  • a pretty-printer as a Haskell/Agda/C/C++/Java/Ocaml module
  • a Latex file containing a readable specification of the language

More information: http://bnfc.digitalgrammars.com/

Installation

Some binaries are available at https://github.com/BNFC/bnfc/releases. Installation from the Haskell sources is possible via stack or cabal.

Installation via stack (recommended)

You need a running installation of stack. To install and run the latest version of bnfc from stackage, enter at the command line:

  stack install BNFC
  bnfc --help

Installation via cabal

You need a running installation of a recent version of GHC and Cabal, most easily available via the Haskell Platform. To install and bnfc from hackage, enter at the command line:

  cabal install BNFC
  bnfc --help

Installing the development version

To install the development version of bnfc with the latest bugfixes (and regressions ;-)):

  git clone https://github.com/BNFC/bnfc.git
  cd bnfc/source

and then either

  cabal install

or

  stack install --stack-yaml stack-8.10.3.yaml

(replace 8.10.3 with your GHC version, and if you want to build with your installed GHC then add flag --system-ghc).

Mini tutorial

  • Build a first parser in 5 min (Haskell backend):

    1. In a fresh directory, prepare a grammar file Sum.cf with the following content:

      EInt.  Exp ::= Integer;
      EPlus. Exp ::= Exp "+" Integer;
      
    2. Build a parser (in Haskell) with bnfc:

      bnfc -d -m Sum.cf  &&  make
      

      The make step needs the Haskell compiler GHC, the lexer generator alex and the parser generator happy (all included in the GHC installation).

    3. Inspect the generated files in directory Sum.

    4. Test the parser.

      echo "1 + 2 + 3" | Sum/Test
      
  • Try the C-family backends. (The prerequisites, GNU C(++) compiler (gcc / g++), lexer generator flex and parser generator bison, are usually present):

    bnfc --c   -m -o sum-c   Sum.cf  &&  make -C sum-c    &&  echo "1 + 2 + 3" | sum-c/TestSum
    bnfc --cpp -m -o sum-cpp Sum.cf  &&  make -C sum-cpp  &&  echo "1 + 2 + 3" | sum-cpp/TestSum
    
  • Try the other backends:

    Option Backend
    --java Requires Java, JLex or JFlex, and CUP.
    --java-antlr Requires ANTLR.
    --ocaml Requires OCaml, ocamllex and ocamlyacc.
    --ocaml-menhir Uses menhir instead of ocamlyacc.
    --agda Produces Agda bindings to the parser generated for Haskell.
    --pygments Produces a lexer definition for the Python highlighting suite Pygments.

Documentation

https://bnfc.readthedocs.org/en/latest/

Support

You can discuss with us issues around bnfc on our mailing list [email protected].

For current limitations of bnfc, or to report a new bug, please consult our issue tracker.

Contribute

License

The project is licensed under the BSD 3-clause license.

BNFC versions until 2.8.4 released under the GNU General Public License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].