aboutsummaryrefslogtreecommitdiffstats
path: root/third_party/ply/example/BASIC/basic.py
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2023-06-24 13:38:11 +0200
committerMartin Robinson <mrobinson@igalia.com>2023-06-30 09:51:31 +0200
commit8be014ee46077e78db21c5d73058c35a4ee65fa9 (patch)
tree9bfd0bc11997381d792fd3015add8be9cd7abd70 /third_party/ply/example/BASIC/basic.py
parent7412e28349237055652a08a2216043d0993a3cea (diff)
downloadservo-8be014ee46077e78db21c5d73058c35a4ee65fa9.tar.gz
servo-8be014ee46077e78db21c5d73058c35a4ee65fa9.zip
Create a top-level "third_party" directory
This directory now contains third_party software that is vendored into the Servo source tree. The idea is that it would eventually hold webrender and other crates from mozilla-central as well with a standard patch management approach for each.
Diffstat (limited to 'third_party/ply/example/BASIC/basic.py')
-rw-r--r--third_party/ply/example/BASIC/basic.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/third_party/ply/example/BASIC/basic.py b/third_party/ply/example/BASIC/basic.py
new file mode 100644
index 00000000000..70ac9e7c740
--- /dev/null
+++ b/third_party/ply/example/BASIC/basic.py
@@ -0,0 +1,65 @@
+# 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()