
THE "TR" FOLDER

  This folder contains pep/nom scripts that translate nom scripts into
  other languages. Currently (aug 2022) the following languages have
  robust translators: java, c (byte chars), ruby, python, go, tcl, javascript
  The translation scripts can be thoroughly tested using the 
  "pep.tt" function in the helpers.pars.sh script. This tests the 
  translation of a large number of short scripts using the data 
  file tr/tr.test.txt

  All the translator scripts create a standalone script (ruby, python) or
  a compilable file (java, go). So the virtual machine (a class 
  or structure with methods) is contained in the script/source code.
  The exception is the c translator which requires the code 
  in libmachine.a in order to compile a standalone executable.

  The libmachine.a c library can be recompiled with functions in 
  the helpers.pars.sh file.

  The bash script helpers.pars.sh contains a number of functions 
  which help to translate and run scripts in different languages.
  Some examples:

  * translate a nom script file to go, compile and run it with input
  >> pep.gof eg/palindrome.pss "dogeeseseegod"
  
  A translation script can be used as follows:

  * translate an inline script into python and run the script
  ----
    pep -f tr/translate.py.pss -i "r;t;t;d" > test.py
    chmod a+x test.py; echo 'abcd' | ./test.py
    # output is: aabbccdd
  ,,,

  * translate the json syntax checker into java and run it with input
  >> pep -f tr/translate.java.pss eg/json.check.pss > Machine.java
  >> javac Machine.java; echo "[1,2,true,[3,4]]" | java Machine

  * make the python translator translate itself into python and run it
  -----
    pep -f tr/translate.py.pss tr/translate.py.pss > tr.py.py
    chmod a+x tr.py.py; echo "r;[0-9]{d;}t;" | ./tr.py.py
  ,,,,

  * use the function in helpers.pars.sh to translate to go, compile and run
  >> pep.gof palindrome.nospace.pss 'do geese see god'

TESTING

  Use the bash function pep.tt in the file helpers.pars.sh to test the nom
  translation scripts. This function uses the file tr.test.txt to translate
  (and compile) a series of small scripts and then test if the output from them
  is correct. The script also tests "Second generation" scripts, which means
  that the translator translates itself and then runs the test script.

STATUS

  18 feb 2025
    Noticed that the perl translator uses a much better grammar and 
    also includes bracket expressions in tests
  22 aug 2022
    The java, go, ruby, python, c, javascript and tcl translators are at a 
    usable mainly bug-free level. The perl translator passes a few tests

NOT WORKING

  18 feb 2025
    Python code has a bug in it when running eg/text.tohtml.pss
    rust, kotlin, perl, swift are all in development.

TO DO

  Consolidate error checking just after parse> label (this 
  may slow down scripts slightly since extra pops and pushes 
  will be performed for scripts.)

  new languages:
  rust, c++, haskell, lisp, julia, swift, php, scheme, R (maybe)
  reform grammar for existing translators.

HISTORY

  18 feb 2025
    Would like to reorganise all these translation scripts. Call
    them nom.to.java.pss nom.to.go.pss etc Add a script* grammar 
    token at EOF that indicates a successful parse. Consolidate
    all error grammar token error checks just after the 
    parse> token (so that all scripts will use the same error
    checking)

  24 aug 2022
    The perl translator now has a nice grammar that also allows
    a test expression grammar. The idea of translators also being
    interpreters seems to work! And it should work in other situations
    such as creating a logo compiler/interpreter.

  22 aug 2022
    Will try to work on new versions of the translators that use a 
    better, more logical grammar (and allow an expression grammar 
    in tests- eg: (E"x",E"y").B"a" {...}  ). Also translators that 
    use a parse method, for more flexibility. Also, I will try to 
    create a "syntax.pss" script that will check for syntax errors 
    and print nicely formatted output.

