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.post12.tar.gz (12.5 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.post12-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: PseuToPy-1.0.1.post12.tar.gz
  • Upload date:
  • Size: 12.5 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.post12.tar.gz
Algorithm Hash digest
SHA256 c7c3a58799fcb2b3c2d5cda44676b3ee85491af86168ca0f51fa68815cba5786
MD5 6b7f6cc3e197c3019c7c5406a7757d4e
BLAKE2b-256 e6eb914a277c6ea7021e66f6403fc65d8f897f5496d0ab87cf39dde41b0e8e74

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PseuToPy-1.0.1.post12-py3-none-any.whl
  • Upload date:
  • Size: 12.6 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.post12-py3-none-any.whl
Algorithm Hash digest
SHA256 11c05c182120dc4c10029681f3e82dcc0d8804fd193f06cbbced3384c943e9e9
MD5 ea7b803f5ee1fe8460884dadd495d8f4
BLAKE2b-256 02d35428f64512ae4d06be9f4333403e0c0d9876a04885524ff0624e455b5eff

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