Pep and Nom

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

nom example scripts

This folder contains some example scripts in the NOM script language. Scripts have the file extension “.pss". These examples can be run using the” interpreter and debugger ("pep") or by translating to JAVA , c, go, python, ruby etc and then (compiling and) running.

doc.dir.index.html contains a list of scripts and documents in this folder.

Documentation for the NOM language and PEP virtual machine is in the /doc/ folder.

The scripts which begin with ro. are solutions (or attempted solutions) to problems on the www.rosettacode.org site. For example the script ro.balanced.brackets.pss solves the balanced_brackets problem .

examples can be run with the interpreter by typing

  pep -f eg/script.pss input-file 
  pep -f eg/script.pss -i <input-text>
 

Examples can be translated into java,tcl,ruby,python,c,go by running the appropriate translation script

translate into go, compile and run

   pep -f tr/translate.go.pss eg/script.pss > script.go
   go build script.go
   echo "<input>" | ./script
 

notable examples

xml.parse.pss is an XML parser and error checker

nom.reference.syntax.pss is a syntax checker for the NOM language which provides precise error messages.

json.check.pss checks the syntax of a JSON text data file.

text.tohtml.pss transforms a “plain-text” document into html

sed.tojava.pss transpiles a gnu SED script into the JAVA language (branches are not supported because java has not [goto] statement )

maths.parse.pss parses and error checks arithmetic infix expressions.

maths.to.latex.pss transforms arithmetic, symbolic and logical expressions into printable LATEX formulas.

exp.tolisp.pss transforms an arithmetic infix expression into LISP This is a simpler and older version of the 2 scripts above

toybnf.pss translates simple BNF type grammar rules into NOM scripts. This is the basis for a bnf style parsing and compiling language

natural.language.pss implements an extremely limited natural language parser.

todo

Make a “table of contents” parser: that is, extract headings from some document and format and accumulate them in a tape cell (probably the first tape cell). Also parse and translate the rest of the document at the same time. This involves making sure that multiple “pop;” statements do not move the tape pointer back to the 1st tape cell. One solution is to use mark/go to realign the tape pointer

a nom table of contents parser.


    begin { ++; mark "top"; }  
    read;
    # .... more code
    "token*token*" {
      clear; get; ++; get; --; put;
      clear; add "newtoken*"; push;
      go "top";  
    }
    "heading*heading*" {
      clear; get; add "\n"; ++; get; --; put;
      clear; add "newtoken*"; push;
      go "top";  
    }
    # I am not even sure that the go "top"; code is 
    # necessary
  

or invent a new drawing/animation/gaming language (getting ambitious which has a slightly more sensible syntax that “logo

” The start of a drawing language is implemented in drawbasic.pss This is currently implemented as a transpiler to PYTHON

a help system


    parse& ??gt;
      pop;
      "help*" {
        #* implement the help
           system here *#
        clear; quit;
      }
      "error*" { clear; }
      push;
    (eof) {
      add "end of script"; print; quit;
    }
  

ideas.