bumble.sf.net language and parsing

plain text

The


"TR" FOLDER

This folder contains pep/nom scripts that translate pep 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 thehelpers.pars.sh.

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 pep 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'

Status


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

To do


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

History


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.