-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyzer.py
More file actions
32 lines (23 loc) · 776 Bytes
/
analyzer.py
File metadata and controls
32 lines (23 loc) · 776 Bytes
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
import argparse
from pyformlang.cfg import *
from src.cfg_algorithms import cyk
from src.regex_cfg import RegexCFG
def check(script):
script = [Terminal(x) for x in script.replace(' ', '@')]
return cyk(script, RegexCFG.from_txt('grammar.txt').to_cnf())
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='script analyzer using CYK')
parser.add_argument(
'--script'
, required=False
, type=str
, help='path to script.txt'
, default=None
)
args = parser.parse_args()
script = ''
with open(args.script, 'r') as f:
for line in f:
script += line.replace('\n', '')
accepts = check(script)
print(f'Script is {"accepted" if accepts else "not accepted"}')