-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
32 lines (26 loc) · 927 Bytes
/
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
from grammar_converter import readGrammarFile, convertGrammar, mapGrammar
from lexAnalysis import lexicalAnalysis
from cyk import cyk
import re, os, sys, argparse
from rules import lex_rule
import time
def main():
# Argparse, mengambil argument dari CLI //
parser = argparse.ArgumentParser()
parser.add_argument('file', type = argparse.FileType('r'))
args = parser.parse_args()
# Proses parsing script JavaScript
print()
print("==============JavaScript Parser============")
print("Loading Your Code...")
time.sleep(2)
print()
# Convert code dalam file script menjadi token
token = lexicalAnalysis(args.file.name,lex_rule)
# Buat CNF berdasarkan grammar cfg yang telah dibuat
CNFgrammar = mapGrammar(convertGrammar((readGrammarFile("cfg.txt"))))
print("Result : ", end ="")
cyk(token, CNFgrammar)
print("===========================================")
if __name__ == "__main__":
main()