forked from arleenchr/IF2124-Tugas-Besar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparserprogram.py
37 lines (31 loc) · 869 Bytes
/
parserprogram.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
from argparse import ArgumentParser
from convert_to_cfg import file_to_cfg
from convert_to_cnf import cfg_to_cnf
from cyk import cyk
from lexer import tokenToStr
from colorama import Back, Style
def red() :
print("\033[31m", end='')
def green() :
print("\033[32m", end='')
def reset() :
print("\033[0m", end='')
if __name__ == "__main__":
# command parser
argParser = ArgumentParser()
argParser.add_argument("filename", type=str)
args = argParser.parse_args()
#print(args.filename)
#print(tokenToStr(args.filename))
# cek
print(Back.CYAN + "Processing...", end='')
print(Style.RESET_ALL)
print()
if (cyk(cfg_to_cnf(file_to_cfg("grammar.txt")),tokenToStr(args.filename))):
green()
print("Accepted")
reset()
else:
red()
print("Syntax Error")
reset()