-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind-inconsistent-grammar.sh
120 lines (109 loc) · 2.3 KB
/
find-inconsistent-grammar.sh
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh
d=`find . -name '*.g4' | grep -v examples | grep -v Generated | sed 's#/[^/]*.g4##' | sort -u`
# find all other grammars in this directory and check if they are
# inconsistently combined or splitted.
for i in $d
do
for j in $i/*.g4
do
spgrammar=no
slgrammar=no
cat $j | grep "parser[ \t\n\r]*grammar" > /dev/null
if [[ $? == 0 ]]
then
spgrammar=yes
fi
cat $j | grep "lexer[ \t\n\r]*grammar" > /dev/null
if [[ $? == 0 ]]
then
slgrammar=yes
fi
for k in $i/*.g4
do
sopgrammar=no
solgrammar=no
if [[ "$j" == "$k" ]]
then
continue
fi
cat $k | grep "parser[ \t\n\r]*grammar" > /dev/null
if [[ $? == 0 ]]
then
sopgrammar=yes
fi
cat $k | grep "lexer[ \t\n\r]*grammar" > /dev/null
if [[ $? == 0 ]]
then
solgrammar=yes
fi
if [[ $spgrammar == "yes" || "$slgrammar" == "yes" ]]
then
if [[ $sopgrammar == "no" && "$solgrammar" == "no" ]]
then
echo $spgrammar $slgrammar $sopgrammar $solgrammar
echo A Inconsistent split/combine grammars in $i
fi
fi
if [[ "$spgrammar" == "no" && "$slgrammar" == "no" ]]
then
if [[ "$sopgrammar" == "yes" || "$solgrammar" == "yes" ]]
then
echo $spgrammar $slgrammar $sopgrammar $solgrammar
echo B Inconsistent split/combine grammars in $i
fi
fi
done
done
done
f=`find . -name '*.g4' | grep -v examples | grep -v Generated`
for i in $f
do
echo $i | grep -i parser > /dev/null
if [[ $? == 0 ]]
then
pfile=yes
else
pfile=no
fi
cat $i | grep "parser[ \t\n\r]*grammar" > /dev/null
if [[ $? == 0 ]]
then
pgrammar=yes
else
pgrammar=no
fi
echo $i | grep -i lexer > /dev/null
if [[ $? == 0 ]]
then
lfile=yes
else
lfile=no
fi
cat $i | grep "lexer[ \t\n\r]*grammar" > /dev/null
if [[ $? == 0 ]]
then
lgrammar=yes
else
lgrammar=no
fi
if [[ "$pgrammar" == "yes" && "$pfile" == "no" ]]
then
echo $pgrammar $pfile $lgrammar $lfile
echo problem A with $i
fi
if [[ "$pgrammar" == "no" && "$pfile" == "yes" ]]
then
echo $pgrammar $pfile $lgrammar $lfile
echo problem B with $i
fi
if [[ "$lgrammar" == "yes" && "$lfile" == "no" ]]
then
echo $pgrammar $pfile $lgrammar $lfile
echo problem C with $i
fi
if [[ "$lgrammar" == "no" && "$lfile" == "yes" ]]
then
echo $pgrammar $pfile $lgrammar $lfile
echo problem D with $i
fi
done