-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
60 lines (48 loc) · 1.25 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
53
54
55
56
57
58
59
60
import CFG
import CYK
import lexer
import argparse
import time
from colorama import Fore, Style
def splash():
print(Fore.YELLOW)
print("============================")
print(" JAVASCRIPT SYNTAX LINTER")
print(" 三位棉兰男神 ")
print("============================")
print(Style.RESET_ALL)
# argparse
parser = argparse.ArgumentParser()
parser.add_argument('file', type=argparse.FileType('r'))
args = parser.parse_args()
filename = args.file.name
# splash
splash()
print(Fore.BLUE +
f'Checking {filename}...\nPlease wait for a moment...' + Style.RESET_ALL)
# timer start
start = time.time()
# grammar
grammar = CFG.Grammar().parseCFG('grammar.txt')
# lexer
lexer = lexer.parseToToken(filename)
# CYK algorithm
result = CYK.cykParse(lexer, grammar)
# time end
end = time.time()
# Result
if result:
print(Fore.GREEN)
print("|--------------------|")
print("| Compile Success!!! |")
print("|--------------------|")
print(Style.RESET_ALL)
else:
print(Fore.RED)
print("|------------------|")
print("| Compile Error... |")
print("|------------------|")
print(Style.RESET_ALL)
# execution time
print(Fore.YELLOW +
f'Execution time : {(end-start):.2f} seconds\n', Style.RESET_ALL)