Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Enki

Enki is a frontend parser generator that uses an annotated EBNF syntax to produce .d sourcefiles.

As a parser generator utility, it uses a completely self-hosted parser for ease of development as well as a proof-of-concept.

Overview

The concept behind Enki is to provide a means to create efficent parser frontends in D, by way of a more suitable grammar. As D is a very versatile and multi-purpose language, the task of composing a parser can become quite tedious and difficult to express for grammars of even modest complexity. Instead of having the developer tediously code a parser in D directly, Enki uses a more targeted grammar (EBNF) to express a parser's definition - and then writes the parser automatically. The result is a tool that acts like a form of source-code compression, allowing the developer to draft a parser with far fewer lines of code, yet with a much higher degree of clarity. ([Enki/Overview More...])

Code Generation

In short, the entire grammar is compiled into a single class, in one output .d file. Each rule is a method in the parser class. Things like rule annotations are understood to be backed by the inherited class, or are otherwise within scope of the parser at compile time. ([Enki/Codegen More...])

Use

To use Enki, simply run 'enki' and read the online instructions. Generating a parser frontend is as simple as passing it your enki code (annotated EBNF) and, optionally, specifying the output file via '-f' if the default 'parser.d' isn't to you liking.

The use of the '-b' option, to re-generate the BNF code, may seem pointless at first glance. It is in fact a good diagnostic to use should you suspect Enki of not parsing your code correctly. The generated BNF file is created from the internal parse-tree and is an accurate representation of what Enki thinks your code means. ([Enki/Use More...])

Table Of Contents