-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cactus.py
46 lines (35 loc) · 1.06 KB
/
Cactus.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
import sys
from Scanner import *
from Error import *
from AST import AST
class Cacti:
def __init__(self):
self.file = ""
self.scanner = None
self.text = ""
self.error = Error()
# checks to make sure there's at least 1 file.
# if(len(sys.argv) != 2):
# self.throw("please import 1 file", 0)
# else:
# self.scan(sys.argv[1])
self.scan("./thorn.cactus")
self.tokens = self.scanner.tokens
# print("AST Construction==========>")
self.ast = AST(self.tokens)
# Method to import and scan file
def scan(self, name):
try:
self.file = open(name, "r")
except:
self.throw("unable to open file", 1)
self.text = self.file.read()
self.scanner = Scanner(self.text)
self.file.close()
# print("Success!")
# helper method to deal with errors
def throw(self, s, l):
self.error.setError(s, l)
self.error.throwError()
if __name__ == "__main__":
cacti = Cacti()