Martin Fowler Explains Txtzyme

By: WardCunningham

2010-10-09 17:44:59

In their new book, Domain Specific Languages, Martin Fowler and Rebecca Parsons demystify the creation of small languages by decomposing the practice into four-dozen carefully-named essays (patterns) offering solutions to every problem one might encounter. What would they call Txtzyme? They'd call it Delimiter-Directed Translation with Embedded Interpretation.

img

Martin explains that line-at-a-time works well where statements are simple and autonomous. More complex languages deserve Syntax-Directed Translation. Fair enough. Txtzyme is simple and can be autonomous which becomes more important when multiple masters are sending lines to a Teensy running Txtzyme.

Martin calls execute-as-you-parse Embedded Interpretation and again cautions that it is only suitable for simple languages. I've described Txtzyme as a "case statement with a loop around it". The "then clauses" of the cases would be the embedded interpretations. Martin suggests numerous ways to save work to be done later and thus in different orders. Txtzyme's 100{ ... } style repeat loop does alter execution order, but it re-parses the input buffer each time which hardly counts as an alternate representation.

Regular readers of my posts here know that I've embedded Txtzyme into all manner of scripting languages where it often becomes the implementation technology behind another, higher-level DSL style program. I've become a fan of what Martin calls Function Sequence. This is particularly nice in perl which relaxes the need for many of the parenthesis that makes this form tedious. Look at the recently posted thermz.pl for a one-page digital-readout thermometer coded in Function Sequence style backed by Txtzyme. Martin describes Function Sequence as the baby brother to Method Chaining, a pattern made popular with jQuery.

What's great about this book is that so many implementation alternatives are spread out in front of you with strengths and weakness called out. This is no easy feat. I suggested "Inserting a Parser" should be included in his Refactoring book ten years ago. Martin spent a day with me hacking JavaCC after which he concluded that the subject might be a little too big for that book. Too big indeed. He now shows that a proper treatment takes 600 carefully crafted pages. Thank you Martin and Rebecca for rising to the challenge.

Back to archive index