aboutsummaryrefslogtreecommitdiffstats
path: root/bytetunes.py
blob: 597ef3acc0f5a92d080000aee84b670341c35cde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python

from expr import *

import sys

DEFAULT = "(t>>6)&(2*t)&(t>>1)"

def play(s):
    machine = parse(preparse(tokenize(s)))
    t = 0
    while True:
        t += 1
        sys.stdout.write(chr(execute(machine, t) & 0x000000FF))

def main():
    if len(sys.argv) <= 1:
        play(DEFAULT)
    elif sys.argv[1] == '--test':
        test_tokenize()
        test_preparse()
        test_parse()
    elif sys.argv[1] == '--parse':
        if len(sys.argv) < 3:
            print strmachine(parse(preparse(tokenize(DEFAULT))))
        else:
            print strmachine(parse(preparse(tokenize(sys.argv[2]))))
    else:
        play(sys.argv[1])

if __name__=='__main__':
    main()