From e1270f81bdc81f5a575b34c2d2c294bdde3e6f4f Mon Sep 17 00:00:00 2001
From: Nathan Binkert <nate@binkert.org>
Date: Sun, 16 Aug 2009 13:39:58 -0700
Subject: ply: update PLY to version 3.2

---
 ext/ply/example/BASIC/basiclog.py | 79 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 ext/ply/example/BASIC/basiclog.py

(limited to 'ext/ply/example/BASIC/basiclog.py')

diff --git a/ext/ply/example/BASIC/basiclog.py b/ext/ply/example/BASIC/basiclog.py
new file mode 100644
index 000000000..ccfd7b967
--- /dev/null
+++ b/ext/ply/example/BASIC/basiclog.py
@@ -0,0 +1,79 @@
+# An implementation of Dartmouth BASIC (1964)
+#
+
+import sys
+sys.path.insert(0,"../..")
+
+if sys.version_info[0] >= 3:
+    raw_input = input
+
+import logging
+logging.basicConfig(
+    level = logging.INFO,
+    filename = "parselog.txt",
+    filemode = "w"
+)
+log = logging.getLogger()
+
+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,debug=log)
+    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,debug=log)
+    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()
+
+  
+            
+
+
+
+
+
+
-- 
cgit v1.2.3