2014-01-13 23:53:42 +01:00
|
|
|
import argparse
|
2013-03-20 19:08:06 +01:00
|
|
|
import malbolge
|
|
|
|
|
2013-07-05 18:31:43 +02:00
|
|
|
|
2014-01-13 23:53:42 +01:00
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="Malbolge interpeter")
|
|
|
|
parser.add_argument("-f", "--file",
|
|
|
|
action="store_true", help="specify a file")
|
|
|
|
parser.add_argument("input", type=str,
|
|
|
|
help="malbolge program (string or file)")
|
|
|
|
args = parser.parse_args()
|
2013-08-25 19:31:57 +02:00
|
|
|
|
2014-01-13 23:53:42 +01:00
|
|
|
if args.file:
|
|
|
|
try:
|
|
|
|
program = open(args.input).read()
|
|
|
|
except FileNotFoundError:
|
|
|
|
parser.error("File not Found.")
|
|
|
|
if program == "":
|
|
|
|
parser.error("File is empty.")
|
|
|
|
else:
|
|
|
|
program = args.input
|
2013-08-25 19:31:57 +02:00
|
|
|
|
2014-01-13 23:53:42 +01:00
|
|
|
machine = malbolge.Machine()
|
|
|
|
machine.run(program)
|
2013-08-25 19:31:57 +02:00
|
|
|
|
2014-01-13 23:53:42 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|