DSL to Python Translator
July 14, 2017
As mentioned in the previous post, I have written the code for the DSL to Python translator. The code is working fine and has been merged with the master branch. 😀
The structure is very simple, it interprets each line of the program written in DSL and checks if it has a valid command. If it has a valid command, the line is processed and it’s arguments are identified and its python-equivalent code is generated and written in the python file for that program.
In case an invalid command is entered, it is ignored (for now).
The translation process has been automated as mentioned in Getting rid of redundancy and the automation scripts are included in
Added two separate scripts to create and run a program written in DSL. The two files are: learnbot_create: to generate the python file from the file written in DSL learnbot_run: to run the generated python file These custom bash commands can be used from any directory
$ gedit ~/.bashrc
Then add the following line at the end of it
Then reload the .bashrc file
$ . ~/.bashrc
Using the commands
The commands can now be used from any directory.
Suppose you have the following file written in DSL:
cd into /path/to/file/ then
To generate the python file, the command is:
To run the
The DSL to Python translator isn’t complete without an error reporter. I will be writing a help page which will list down all the valid learnbot commands and it’s correct usage. The user will just type
learnbot-help and the help page will come up in the terminal.
Everytime an invalid command is detected, the translator will stop and report the error, saying:
Invalid command. Type learnbot-help for more info on commands and their correct usage.
Aniq Ur Rahman