Build a DSL *Fast* With M4



The M4 macro preprocessor is a tool that inspires fear in the hearts of many open tech developers. It shouldn't. I'll show you how to build domain-specific languages quickly and easily in M4.


The M4 macro preprocessor is designed to act as a generic text-to-text translator; it applies macros to text in a very flexible way. You may have noticed its use in Sendmail configuration, or in autoconf/automake.

Unfortunately, these rather twisty systems don’t do M4 justice as an implementation language for domain-specific languages. In addition, M4 has a somewhat deserved reputation for being hard to write and debug macros for. However, with proper care, these problems can be managed. I’ve found that I can put together a highly-functional DSL in a fraction of the time it would take me using any other method I’m aware of.

I will show some examples of systems my students and I have built: a compiler backend, a plan generator, the first generation of XCB, and a text formatter. I will also discuss the principles of DSL construction in M4, and we’ll construct a toy language of some sort as a demonstration.

Speaking experience


  • Beach headshot 320x200

    Bart Massey

    Portland State University


    Bart Massey has been geeking around with community computing for 35 years, and has been involved in Free Software and Open Source since its inception. For the past 15 years, he has been a CS Prof at Portland State University, where he works in open tech, software engineering, artificial intelligence and low-level software development.

    Bart’s titles include Member of the PSU MCECS Innovation Program Board and past Secretary of the X.Org Foundation Board. Bart is the architect of the X library XCB, a modern replacement for Xlib, and the author of the XCB image extension. His current open tech interests include Haskell, open hardware and building bridges between pieces of the open tech community. He was one of the original participants in the Open Source Bridge conversation.