What if Perl 6 grammars could generate?

By Jonathan Worthington (‎jnthn‎) from Prague.pm
Date: Tuesday, 4 June 2013 15:05
Duration: 45 minutes
Target audience: Intermediate
Language: English
Tags: 6 grammars parsing


Perl 6 grammars offer a powerful way to build parsers. By building upon the more familiar notion of regular expressions, they offer easy on-ramps to those getting started. They also enable working in a programmer-friendly recursive descent style, while automatically generating a lexical analyzer for you in order to avoid naively recursing down all the paths a true recursive descent parser would need to. Furthermore, a grammar can be coupled to an actions class, enabling a data structure of the programmer's choosing to be built up as the grammar does its work.

So, we have a good way to go from text to a data structure. That's great. But...what about the other direction? What if we could take all the hard work we put into our grammar, and use it to help us generate well-formed output? What if we want to start from a data structure, like the ones our actions built?

In this session, I'll explore how we might go about turning the arrow of parsing backwards. Taking inspiration from the concept of duality, we'll consider how the building blocks of grammars can be individually turned inside out, try to work out how they can be composed in this upside down world, and - if that all proves far too easy - maybe we'll find a moment to take on turning the actions backwards too, so we can get from a data structure all the way back to text.

Will the result be useful? Who knows! Will we learn stuff about grammars and Perl 6 trying? Oh my, yes!

Attended by: