-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathredcode.py
More file actions
46 lines (34 loc) · 844 Bytes
/
redcode.py
File metadata and controls
46 lines (34 loc) · 844 Bytes
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sys
import redcodelex, redcodeparse
def print_usage(program_name):
print("Usage: {} <filename>".format(program_name))
def main():
# Sanity check arguments
if len(sys.argv) == 2:
filename = sys.argv[1]
else:
print_usage(sys.argv[0])
sys.exit(1)
# Source code to build
data = ''
# Determine whether to operate on a file or stdin
if filename == "-":
# Operate on stdin
pass
else:
data = open(filename, 'r').read()
'''
# Build the lexer on the program bytes
lexer.input(data)
# Tokenize
while True:
tok = lexer.token()
if not tok:
break # No more input
print(tok)
'''
# Parser test
result = redcodeparse.parse(data)
print(result)
if __name__ == '__main__':
main()