GithubHelp home page GithubHelp logo

tabulatejarl8 / ti842py Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 0.0 245 KB

A TI-BASIC to Python 3 transpiler

Home Page: https://tabulate.tech

License: GNU General Public License v3.0

Python 100.00%
ti-basic python3 ti-84-plus-ce transpiler

ti842py's Introduction

ti842py Logo

PyPI Downloads PyPI license Maintenance GitHub Issues GitHub followers GitHub Repo stars
Kofi Badge


ti842py is a TI-BASIC to Python 3 transpiler. A transpiler is a piece of software that can convert code from one language to another. This program should be able to convert a lot of programs, but if you find something that it can't convert yet, start an issue. This transpiler also has the ability to automatically decompile any 8Xp file that you supply as the input file, with the help of my other project that I contribute to, basically-ti-basic. Note that this software is in beta and may produce inaccurate results.

Features


  • Converts string literals to comments
  • Attempts to interpret implicit multiplication
  • Attempts to fix floating point arithmetic errors
  • Disp/Output()
  • Variable assignment
  • If/Then/Else statements, including Else If
  • ClrHome
  • Input/Prompt
  • For, While, and Repeat loops
  • Pause
  • Wait
  • Stop
  • DelVar
  • getKey
  • Goto/Lbl
  • getDate, getTime, and dayOfWk
  • IS>(/DS<(
  • Menu()
  • toString()
  • randInt()/rand
  • Most drawing functions
  • List subscripting
  • Matrices
  • Ans
  • prgm
  • round()

Planned Features

  • Return
  • eval()/expr()

Known issues

Issues can be found at https://github.com/TabulateJarl8/ti842py/issues

Installation


ti842py can be installed via PyPI or by cloning the repository. To install it with PyPI, just run pip3 install ti842py in a terminal. To install it locally, you can clone the repository and run python setup.py install --user.

Usage


Feel free to use the programs found at https://github.com/TabulateJarl8/tiprograms to test this project out.

CLI Usage

ti842py can be used in 3 different ways. The first way is just running it from the command line. For example, if you wanted to convert the program in tiprogram.txt to tiprogram.py, you can this command: ti842py tiprogram.txt -o tiprogram.py. If no value is specified for -o, the converted program will be written to stdout. The -n flag can be added to force the transpiler to not decompile the input file, and the -d flag can be added to force the transpiler to attempt and decompile the input file. If the --run or -r argument is supplied, the resulting python file will be run after it is done transpiling

usage: ti842py [-h] [-o OUTFILE] [-n] [-d] [--no-fix-multiplication] [--no-fix-floating-point] [--turbo-draw] [-r] [-V] [infile]

TI-BASIC to Python 3 Transpiler

positional arguments:
  infile                Input file (filename or stdin).

optional arguments:
  -h, --help            show this help message and exit
  -o OUTFILE, --out OUTFILE
                        Optional output file to write to. Defaults to standard out.
  -n, --force-normal    Forces the program to not attempt and decompile the input file. Useful for false positives
  -d, --force-decompile
                        Forces the program to attempt to decompile the input file
  --no-fix-multiplication
                        Do not attempt to fix implicit multiplication. For example, AB -> A*B and A(1) -> A*(1)
  --no-fix-floating-point
                        Do not attempt to fix floating point arithmetic errors. For example, 1.1 * 3 would normally say 3.3000000000000003 instead of 3.3
  --turbo-draw          Remove the 0.1 second delay between drawing actions
  -r, --run             Runs the program after it's done transpiling. Will not print to stdout
  -V, --version         show program's version number and exit

Advanced terminal usage

You can use ti842py by piping files to it's stdin. This can be done via pipes or redirects, and the files can be either 8Xp or plain text files, just like normal. Here's some examples:

$ cat BAR.8Xp | ti842py --run
$ ti842py -o bar.py < BAR.8Xp
$ cat CLOCK.bas | ti842py -nr
$ ti842py --no-fix-floating-point --run < CLOCK.bas

Programmatic Usage

ti842py can also be imported and used in a program. Here is an example program to convert tiprogram.txt to tiprogram.py:

from ti842py import transpile

transpile("tiprogram.txt", "tiprogram.py")

Again, if the second argument is not supplied, the program will be written to stdout. The transpile command can be supplied with optional arguments. decompileFile, multiplication, and floating_point default to True, and forceDecompile, run, and turbo_draw default to False

The last way that ti842py can be ran is by running the main python file. After cloning the repository, cd into the repository and run python ti842py/main.py inputfile.txt. You can supply any arguments that you would supply with the ti842py command.

Special functions


  • getKey - The getKey function works just like it does in normal TI-BASIC, except with some special rules. Any key on the keyboard pressed will be converted to the corresponding key on the calculator. This works for letters, numbers, arrow keys, enter, delete, and symbols. As for the buttons not on a keyboard, the top 5 keys are the F1-F5 keys on the keyboard, 2nd is grave `, and alpha is tilda ~. mode is F6, stat is f7, vars is F8, the X,T,θ,n key is F9, and clear is backspace.

  • If - If blocks with Then after the If must be ended with End, they cannot be left open. If blocks on 2 lines without a Then cannot be closed with End

  • prgm - prgm will search the current directory for a file matching the provided name (case insensitive; extension of .8xp). If found, the file will be passed to the command ti842py {filename} --run, where {filename} is the name of the file. If a path is given that contains . or ~, or if the path is not all uppercase, the transpiler will assume that the path has been manually provided by the user (this will be useful once I implement a TI-BASIC shell).

Libraries used


ti842py's People

Contributors

tabulatejarl8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ti842py's Issues

Shell interpreter

Is your feature request related to a problem? Please describe.
It would be interesting to add a flag that drops the user into a shell, similar to that of Python's shell. This would be like the home screen shell that you're in on the TI-84, where you can't do any advanced programming stuff but you can call other programs and do calculations and other similar things.

Describe the solution you'd like
Implement a shell similar to the shell in the TI-84 calculator.

Persistant data

Is your feature request related to a problem? Please describe.
Add a system that allows things like variables, lists, matrices, graphs, etc to persist across program runs. Also add an option to disable it. This will make it more similar to how the TI-84 works

Additional context
Use a class that sorts locals into dictionaries and pickles them

Rewrite tests

Rewrite tests to use unittest instead of doing things manually

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.