forked from vspandan/IFuzzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckDBVsNonTerm.py
45 lines (36 loc) · 1.21 KB
/
checkDBVsNonTerm.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
from os.path import exists
grammarfile='/home/rubbernecker/ifuzzer_s/langparser/JavaScript.g4'
fragpoolfolder="/home/rubbernecker/ifuzzer_s/database/"
non_Terminals=[]
def set_bnf(bnf):
def strip_spaces(key, values):
values = [value.strip()
for value in values.split('|') if value]
return values
bnf_dict = {}
for item in bnf.split('\n'):
if item.find(':') >= 0:
key, values = item.split(':',1)
key = key.strip()
bnf_dict[key] = strip_spaces(key, values)
non_Terminals.append(key)
elif item:
values = bnf_dict[key]
values.extend(strip_spaces(key, item))
bnf_dict[key] = values
else:
pass
def _extractProductions():
bnf=""
f = open(grammarfile,'r')
for line in f:
bnf+=line;
f.close()
set_bnf(bnf)
def _verifyDBFiles():
_extractProductions()
for nonTerm in non_Terminals:
if not exists(fragpoolfolder+nonTerm):
print nonTerm
if __name__ == '__main__':
_verifyDBFiles()