# An implementation of Dartmouth BASIC (1964) # import sys sys.path.insert(0,"../..") if sys.version_info[0] >= 3: raw_input = input import basiclex import basparse import basinterp # If a filename has been specified, we try to run it. # If a runtime error occurs, we bail out and enter # interactive mode below if len(sys.argv) == 2: data = open(sys.argv[1]).read() prog = basparse.parse(data) if not prog: raise SystemExit b = basinterp.BasicInterpreter(prog) try: b.run() raise SystemExit except RuntimeError: pass else: b = basinterp.BasicInterpreter({}) # Interactive mode. This incrementally adds/deletes statements # from the program stored in the BasicInterpreter object. In # addition, special commands 'NEW','LIST',and 'RUN' are added. # Specifying a line number with no code deletes that line from # the program. while 1: try: line = raw_input("[BASIC] ") except EOFError: raise SystemExit if not line: continue line += "\n" prog = basparse.parse(line) if not prog: continue keys = list(prog) if keys[0] > 0: b.add_statements(prog) else: stat = prog[keys[0]] if stat[0] == 'RUN': try: b.run() except RuntimeError: pass elif stat[0] == 'LIST': b.list() elif stat[0] == 'BLANK': b.del_line(stat[1]) elif stat[0] == 'NEW': b.new()
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
README | File | 2.45 KB | 0644 |
|
basic.py | File | 1.5 KB | 0644 |
|
basiclex.py | File | 1.15 KB | 0644 |
|
basiclog.py | File | 1.65 KB | 0644 |
|
basinterp.py | File | 16.88 KB | 0644 |
|
basparse.py | File | 8.69 KB | 0644 |
|
dim.bas | File | 224 B | 0644 |
|
func.bas | File | 73 B | 0644 |
|
gcd.bas | File | 359 B | 0644 |
|
gosub.bas | File | 216 B | 0644 |
|
hello.bas | File | 57 B | 0644 |
|
linear.bas | File | 420 B | 0644 |
|
maxsin.bas | File | 217 B | 0644 |
|
powers.bas | File | 268 B | 0644 |
|
rand.bas | File | 60 B | 0644 |
|
sales.bas | File | 375 B | 0644 |
|
sears.bas | File | 481 B | 0644 |
|
sqrt1.bas | File | 78 B | 0644 |
|
sqrt2.bas | File | 56 B | 0644 |
|