language and parsing
### Pep and Nom
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.
a nom script to print line numbers of input text -----+ begin { add "1 "; } read; [\n] { lines; add " "; } print; clear; ,,,,
The home page for pep/nom is located at http://www.nomlang.org . The source code, "examples" /eg/ , translation scripts and other documentation is also at Sourceforge (and has been for some years. Thank you!). The complete system can be "downloaded" nomsf://download/
Nom is a "Domain Specific language" for parsing "context-free" wp:context-free_language and context-sensitive languages and pattern. Nom "compiles" nomsf://compile.pss itself and can also translate itself into other languages like [nom:translation.links]
The name *Nom* doesn't "stand for" anything but is similar to an indo-european root for "name" and may also be a vague accolade and reference to *Noam* Chomsky for his classification of formal languages.
This "Nom" has nothing to do with the Rust parsing library which is also called "Nom" and is an unfortunate name clash.
### WHAT CAN YOU DO WITH NOM ?
*Here is a list:*
- You can use nom to explore grammars and text patterns and parsing and
compiling without having to learn a big programming language.
- recognise, parse, error-check, format, translate, transpile and compile
many type of patterns in text (which are called "formal languages" in
mathematics and computer-science.)
- Parse and error check an [xml] data file
with a script like /eg/xml.parse.pss
and also translate it to another
format.
- Parse and error check "json" /eg/json.check.pss
files
- generate maths formulas from plain text with a script like
/eg/maths.tolatex.pss
. So you can write a formula like
cuberoot(:Theta + x/(x+1))/(x^-0.5 + 1/2)And then use the [nom] script to generate [latex] and pdf as follows:
eg/maths.tolatex.pss
\
-i ' cuberoot(:Theta + x/(x+1))/(x^-0.5 + 1/2) '
# see below for rendering with pdflatex
,,,,
<:r:1:cc:/image/maths/formula.cuberoot.png>
- you can generate html documents from plain text, like this webpage you
are reading now, with a script like /eg/text.tohtml.pss
- You can translate a language like [sed] into [java] using a
script like /eg/sed.tojava.pss
and then "compile" the sed
script with the java virtual machine
- You can "translate" /tr/doc.dir.index.html
a *nom* script into
a standalone program in another language like [nom:translation.links]
- You can use nom to build a another (better?) parsing/compiling
language *on top* of nom. An example of this sort of language
would be /eg/toybnf.pss
- Recognise, parse and translate text file formats like css, dns
- You can use nom to compile itself with a script like
nomsf://compile.pss or use nom to check its own syntax with
a script like /eg/nom.syntax.reference.pss
- You can use nom to create a language like the [logo] turtle
drawing language with a script like /eg/drawbasic.pss
(not complete)
- you can use [nom] to create an interesting modern computer
language with a really helpful compiler. (Type checking
needs to be done in a separate 1st pass nom script).
- and much more.
### NOM SCRIPT EXAMPLES
The folder /eg/ contains a set of example scripts written in the [nom] language including an [xml] parser and error checker and a [json] parser among other scripts.
### 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.
I also try to write a general blog about language, culture, art, travel, the garden, making things or whatever which is called Shrob
There is also a journal href="/doc/pepnom.doc.journal.html">/doc/pepnom.doc.journal.html
of
work that I carry out on *pep and nom* . Sometimes I have long
breaks.
### DOWNLOAD AND COMPILE THE PEP/NOM INTERPRETER
Download file: "download.pepnom.tar.gz" /download/download.pepnom.tar.gz
Prerequisites: a "c" compiler (I have tested with gcc and "tcc" https://bellard.org/tcc/">https://bellard.org/tcc/">https://bellard.org/tcc/">https://bellard.org/tcc/">https://bellard.org/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 pepnomtar.gz
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"
http://bumble.sf.net/books/pars/download/download.pepnom.tar.gz
or on this site ( "download.pepnom.tar.gz" /download/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" nomsf://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 href="doc/">doc/
on this server. Each command in the *nom* language is documented in
a separate file in the /doc/commands href="commands/">commands/
.
The folder /doc/syntax/ contains explanations of each syntactical element of the *nom* language, such as "blocks" nomsyn://block , nomsyn://comments , nomsyn://tests and so forth.
Each element of the [pep] virtual pep://machine such as the pep://tape ,
pep://stack and the pep://workspace buffer (among others) is documented in
the /doc/ href="machine/ ">machine/
ectory on this server.
The *pep* interpreter is documented in the /doc/peptool/ folder.
This documentation is in the process of being revised and expanded.
### AN EXAMPLE NOM SCRIPT
For a number of practical example scripts see the "nom example"
/eg/
.
#: ---+ means nom codeblock
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")
,,,,
### TRANSLATION OF NOM SCRIPTS
Nom scripts can be translated into several languages, including [nom:translation.links] 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.