-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·37 lines (33 loc) · 1003 Bytes
/
main.py
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
#! /usr/bin/env python3
from lex import tokenize
from parser import parse_tokenlist
from table import SymbolTable
from sys import argv
if __name__ == '__main__':
sym = SymbolTable()
if len(argv) <= 1:
text="LOOP: ADD 12 3 R0;\n" +\
" ADD 5 R0 R1;\n" +\
" GOTO LOOP;;\n"
print("Program:")
print(text)
token_list = tokenize(text, sym)
s,w = parse_tokenlist(token_list)
print("Parsed:")
for l in s:
print(l)
print("Warnings:")
for l in w:
print(l)
else:
for fn in argv[1:]:
print("File name: {}".format(fn))
with open(fn) as f:
token_list = tokenize(f.read(), sym)
s,w = parse_tokenlist(token_list)
print("Parsed:")
for l in s:
print(l)
print("Warnings:")
for l in w:
print(l)