Code Monkey home page Code Monkey logo

olpybasic's Introduction

OLPyBASIC

Python with line numbers (Ordered List Python BASIC (Beginners' All-purpose Symbolic Instruction Code)) is a new programming language with goto. Syntax and features will change without prior notice.

There are numbers before each line and the code runs in order, but execution can jump using goto or gosub with return. For each numbered line it uses Python's exec() function. That means it's compatible with Python3 or MicroPython in each logical line. OLPyBASIC has the advantage that you can have tutorials where you add lines to the program. It will also be easy to implement single stepping and continue after stop. Another advantage is that you can run spaghetti code in Python. This means that you can easily convert old BASIC programs to run in a modern programming language that normally lacks goto. This buys you time while you try to figure out how to remove the gotos, or leave them in, if your customer accepts that. Labels are supported using e.g. lbl("ex") and goto("ex"), see the examples folder.

To start:

python3 -i olpybasic.py # Next line is an alternative if you have MicroPython in Linux or Unix.
~/micropython/ports/unix/micropython -i olpybasic.py # Next line is for NumWorks calculator.
from olpybasic import *

Example input (no need to input comments after #):

P('10 print("OLPyBASIC")') # P is short for put.
run() # Run i.e. start program.
P('20 print("uPython")') # If difficult to enter single quote, try P(input())
run()
P('30 x=30')
P('40 print(x)')
run()
P('50 x+=1')
P('60 if x<=40:goto(40)')
run()
PM() # PM is short for paste mode
70 stop()
90 print(11*x)
99 ret()
45 gosub(90) # Enter empty line to quit paste mode.

Enter:

run()
L() # L is short for list
D(50) # D is short for delete
L()
P('50 x+=2')
L()
tron() # trace on
run()
troff() # trace off
run()

Please create issues if you have bug reports, suggestions for e.g. code improvements (I'm a Python/MicroPython beginner), or feature requests. This should be very light weight, but also comfortable to use.

Planned changes: for loops might be implemented, by converting them to if with gotos like in Ratfor.

Run OLPyBASIC online in browser: https://my.numworks.com/python/mobluse/olpybasic
https://my.numworks.com/python/mobluse/test_olpybas
https://my.numworks.com/simulators/zzpnwo (Doesn't work now, but the issue is reported.)

New Reddit
Old Reddit

The editor is inspired by ZX Forth Editor Manual.

olpybasic's People

Contributors

mobluse avatar

Watchers

 avatar  avatar  avatar

olpybasic's Issues

Write a program that converts BASIC to OLPyBASIC

It would be rather easy to write a program that converts ZX80 or ZX81 BASIC to OLPyBASIC since these BASICs only have one statement per line. It's relatively easy to write a program that converts from ZX Spectrum BASIC to ZX81 BASIC. Conversion programs from Microsoft BASIC e.g. CBM BASIC v2 (for e.g. C64), MBASIC, or GW-BASIC should also be possible. Also Applesoft BASIC should be possible to convert, but it has different precedence rules.

Write such a conversion program!

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.