Home
General description
PseuToPy is a Python library which defines a grammar for a pseudocode-based pseudocode. With this grammar, PseuToPy is then able to take instructions written in pseudocode and converts it into the equivalent Python instructions.
PseuToPy is designed for educational purposes. In that sense, PseuToPy is suited to anyone embarking in the journey of learning Python programming by offering a relaxed syntax and a grammar that very much resembles the grammar of a natural language.
Currently, PseuToPy only exists in English, but more languages (French, Italian, Spanish) will arrive soon.
Installation
Use the package manager pip to install PseuToPy.
pip install pseutopy
This will also install the following dependencies:
Usage
You can import PseuToPy and use it within your own project.
import astor
from pseutopy.pseutopy import PseuToPy
pseutopy = PseuToPy()
# These two lines generate the AST of the pseudocode instructions
convert_from_string = pseutopy.convert_from_string("""
declare myVar
set myVar to 3 plus 1
""")
convert_from_file = pseutopy.convert_from_file("./path/to/file")
# You can then convert these AST into Python instructions with astor
print(astor.to_source(convert_from_string))
print(astor.to_source(convert_from_file))
# For example, the result of print(astor.to_source(convert_from_string)) is:
# myVar = None
# myVar = 3 + 1
Or you can use the CLI utility that ships with this project.
python cli.py --help
# This is the output of the help flag
usage: pseutopy.py [-h] [-f | -s] [-a] [-q] input
A pseudocode to Python converter written in Python using textX.
positional arguments:
input Pseudocode input to be converted into Python
optional arguments:
-h, --help show this help message and exit
-f, --file Input is now expected to be a file
-s, --string Input is now expected to be a string (default)
-a, --ast Prints out the generated Python AST
-q, --quiet Don't print the generated Python code
Testing
To run unit tests, run pytest
at the root of the project.
Authors and acknowledgment
I particularly wish to thank @Houguiram, @TheOnlyMrFlow, and @EricSombroek for their initial contributions to this project, which greatly helped me in getting to this stage.