Is there a programming language that is combination of Python and Basic?
Arnaud Delobelle
arnodel at googlemail.com
Fri Apr 17 17:23:54 EDT 2009
baykus <baykusderki at gmail.com> writes:
> Hi
>
> I am looking for one of those experimental languages that might be
> combination of python+basic. Now thta sounds weird and awkward I know.
> The reason I am asking is that I always liked how I could reference-
> call certain line number back in the days. It would be interesting to
> get similar functionality in Python.
I am currently working on such a "Python-Basic" programming language.
Here is the current implementation:
-------------- basic.py ----------------
class GotoLine(Exception): pass
def goto(newlno): raise GotoLine(newlno)
def run(program):
lno = 0
env = { 'goto': goto }
try:
while lno <= max(program):
try:
if lno in program:
exec program[lno] in env
lno += 1
except GotoLine, g:
lno, = g.args
except Exception:
print "? Syntax error in line", lno
print "OK."
----------------------------------------
Example of use
==============
marigold:junk arno$ python -i basic.py
>>> program = {
... 5: "# REM Python-Basic example program",
... 6: "# REM ----------------------------",
... 10: "i = 0",
... 20: "print 'Hello, world', i",
... 30: "i = i + 1",
... 40: "if i < 10: goto(20)",
... 50: "name = raw_input('What is your name? ')",
... 60: "print 'Welcome,', name",
... 70: "gosub(80)"
... }
>>> run(program)
Hello, world 0
Hello, world 1
Hello, world 2
Hello, world 3
Hello, world 4
Hello, world 5
Hello, world 6
Hello, world 7
Hello, world 8
Hello, world 9
What is your name? Arnaud
Welcome, Arnaud
? Syntax error in line 70
OK.
>>>
As you can see, I haven't implemented gosub() yet.
--
Arnaud
More information about the Python-list
mailing list