Pep & Nom

home | documentation | examples | translators | download | journal | blog | all blog posts

what is pep/nom

Nom is a parser-parser, a compiler-compiler, a text pattern recogniser, a way of thinking about grammars, a text filter tool, a language “translator” ...

The Pep & Nom system is a system for parsing and translating context-free languages. It uses the Unix text-stream editing philosophy and applies it to formal languages and patterns . Nom is (for me) an enjoyable way to explore grammars, text patterns, syntax, translators and compilers.

The source code, examples , translation scripts and other documentation is also at Sourceforge (and has been for some years. Thank you!). The complete system can be downloaded

Nom is a “Domain Specific language” for parsing context-free and context-sensitive languages and pattern. Nom compiles itself and can also translate itself into other languages like rust| dart| perl| lua| go | java | javascript| ruby | python| tcl | c

Please check the nom status for an overview of what stage this amazing parsing system is at.

what is nom for ?

nom script examples

The folder /eg/ contains a set of example scripts written in the NOM language. These examples range from very simple parsing tasks such as recognising VV palindromes or implementing the esoteric “brainf**k” language, to more complex examples such as an XML parser/error-checker, a JSON parser, an equation formatter, a sed-to-java translator, some 'chat' scripts, and the text-to-html script that renders this website.

the pep/nom blog

I write a blog about the Pep/Nom system in the (perhaps vain) attempt to publicise it and explore my own ideas about it.

There is also a journal of work that I carry out on pep and nom . This has been a long term hobbyist project (so far) and from time to time I will take an extended break from development, but I find myself constantly returning in order to develop the potential of the system further.

download and compile the pep/nom interpreter

Download: download.pepnom.tar.gz

Another way of downloading all the source code and documentation is with git from github.

get the system from github
 git clone https://github.com/pepnom/pep

Prerequisites: a “c” compiler (I have tested with gcc and previously with tcc the tiny c compiler ) The instructions below are very “unixy” but the system should compile and run on Windows as well. (I have tested it on Linux and MacOS but not Windows).

download the pepnom tar.gz file
 wget http://bumble.sf.net/books/pars/download/download.pepnom.tar.gz

( or just right click and download)

The download file is at sourceforge here or on this site ( download.pepnom.tar.gz ) The system is about 1 megabyte compressed, which included the interpreter, translation scripts, examples and a documentation booklet.

extract the compressed files where-ever you like
 tar -xvzf download.pepnom.tar.gz

change directory into the pepnom folder
 cd pepnom

compile the pep interpreter (requires some 'c' compiler)
 ./make.pepnom.sh

try out the pep interpreter (convert arithmetic expression to 'lisp')
 ./pep -f eg/exp.tolisp.pss -i "3+4/(5.1*7)"

Put the executable in your PATH variable so that you can use it from anywhere.

There are also some bash functions in the file helpers.pars.sh for compiling the code (and translating nom scripts into other languages) with various options.

documentation

The main documentation for Pep & Nom is in the /doc folder on this server. Each command in the nom language is documented in a separate file in the /doc/commands folder.

The folder /doc/syntax/ contains explanations of each syntactical element of the nom language, such as blocks , comments , tests and so forth.

Each element of the PEP virtual machine such as the tape , stack and the workspace buffer (among others) is documented in the /doc/machine/ directory on this server.

The pep interpreter is documented in the /doc/peptool/ folder.

example scripts

a nom script to print line numbers of input text


    begin { add "1 "; } read; 
    [\n] { lines; add " "; }
    print; clear;
  

For a number of practical example scripts see the nom example folder.

word by word parsing and translating


   # the lexical analysis phase of the script
   while [:space:]; clear;
   whilenot [:space:]; put; clear; add "word*"; push;

   # the parsing/compiling phase of the script
   parse>

   # get 2 grammar tokens off the stack
   pop; pop;
   # grammar rule:
   #   text := ( word word ) | ( text word ) ;
   "word*word*", "text*word*" {
     # format as one word per line
     clear; get; add "\n"; ++; get; --; put; clear;
     # reduce 2 grammar tokens to 1 ("text")
     add "text*"; push; .reparse
   }
   push; push;
   # at the end of the input stream 
   (eof) {
     # get the final grammar token, and print the formatted 
     # text.
     pop; clear; get; print; quit; 
   }
   # if not at end of input-stream, go back to
   # the top of script (this is an implicit loop, like in 
   # "sed" or "awk")

  

This “Nom” has nothing to do with the Rust parsing library which is also called “Nom” and is an unfortunate name clash. For this reason, I often call the nom language “nomlang”.

translation of nom scripts

Nom scripts can be translated into several languages, including rust| dart| perl| lua| go | java | javascript| ruby | python| tcl | c In fact, the translation scripts can translate themselves. This is a strangely profound corollary of writing a parser-parser language or a compiler-compiler system.

See the /doc/ and /tr/ translation folders for more details.