What Is Grammatica?

Updated

Grammatica is a parser generator (also called a compiler compiler) that produces parsers for C# and Java. You write a grammar, and Grammatica turns it into readable, well-commented source code for one of those two target languages. It is open source under the permissive BSD license, which allows modification and unlimited redistribution, including in commercial applications.

What a parser generator does

A parser generator takes a formal description of a language — its grammar — and generates code that can read input conforming to that grammar. Instead of hand-writing a parser, you define the rules and let the tool build the parser for you. This is the same general category as yacc and ANTLR.

What sets Grammatica apart

According to the project, Grammatica improves on similar tools in a few specific ways:

  • Readable output — it generates well-commented, readable source code rather than dense machine-oriented code.
  • Error handling — it includes automatic error recovery and detailed error messages.
  • Grammar testing without code generation — you can test and debug grammars without first generating source code.

The project also points to a wiki page titled "why use Grammatica?" for a fuller list of reasons to use — or avoid — the tool.

Supported target languages

Grammatica generates parsers for:

Target API documentation available
Java Java API Documentation
.NET (C#) .NET API Documentation

Documentation and downloads

The site provides the following resources:

  • Reference Manual — reference documentation with examples and usage information.
  • Java API Documentation — the API for generated Java parsers.
  • .NET API Documentation — the API for generated .NET (C#) parsers.
  • Release Documentation — release information for the latest version.
  • Downloads — releases hosted on GitHub with version history.

All documentation listed is also included in the download package.

License

Grammatica is released under the BSD license. This gives you full access to the source code, permits changes, and allows unlimited redistribution and usage in commercial applications.

When Grammatica fits

Grammatica is a reasonable choice if you need to build a parser for a language or data format and want the generated code in C# or Java, prefer readable output you can maintain, and want the freedom of a permissive license. If your target language is something other than C# or Java, or you need a tool with a different feature set, the project's own "why use Grammatica?" wiki page is the place to check the trade-offs before committing.