Beispiel #1
0
    return '\n\n'.join(fns)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Compile or interpret .math scripts.')

    parser.add_argument('filename', type=str,
                        help='the file to compile or interpret')
    parser.add_argument('-o, --out', dest='output', type=str,
                        help='the file to write compiled output to')
    parser.add_argument('-p, --pretty', dest='pretty',
                        action='store_true',
                        help='output pretty-printed code')

    args = parser.parse_args()

    fns, code = compile_bytecode(args.filename)
    if args.pretty:
        out = prettyprint(fns, code)
        if args.output:
            with open(args.output, 'w') as f:
                f.write(out)
        else:
            print(out)
    elif args.output:
        output(code, args.output)
    else:
        result = interp(fns, code)
        print(result)
Beispiel #2
0
@app.route('/', methods = ['POST'])
def hello():
	try:
		program = json.loads(request.data)
	except ValueError, e:
		print request.data
		return json.dumps({'error': 'invalid json'}), 400
	if "Pages" not in program:
		return json.dumps({'error': 'no pages in program'}), 400
	hasMain = False
	for page in program["Pages"]:
		if 'Name' not in page:
			return json.dumps({'error': 'malformed page'}), 400
		if page['Name'] == 'Main':
			hasMain = True
	if not hasMain:
		return json.dumps({'error': 'no main page'}), 400
	print program
	try:
		interpreter.interp(program)
	except:
		print '-'*20
		traceback.print_exc(file=sys.stdout)
		print '-'*20
		return json.dumps({'error': 'problem running program'}), 400
	return json.dumps({'success': 'program ran to completion'}), 200

if __name__ == "__main__":
	app.run(host='0.0.0.0', port=80,debug=True)