I have, over the last few days, been writing several NOM scripts which seem significant. One was an xml parser and error checker. This script was written in what was, for me, a few short amount of time: a few hours. I was surprised by the speed and also by the fact that nom and PEP was capable of parsing XML . But it is, and does.
Another script that I wrote quickly was /eg/toybnf.pss . This is actually the start of the language that I always imagined that nom would become. That is, an expressive language loosely based on BNF syntax (or one of it’s variants). This script also only took a few hours to write.
Another script which seems significant is /eg/nom.syntax.reference.pss which provides really good error checking for nom scripts giving a line and character number for where the syntax is bad, even in the case of unmatched opening braces (which can be a tricky problem, because by the time that the parser/compiler knows that something went wrong, it is too late to give a helpful error message).
I also updated the arithmetic and expression parser /eg/maths.parse.pss and included much better error checking. I also had the idea of “throwing errors” just like in modern languages. But in this case, the error that is thrown is actually just a parse token that is put on the token stack with a message. This system works well, and is worth using in any non-trivial language or pattern parser/compiler.
Another recent invention is putting a built in “help” system into the NOM script. This works in a similar way to the error tokens: A “help” token is put onto the parse stack and then an error token is put on immediately after it. The error token parser or trap then checks the parse-stack to see if there is a help token there, and if so, prints the messages in the help token.
To see how the help and error system works, it is best to look at the script /eg/maths.parse.pss . Another advantage of it, is that the help system can have categories of help, or topics and the script writer can implement a help command (with an argument) which prints help about a particular topic or topics.
This error/help token system is so useful that I think that all significant NOM scripts should be written with it - in other words, it should be part of a script template.
Another interesting script that I was able to write recently was /eg/maths.to.latex.pss which takes a mathematical, symbolic, arithmetic or logical expression and formats it into a LATEX formula or equation. The results are remarkably pleasing to the eye.
pep -f eg/maths.to.latex.pss -i ' sqrt(x^2 + y^-0.25) + 5^(x+y)/(x+y)' \
> test.tex
pdflatex test.tex; open test.pdf
The LATEX formatter is based on the eg/maths.parse.pss with some editions for symbols and equations. But both of these scripts understand operator precedence, associativity and grouping with brackets.
Another script, which is not complete but seems very promising is /eg/drawbasic.pss which implements a “turtle” drawing language similar to LOGO or the PYTHON turtle graphics package. The language is designed to be more basic-like than logo, and less pythony than python. It seems feasible and easy to cut and paste the expression parser in /eg/maths.parse.pss and put it in the drawbasic language.
Also, while writing the “maths” scripts I thought about parse-token “lookahead” using the NOM language and developed some simple and effective techniques for it which can be seen in those scripts.
I am really not sure what is the most effective way to promote NOM but it seems a pity that it is not used and investigated by more people, especially programmers and linguists.
mjb