summaryrefslogtreecommitdiff
path: root/ext/ply/example/BASIC/basic.py
diff options
context:
space:
mode:
authorSteve Reinhardt <stever@eecs.umich.edu>2007-05-26 17:10:35 -0700
committerSteve Reinhardt <stever@eecs.umich.edu>2007-05-26 17:10:35 -0700
commit87bb4c3792d080e0be0b16b0b39957215c7dfbfa (patch)
tree610381930af6bedda57cea3662563965c9c4cc63 /ext/ply/example/BASIC/basic.py
parentda46364b1878339841e9cda5a62ee104409b6535 (diff)
parent44ebb8d3e27329e9f0b501897585359b4ab696f2 (diff)
downloadgem5-87bb4c3792d080e0be0b16b0b39957215c7dfbfa.tar.xz
Merge vm1.(none):/home/stever/bk/newmem-head
into vm1.(none):/home/stever/bk/newmem-cache2 --HG-- extra : convert_revision : c2540bfd34eb5a6f41cb15ffe50f8ec72f80abb1
Diffstat (limited to 'ext/ply/example/BASIC/basic.py')
-rw-r--r--ext/ply/example/BASIC/basic.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/ext/ply/example/BASIC/basic.py b/ext/ply/example/BASIC/basic.py
new file mode 100644
index 000000000..3a07acdbf
--- /dev/null
+++ b/ext/ply/example/BASIC/basic.py
@@ -0,0 +1,68 @@
+# An implementation of Dartmouth BASIC (1964)
+#
+
+import sys
+sys.path.insert(0,"../..")
+
+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 = prog.keys()
+ 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()
+
+
+
+
+
+
+
+
+