Skip to content
Amanda Koh edited this page Oct 7, 2016 · 56 revisions

Welcome to iambic!

Quick links

Reference

Guides

What is this?

Iambic is a modern, general purpose parser generator library for .NET especially suited to embedding. Use Iambic to add expression evaluation support to your apps, build compilers for your own programming/scripting languages, make code editors with syntax highlighting and error markup, or simply to parse structured data formats.

Iambic can be classified as a Parsing Expression Grammar library, and the parsers it builds can be classified as recursive descent parsers of the Packrat parser family, which offer guaranteed O(n) parsing performance with bounded O(n) memory usage. It is both a parser combinator library as well as a parser generator that uses grammars (PEGs, to be exact) specified as text.

Iambic is its own user - it uses itself to compile parsers. This helps to enforce Iambic's correctness and ease of use. (Of course, Iambic also has its own suite of tests.)

Iambic is nimble, flexible, extensible, and light. One of the goals of Iambic is to fill the gap when something more powerful than regular expressions is required but the available parser generators are too unwieldy (which usually results in hacking together some regular expressions and string manipulation).

Another one of Iambic's goals is to be powerful enough to build tools like IDE-style code editors, so it also supports automatic error recovery and the metadata for highlighting syntax errors and reporting compile problems.

Iambic is also pretty good at composing grammars together (embedding one language inside another).

Oh, and Iambic welcomes ports to other languages/platforms too.



Why not just use regexes?

Regexes are wonderful tools for messy problems, but they only work with flat structures - they can't do things like ensure that nested pairs of braces have matching opening and closing braces, or extract patterns that can occur a variable number of times into separate strings.

For example, if you have a string that is made up of a variable number of comma-separated date values, like this:

2010-05-12, 1998-07-19, 2005-11-23, 2000-01-01

and you want to be able to pull out each date easily, then you need something better than a regex alone. (You could write a regex in a loop, but then you'd need to worry about the separating commas, the case when there are zero dates, and so on.)

What's worse, often these sorts of problems seem too small and simple to warrant using a "real" parser, meaning that programmers end up rolling their own fragile and error prone solutions together.



How do I use this?

Take a look at a simple example of using Iambic in practice, or a more advanced tutorial for building a calculator.