-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplumber.py
More file actions
68 lines (54 loc) · 1.69 KB
/
Copy pathplumber.py
File metadata and controls
68 lines (54 loc) · 1.69 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from lexer import LexicalAnalyzer
from parser_class import Parser
import sys
import os
def main():
#for debug reasons. set this to false if not using debugger
debug = False #set sample file path inside the debug_path
debug_path = os.getcwd() + "\\sample.plumb"
script_path = ""
#end of debug settings
shell = False
script = False
args_list = sys.argv
if len(args_list) <= 1 and not debug:
shell = True
if len(args_list) >= 2 and not debug:
if args_list[1] == "--help":
print("Usage: python plumber.py <input file>")
sys.exit(1)
else:
script_path += args_list[1]
script = True
#check if file ends with plumb
if shell:
while True:
str = input("\033[0m"+"Plumber shell << ")
if str == "":
continue
else:
str += "\n"
lex = LexicalAnalyzer(str)
lex.scanToken()
if lex.isError():
continue
parser = Parser(lex.get_token_list()).ParseToken()
if script:
if debug:
script_path = debug_path
if not script_path.endswith(".plumb"):
print("Error: Invalid file type. Try using .plumb")
sys.exit(1)
try:
f = open(script_path, "r")
file_str = f.read()
lexer = LexicalAnalyzer(file_str)
lexer.scanToken()
parser = Parser(lexer.get_token_list())
if lexer.isError():
return
parser.ParseToken()
except Exception as e:
print(e)
if __name__ == "__main__":
main()