Pep and Nom

home | blog | all blog posts

6 feb 2025

Is the Nom Language Gobbledigook?

What is “gobbledegook"? I think that it is language that is not” easily or naturally understandable. It may have meaning, but it requires special study or analysis to understand.

Let's have a look at some nom code...

A fragment of an arithmetic expression parser

  pop; pop;
  # we dont need any look ahead here because * and / have 
  # precedence.
  "exp*opmul*exp*" {
     clear; 
     add " ("; ++; get; --; get; ++; ++; get; add ")"; 
     --; --; put; clear; 
     add "exp*"; push;
     .reparse
  }
  

This code comes from the example script bumble.sf.net/books/pars/eg/exp.tolisp.pss which parses (very) simple arithmetic expressions and translates them into the Lisp language. As you look at it, you may think (with a sinking feeling of dismay) “Oh no! not another of those cryptic Unix languages.” . Or more succinctly “That's gobbledigook” .

Nom is an example of a “domain specific programming language” . It was partly inspired by Sed the Unix text stream editor. It is a little more complex than sed and a little simpler than, for example, the AWK language. Now lets have a quick look at some sed code...

delete duplicate, consecutive lines from a file (emulates "uniq").
 sed '$!N; /^\(.*\)\n\1$/!P; D'

Unless you like to write sed code in your spare time, you will also now be thinking “visual noise” . At least the sed code is shorter than the nom fragment above, but it is equally cryptic. Part of the reason for its crypticness is that the code is manipulating an implicit virtual machine. Unless you are familiar with the machine, then the “commands” (single letters) don’t make much sense.

Originally, when the idea for pep/nom occurred to me, I thought that I would use nom to write a more natural and expressive language “on top” of it. I had in mind something like this:

an imaginary language for parsing and translating

    exp := exp opmul exp {
      &0 = " (" $2 " " $1 " " $3 ")";
    }
  

The idea is to allow grammar reductions and the translation of attributes in a more or less natural form. If you have worked with BNF grammars and other lexing and parsing systems (lex and yacc for example), then the imaginary language above should be reasonably understandable. In fact, this fragment would do exactly the same thing as the nom script fragment quoted above.

So far, I have not written this language, but it is the sort of task that pep/nom is good at. The reason I have never, so far, created a nom script to implement the language above is that I have been absorbed in exploring the possibilities and the limitations of pep/nom. So far I have discovered that nom is very good at parsing and translating itself which is why there are nom scripts for translating into Go , Java , Python and other languages.

Pep/nom is not so good at doing things like type checking.

So the answer to the question which is the title to this blog post is: Yes, nom may look like gobbledigook at first sight, but it has great potential for the recognising, parsing, transforming, transpiling and compiling of context free language patterns.

mjb