Grammars is a .NET C# 4.0 library that provides tools for the definition of regular, context-free and context-dependent grammars, and the application of various algorithms and techniques. It can be used for fast prototyping of DSL, for implementation of mini-languages (for configuration or scripting) and for the test of several formal languages concepts in an academic context.

The library is designed to be extensible and easy to use, rather than super optimized. For instance, the LR parser builder algorithm is implemented in a pretty straight forward manner, as described in the Dragon Book. The main purpose is to provide a useful tool for teaching, experimenting and prototyping, and not a professional parser maker (there are many great parser generators out there, even a very good few right here in CodePlex).

To see some examples, please go to the Documentation page.

Contributions
Contributions are always accepted. If you would like to work on this project, please contact us. The source code is fully available for download in Source Code under the LGPL. For the organization of collaborations, and an explanation of the source code structure please visit Contributions.

Features
The library features a BFN-like embedded DSL for the definition of grammars, that allows some standard constructions, through the use of operators overloading and a fluid interface. It also allows the definition of semantic rules as C# delegates, embracing the full power of IntelliSense and static typing.

Right now we provide a standard LR parser generator that builds a shift-reduce parser out of your grammar, assuming the grammar is LR(1). The parsers created by this mechanism also automatically apply the semantic rules associated with every reduction.

The library also provides some sentence generators that traverse the grammars and generate sentences in different fashions. For instance, we give a random generator which generates a sentence at a time using a random production for every non-terminal, and an ordered generator which generates sentences in a lexicographical order.

Upcoming Features
  • Grammar optimization tools: eliminate left and right recursion, conversion to normal forms, and others.
  • An LL parser generator for anyone who wants it.
  • Some support for regular grammars: building and simplifying the automaton, etc.
  • Analysis of some theoretical problems, such as determining the equivalence of two grammars (please note that most of these problems are undecidable in general).

Last edited Apr 4, 2012 at 2:36 PM by AlejandroPiad, version 5