Skip to main content

PseuToPy is a package that transpiles pseudocode into its equivalent Python code

Project description

Build Status MIT License

PseuToPy

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 convert 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.

from pseutopy.pseutopy import PseuToPy
import astor

pseutopy = PseuToPy()

# These two lines generate the AST of the pseudocode instructions
convert_from_string = pseutopy.convert_from_string("declare a set a 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))

Or you can use the CLI utility that ships with this repository.

python pseutopy.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 and 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 contributions which greatly helped in setting up the bases for this project.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PseuToPy-1.0.1.post11.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PseuToPy-1.0.1.post11-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file PseuToPy-1.0.1.post11.tar.gz.

File metadata

  • Download URL: PseuToPy-1.0.1.post11.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.7

File hashes

Hashes for PseuToPy-1.0.1.post11.tar.gz
Algorithm Hash digest
SHA256 95e5f23fbc98ca79864a6e20ddbb3fbf99e8dba77850faa175a01c1f070b58e5
MD5 b817c2466f7a979bdec43cb24b570266
BLAKE2b-256 312c24544beae101b7199e529798a75bd721ba74d2f295d151826d7d604868f6

See more details on using hashes here.

File details

Details for the file PseuToPy-1.0.1.post11-py3-none-any.whl.

File metadata

  • Download URL: PseuToPy-1.0.1.post11-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.7

File hashes

Hashes for PseuToPy-1.0.1.post11-py3-none-any.whl
Algorithm Hash digest
SHA256 73aa20c8f6cdcb2c5fc444547463a79c1050ea6e43fcb9af65fc0ba66be63883
MD5 48e2c4c7bfbdf659a3dc5b6991e14993
BLAKE2b-256 142023a57f575e097db09184e5efa60ba4892654dede0f1b4a781c600b7cf754

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page