-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (39 loc) · 1.13 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import logging
import nltk
import sys
from instruction import Instruction
from interpreter import Interpreter
FORMAT = '%(asctime)-15s %(name)-12s %(levelname)-8s %(message)s'
LOG = logging.getLogger('main')
LOG.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter(FORMAT))
LOG.addHandler(ch)
def main():
instructions = []
tokens = tokenize("input.asm")
for t in tokens:
ins = Instruction()
ins.instruction = t[0].upper()
try:
ins.parameters.append(t[1].upper())
ins.parameters.append(t[3].upper())
except:
pass
instructions.append(ins)
interpreter = Interpreter(instructions)
interpreter.run()
def prepare_nltk():
""" Download nltk tokenizer data files"""
nltk.download(info_or_id='punkt')
def tokenize(file):
prepare_nltk()
try:
with open(file , "r") as f:
lines = f.readlines()
return [nltk.word_tokenize(l) for l in lines]
except Exception as e:
LOG.error("Couldn't read input file: {}".format(e))
sys.exit(1)
if __name__ == '__main__':
main()