Nyu

nyu is a powerful and flexible parser generator based on the TBPEG (tree building parsing expression grammar) notation. nyu grammars describe both how to parse data and how to create custom ASTs at the same time. PEG rules have been extended and modified where appropriate and new operators have been added to the PEG notation to make this task feasible.

nyu outputs parsers that take advantage of the chilon::parser meta-programming library for C++0x. The generated code is very neat and there is an almost one to one mapping between the structure of an input grammar and the generated parser.

The following is an example that shows how a list of sums can be represented in nyu and the kind of ASTs it would build. There are more examples in the tutorial.

An example grammar - basic maths.

The following Grammar stores std::vector< chilon::variant<Addition, Product, chilon::range> >

@grammar mathematics
Spacing   <- \s
Number    <- [0-9]+
Product   <= Number  |% "*"
Addition  <= Product |% "+"
Grammar   <- Addition+

This table demonstrates some text parsed with the above grammar and a short-hand representation of the AST stored (“[ .. ]” for lists, variants are expanded).

Parse Data AST
“4 + 2” [ Addition[4, 2] ]
“4” [ 4 ]
“4 7” [ 4, 7 ]
“4 + 2 * 7” [ Addition[4, Product[2, 7]] ]

Further Reading

The tutorial is currently missing detail on many operator types and missing information on some of the advanced features of nyu but is in the process of rapid expansion. The chilon::parser tutorial is a good reference to the chilon::parser library that the generated parsers use. The syntax of nyu is described in the paper on tree building parser expression grammars which can be found here. nyu also includes support for storing hashed containers which is not described in this paper.

Contributing

Wanted: Code, bug reports, suggestions and art for the website.
E-mail: nyu (@) chilon.net.
IRC Channel: #nyah on irc.freenode.net