diff --git a/topics/investigation/complexity/Makefile b/topics/investigation/complexity/Makefile new file mode 100644 index 00000000..1984db02 --- /dev/null +++ b/topics/investigation/complexity/Makefile @@ -0,0 +1,7 @@ +test: + cp ../../convergence/fl/snapshot/*.bgf tests/ + cp ../../convergence/java/snapshot/*.bgf tests/ + ls -1 tests/*.bgf | xargs -n1 ./testperform + +clean: + rm -f tests/*.bgf tests/*.out \ No newline at end of file diff --git a/topics/investigation/complexity/avs.py b/topics/investigation/complexity/avs.py new file mode 100755 index 00000000..8b944439 --- /dev/null +++ b/topics/investigation/complexity/avs.py @@ -0,0 +1,40 @@ +#!/usr/local/bin/python +# -*- coding: utf-8 -*- +import sys +sys.path.append('../../../shared/python') +import BGF +sys.path.append('../size') +import var + +def rhssize(node): + if node.__class__.__name__ == 'Grammar': + return sum(map(rhssize,node.prods))/(0.0+len(var.var(node))) + elif node.__class__.__name__ in ('Production','Selectable'): + return rhssize(node.expr) + elif node.__class__.__name__ == 'Expression': + return rhssize(node.wrapped) + elif node.__class__.__name__ == 'Marked': + return rhssize(node.data) + elif node.__class__.__name__ in ('Plus','Star','Optional'): + return rhssize(node.data) + elif node.__class__.__name__ in ('Terminal','Nonterminal','Value'): + return 1 + elif node.__class__.__name__ in ('Epsilon','Any','Empty'): + return 0 + elif node.__class__.__name__ in ('Choice','Sequence'): + return sum(map(rhssize,node.data)) + else: + print 'How to deal with',node.__class__.__name__,'?' + return 0 + +if __name__ == "__main__": + if len(sys.argv) != 2: + print 'This tool calculates an AVS metric for any given BGF grammar.' + print 'Usage:' + print ' '+sys.argv[0]+' ' + sys.exit(1) + bgf = BGF.Grammar() + bgf.parse(sys.argv[1]) + #print 'AVS =',rhssize(bgf) + print '%.2f' % rhssize(bgf) + sys.exit(0) diff --git a/topics/investigation/complexity/hal.py b/topics/investigation/complexity/hal.py new file mode 100755 index 00000000..d96dae02 --- /dev/null +++ b/topics/investigation/complexity/hal.py @@ -0,0 +1,104 @@ +#!/usr/local/bin/python +# -*- coding: utf-8 -*- +import sys +import math +sys.path.append('../../../shared/python') +import BGF +sys.path.append('../size') +import var +import term + +def values(g): + # returns the number of values used in the grammar + vals = [] + for v in g.getXml().findall('.//value'): + if v.text not in vals: + vals.append(v.text) + return vals + +def labels(g): + # returns the number of production labels used in the grammar + labs = [] + for v in g.prods: + if v.label and v.label not in labs: + labs.append(v.label) + return labs + +def selectors(g): + # returns the number of expression selectors used in the grammar + sels = [] + for v in g.getXml().findall('.//selectable'): + if v.findtext('selector') not in sels: + sels.append(v.findtext('selector')) + return sels + +def opr(node): + # number of occurrences of operators + if node.__class__.__name__ == 'Grammar': + return sum(map(opr,node.prods)) + elif node.__class__.__name__ == 'Production': + return opr(node.expr) + elif node.__class__.__name__ == 'Selectable': + return 1+opr(node.expr) + elif node.__class__.__name__ == 'Expression': + return opr(node.wrapped) + elif node.__class__.__name__ == 'Marked': + return 1+opr(node.data) + elif node.__class__.__name__ in ('Plus','Star','Optional'): + return 1+opr(node.data) + elif node.__class__.__name__ in ('Terminal','Nonterminal','Value'): + return 0 + elif node.__class__.__name__ in ('Epsilon','Any','Empty'): + return 1 + elif node.__class__.__name__ in ('Choice','Sequence'): + return sum(map(opr,node.data)) + else: + print 'How to deal with',node.__class__.__name__,'?' + return 0 + +def opd(node): + # number of occurrences of operands + if node.__class__.__name__ == 'Grammar': + return sum(map(opd,node.prods)) + elif node.__class__.__name__ == 'Production': + if node.label: + return 2+opd(node.expr) + else: + return 1+opd(node.expr) + elif node.__class__.__name__ == 'Selectable': + return 1+opd(node.expr) + elif node.__class__.__name__ == 'Expression': + return opd(node.wrapped) + elif node.__class__.__name__ == 'Marked': + return opd(node.data) + elif node.__class__.__name__ in ('Plus','Star','Optional'): + return opd(node.data) + elif node.__class__.__name__ in ('Terminal','Nonterminal','Value'): + return 1 + elif node.__class__.__name__ in ('Epsilon','Any','Empty'): + return 0 + elif node.__class__.__name__ in ('Choice','Sequence'): + return sum(map(opd,node.data)) + else: + print 'How to deal with',node.__class__.__name__,'?' + return 0 + +if __name__ == "__main__": + if len(sys.argv) != 2: + print 'This tool calculates a HAL metric for any given BGF grammar.' + print 'Usage:' + print ' '+sys.argv[0]+' ' + sys.exit(1) + bgf = BGF.Grammar() + bgf.parse(sys.argv[1]) + + # Selectable, Marked, Plus, Star, Optional, Epsilon, Empty, Any, Choice, Sequence + mu1 = 10 + mu2 = len(var.var(bgf)) + len(term.term(bgf)) + len(values(bgf)) + len(labels(bgf)) + len(selectors(bgf)) + eta1 = opr(bgf) + eta2 = opd(bgf) + hal = (mu1*eta2*(eta1+eta2)*math.log(mu1+mu2,2)) / (2*mu2) + #print 'µ₁ =',mu1,', µ₂ =',mu2,', η₁ =',eta1,', η₂ =',eta2 + #print 'HAL =',hal + print '%.2f' % hal + sys.exit(0) diff --git a/topics/investigation/complexity/mcc.py b/topics/investigation/complexity/mcc.py new file mode 100755 index 00000000..cf6cea69 --- /dev/null +++ b/topics/investigation/complexity/mcc.py @@ -0,0 +1,38 @@ +#!/usr/local/bin/python +# -*- coding: utf-8 -*- +import sys +sys.path.append('../../../shared/python') +import BGF + +def mccabe(node): + if node.__class__.__name__ == 'Grammar': + return sum(map(mccabe,node.prods)) + elif node.__class__.__name__ in ('Production','Selectable'): + return mccabe(node.expr) + elif node.__class__.__name__ == 'Expression': + return mccabe(node.wrapped) + elif node.__class__.__name__ == 'Marked': + return mccabe(node.data) + elif node.__class__.__name__ in ('Plus','Star','Optional'): + return 1+mccabe(node.data) + elif node.__class__.__name__ in ('Terminal','Nonterminal','Epsilon','Any','Empty','Value'): + return 0 + elif node.__class__.__name__ == 'Choice': + return len(node.data)-1 + max(map(mccabe,node.data)) + elif node.__class__.__name__ == 'Sequence': + return sum(map(mccabe,node.data)) + else: + print 'How to deal with',node.__class__.__name__,'?' + return 0 + +if __name__ == "__main__": + if len(sys.argv) != 2: + print 'This tool calculates an MCC metric for any given BGF grammar.' + print 'Usage:' + print ' '+sys.argv[0]+' ' + sys.exit(1) + bgf = BGF.Grammar() + bgf.parse(sys.argv[1]) + #print 'MCC =',mccabe(bgf) + print mccabe(bgf) + sys.exit(0) diff --git a/topics/investigation/complexity/testperform b/topics/investigation/complexity/testperform new file mode 100755 index 00000000..5d61f2bf --- /dev/null +++ b/topics/investigation/complexity/testperform @@ -0,0 +1,7 @@ +#!/bin/sh + +echo [Test Case] `basename $1` +./mcc.py $1 > $1.out || exit -1 +./avs.py $1 >> $1.out || exit -1 +./hal.py $1 >> $1.out || exit -1 +diff $1.out $1.baseline || exit -1 diff --git a/topics/investigation/complexity/tests/antlr.bgf.baseline b/topics/investigation/complexity/tests/antlr.bgf.baseline new file mode 100644 index 00000000..a8346931 --- /dev/null +++ b/topics/investigation/complexity/tests/antlr.bgf.baseline @@ -0,0 +1,3 @@ +11 +2.55 +1810.64 diff --git a/topics/investigation/complexity/tests/dcg.bgf.baseline b/topics/investigation/complexity/tests/dcg.bgf.baseline new file mode 100644 index 00000000..e5913f8d --- /dev/null +++ b/topics/investigation/complexity/tests/dcg.bgf.baseline @@ -0,0 +1,3 @@ +5 +3.12 +2211.75 diff --git a/topics/investigation/complexity/tests/ecore.bgf.baseline b/topics/investigation/complexity/tests/ecore.bgf.baseline new file mode 100644 index 00000000..448d65b5 --- /dev/null +++ b/topics/investigation/complexity/tests/ecore.bgf.baseline @@ -0,0 +1,3 @@ +9 +2.17 +4570.24 diff --git a/topics/investigation/complexity/tests/ecore2.bgf.baseline b/topics/investigation/complexity/tests/ecore2.bgf.baseline new file mode 100644 index 00000000..49471199 --- /dev/null +++ b/topics/investigation/complexity/tests/ecore2.bgf.baseline @@ -0,0 +1,3 @@ +9 +2.11 +3139.12 diff --git a/topics/investigation/complexity/tests/fl_ldf.bgf.baseline b/topics/investigation/complexity/tests/fl_ldf.bgf.baseline new file mode 100644 index 00000000..472756d5 --- /dev/null +++ b/topics/investigation/complexity/tests/fl_ldf.bgf.baseline @@ -0,0 +1,3 @@ +3 +1.40 +360.00 diff --git a/topics/investigation/complexity/tests/impl1.bgf.baseline b/topics/investigation/complexity/tests/impl1.bgf.baseline new file mode 100644 index 00000000..99b87561 --- /dev/null +++ b/topics/investigation/complexity/tests/impl1.bgf.baseline @@ -0,0 +1,3 @@ +45 +4.07 +132357.97 diff --git a/topics/investigation/complexity/tests/impl2.bgf.baseline b/topics/investigation/complexity/tests/impl2.bgf.baseline new file mode 100644 index 00000000..7f38155d --- /dev/null +++ b/topics/investigation/complexity/tests/impl2.bgf.baseline @@ -0,0 +1,3 @@ +73 +4.47 +80315.75 diff --git a/topics/investigation/complexity/tests/impl3.bgf.baseline b/topics/investigation/complexity/tests/impl3.bgf.baseline new file mode 100644 index 00000000..e7fa6c41 --- /dev/null +++ b/topics/investigation/complexity/tests/impl3.bgf.baseline @@ -0,0 +1,3 @@ +130 +4.48 +132603.43 diff --git a/topics/investigation/complexity/tests/jaxb.bgf.baseline b/topics/investigation/complexity/tests/jaxb.bgf.baseline new file mode 100644 index 00000000..b41a4620 --- /dev/null +++ b/topics/investigation/complexity/tests/jaxb.bgf.baseline @@ -0,0 +1,3 @@ +9 +1.45 +3056.21 diff --git a/topics/investigation/complexity/tests/ldf.bgf.baseline b/topics/investigation/complexity/tests/ldf.bgf.baseline new file mode 100644 index 00000000..472756d5 --- /dev/null +++ b/topics/investigation/complexity/tests/ldf.bgf.baseline @@ -0,0 +1,3 @@ +3 +1.40 +360.00 diff --git a/topics/investigation/complexity/tests/om.bgf.baseline b/topics/investigation/complexity/tests/om.bgf.baseline new file mode 100644 index 00000000..f8a0fa97 --- /dev/null +++ b/topics/investigation/complexity/tests/om.bgf.baseline @@ -0,0 +1,3 @@ +9 +1.60 +2992.59 diff --git a/topics/investigation/complexity/tests/read1.bgf.baseline b/topics/investigation/complexity/tests/read1.bgf.baseline new file mode 100644 index 00000000..f303e901 --- /dev/null +++ b/topics/investigation/complexity/tests/read1.bgf.baseline @@ -0,0 +1,3 @@ +45 +3.96 +148307.20 diff --git a/topics/investigation/complexity/tests/read2.bgf.baseline b/topics/investigation/complexity/tests/read2.bgf.baseline new file mode 100644 index 00000000..7f83d373 --- /dev/null +++ b/topics/investigation/complexity/tests/read2.bgf.baseline @@ -0,0 +1,3 @@ +58 +4.22 +176882.01 diff --git a/topics/investigation/complexity/tests/read3.bgf.baseline b/topics/investigation/complexity/tests/read3.bgf.baseline new file mode 100644 index 00000000..1745a238 --- /dev/null +++ b/topics/investigation/complexity/tests/read3.bgf.baseline @@ -0,0 +1,3 @@ +92 +4.28 +258577.76 diff --git a/topics/investigation/complexity/tests/sdf.bgf.baseline b/topics/investigation/complexity/tests/sdf.bgf.baseline new file mode 100644 index 00000000..754bf520 --- /dev/null +++ b/topics/investigation/complexity/tests/sdf.bgf.baseline @@ -0,0 +1,3 @@ +4 +3.57 +2238.48 diff --git a/topics/investigation/complexity/tests/txl.bgf.baseline b/topics/investigation/complexity/tests/txl.bgf.baseline new file mode 100644 index 00000000..73d048b2 --- /dev/null +++ b/topics/investigation/complexity/tests/txl.bgf.baseline @@ -0,0 +1,3 @@ +10 +3.57 +1363.13 diff --git a/topics/investigation/complexity/tests/xml.bgf.baseline b/topics/investigation/complexity/tests/xml.bgf.baseline new file mode 100644 index 00000000..a99bb91b --- /dev/null +++ b/topics/investigation/complexity/tests/xml.bgf.baseline @@ -0,0 +1,3 @@ +9 +2.00 +3270.97 diff --git a/topics/investigation/complexity/tests/xsd.bgf.baseline b/topics/investigation/complexity/tests/xsd.bgf.baseline new file mode 100644 index 00000000..a99bb91b --- /dev/null +++ b/topics/investigation/complexity/tests/xsd.bgf.baseline @@ -0,0 +1,3 @@ +9 +2.00 +3270.97 diff --git a/topics/investigation/size/bottom.py b/topics/investigation/size/bottom.py new file mode 100755 index 00000000..442fe726 --- /dev/null +++ b/topics/investigation/size/bottom.py @@ -0,0 +1,24 @@ +#!/usr/local/bin/python +# -*- coding: utf-8 -*- +import sys +sys.path.append('../../../shared/python') +import BGF +import defined +import used + +if __name__ == "__main__": + if len(sys.argv) != 2: + print 'This tool calculates a BOTTOM metric for any given BGF grammar.' + print 'Usage:' + print ' '+sys.argv[0]+' ' + sys.exit(1) + bgf = BGF.Grammar() + bgf.parse(sys.argv[1]) + bottoms = [] + definednts = defined.defined(bgf) + for nt in used.used(bgf): + if nt not in definednts: + bottoms.append(nt) + #print 'BOTTOM =',len(bottoms) + print len(bottoms) + sys.exit(0) diff --git a/topics/investigation/size/defined.py b/topics/investigation/size/defined.py new file mode 100755 index 00000000..6b805213 --- /dev/null +++ b/topics/investigation/size/defined.py @@ -0,0 +1,24 @@ +#!/usr/local/bin/python +# -*- coding: utf-8 -*- +import sys +sys.path.append('../../../shared/python') +import BGF + +def defined(g): + nts = [] + for p in g.prods: + if p.nt not in nts: + nts.append(p.nt) + return nts + +if __name__ == "__main__": + if len(sys.argv) != 2: + print 'This tool calculates a DEFINED metric for any given BGF grammar.' + print 'Usage:' + print ' '+sys.argv[0]+' ' + sys.exit(1) + bgf = BGF.Grammar() + bgf.parse(sys.argv[1]) + #print 'DEFINED =',len(defined(bgf)) + print len(defined(bgf)) + sys.exit(0) diff --git a/topics/investigation/size/term.py b/topics/investigation/size/term.py index 5c018b7c..776aa979 100755 --- a/topics/investigation/size/term.py +++ b/topics/investigation/size/term.py @@ -4,6 +4,14 @@ sys.path.append('../../../shared/python') import BGF +def term(g): + ts = [] + for p in g.prods: + for n in p.expr.wrapped.getXml().findall('.//terminal'): + if n.text not in ts: + ts.append(n.text) + return ts + if __name__ == "__main__": if len(sys.argv) != 2: print 'This tool calculates a TERM metric for any given BGF grammar.' @@ -12,11 +20,6 @@ sys.exit(1) bgf = BGF.Grammar() bgf.parse(sys.argv[1]) - term = [] - for p in bgf.prods: - for n in p.expr.wrapped.getXml().findall('.//terminal'): - if n.text not in term: - term.append(n.text) #print 'TERM =',len(term) - print len(term) + print len(term(bgf)) sys.exit(0) diff --git a/topics/investigation/size/testperform b/topics/investigation/size/testperform index 32015229..c506488e 100755 --- a/topics/investigation/size/testperform +++ b/topics/investigation/size/testperform @@ -1,8 +1,10 @@ #!/bin/sh echo [Test Case] `basename $1` +./term.py $1 >> $1.out || exit -1 +./var.py $1 >> $1.out || exit -1 +./top.py $1 >> $1.out || exit -1 +./bottom.py $1 >> $1.out || exit -1 ./prod.py $1 > $1.out || exit -1 ./bprod.py $1 >> $1.out || exit -1 -./var.py $1 >> $1.out || exit -1 -./term.py $1 >> $1.out || exit -1 diff $1.out $1.baseline || exit -1 diff --git a/topics/investigation/size/tests/antlr.bgf.baseline b/topics/investigation/size/tests/antlr.bgf.baseline index bb7b1d79..bdf281c4 100644 --- a/topics/investigation/size/tests/antlr.bgf.baseline +++ b/topics/investigation/size/tests/antlr.bgf.baseline @@ -1,4 +1,2 @@ 14 8 -11 -9 diff --git a/topics/investigation/size/tests/dcg.bgf.baseline b/topics/investigation/size/tests/dcg.bgf.baseline index d3e138f9..47e32061 100644 --- a/topics/investigation/size/tests/dcg.bgf.baseline +++ b/topics/investigation/size/tests/dcg.bgf.baseline @@ -1,4 +1,2 @@ 11 11 -8 -9 diff --git a/topics/investigation/size/tests/ecore.bgf.baseline b/topics/investigation/size/tests/ecore.bgf.baseline index 0215344c..afc8341c 100644 --- a/topics/investigation/size/tests/ecore.bgf.baseline +++ b/topics/investigation/size/tests/ecore.bgf.baseline @@ -1,4 +1,2 @@ 18 12 -12 -0 diff --git a/topics/investigation/size/tests/ecore2.bgf.baseline b/topics/investigation/size/tests/ecore2.bgf.baseline index e2402886..3cf64aa1 100644 --- a/topics/investigation/size/tests/ecore2.bgf.baseline +++ b/topics/investigation/size/tests/ecore2.bgf.baseline @@ -1,4 +1,2 @@ 15 9 -9 -0 diff --git a/topics/investigation/size/tests/fl_ldf.bgf.baseline b/topics/investigation/size/tests/fl_ldf.bgf.baseline index 37964881..51993f07 100644 --- a/topics/investigation/size/tests/fl_ldf.bgf.baseline +++ b/topics/investigation/size/tests/fl_ldf.bgf.baseline @@ -1,4 +1,2 @@ 2 2 -5 -1 diff --git a/topics/investigation/size/tests/impl1.bgf.baseline b/topics/investigation/size/tests/impl1.bgf.baseline index 06fad415..4c3f501d 100644 --- a/topics/investigation/size/tests/impl1.bgf.baseline +++ b/topics/investigation/size/tests/impl1.bgf.baseline @@ -1,4 +1,2 @@ 282 282 -142 -91 diff --git a/topics/investigation/size/tests/impl2.bgf.baseline b/topics/investigation/size/tests/impl2.bgf.baseline index 0959fd24..972dde54 100644 --- a/topics/investigation/size/tests/impl2.bgf.baseline +++ b/topics/investigation/size/tests/impl2.bgf.baseline @@ -1,4 +1,2 @@ 185 185 -91 -92 diff --git a/topics/investigation/size/tests/impl3.bgf.baseline b/topics/investigation/size/tests/impl3.bgf.baseline index b9194bf7..87e4258d 100644 --- a/topics/investigation/size/tests/impl3.bgf.baseline +++ b/topics/investigation/size/tests/impl3.bgf.baseline @@ -1,4 +1,2 @@ 245 245 -126 -96 diff --git a/topics/investigation/size/tests/jaxb.bgf.baseline b/topics/investigation/size/tests/jaxb.bgf.baseline index 2c796297..eaa47c94 100644 --- a/topics/investigation/size/tests/jaxb.bgf.baseline +++ b/topics/investigation/size/tests/jaxb.bgf.baseline @@ -1,4 +1,2 @@ 17 11 -11 -0 diff --git a/topics/investigation/size/tests/ldf.bgf.baseline b/topics/investigation/size/tests/ldf.bgf.baseline index 37964881..51993f07 100644 --- a/topics/investigation/size/tests/ldf.bgf.baseline +++ b/topics/investigation/size/tests/ldf.bgf.baseline @@ -1,4 +1,2 @@ 2 2 -5 -1 diff --git a/topics/investigation/size/tests/om.bgf.baseline b/topics/investigation/size/tests/om.bgf.baseline index aa3b1cbb..8ebdcc76 100644 --- a/topics/investigation/size/tests/om.bgf.baseline +++ b/topics/investigation/size/tests/om.bgf.baseline @@ -1,4 +1,2 @@ 16 10 -10 -0 diff --git a/topics/investigation/size/tests/read1.bgf.baseline b/topics/investigation/size/tests/read1.bgf.baseline index 0b1b9f86..1fc73e9a 100644 --- a/topics/investigation/size/tests/read1.bgf.baseline +++ b/topics/investigation/size/tests/read1.bgf.baseline @@ -1,4 +1,2 @@ 315 315 -157 -91 diff --git a/topics/investigation/size/tests/read2.bgf.baseline b/topics/investigation/size/tests/read2.bgf.baseline index fbe26159..fc659f0f 100644 --- a/topics/investigation/size/tests/read2.bgf.baseline +++ b/topics/investigation/size/tests/read2.bgf.baseline @@ -1,4 +1,2 @@ 346 346 -162 -93 diff --git a/topics/investigation/size/tests/read3.bgf.baseline b/topics/investigation/size/tests/read3.bgf.baseline index ce3c3088..905127e4 100644 --- a/topics/investigation/size/tests/read3.bgf.baseline +++ b/topics/investigation/size/tests/read3.bgf.baseline @@ -1,4 +1,2 @@ 435 435 -211 -97 diff --git a/topics/investigation/size/tests/sdf.bgf.baseline b/topics/investigation/size/tests/sdf.bgf.baseline index 302e84d4..47e32061 100644 --- a/topics/investigation/size/tests/sdf.bgf.baseline +++ b/topics/investigation/size/tests/sdf.bgf.baseline @@ -1,4 +1,2 @@ 11 11 -7 -9 diff --git a/topics/investigation/size/tests/txl.bgf.baseline b/topics/investigation/size/tests/txl.bgf.baseline index c20bbf89..dfa5ffdc 100644 --- a/topics/investigation/size/tests/txl.bgf.baseline +++ b/topics/investigation/size/tests/txl.bgf.baseline @@ -1,4 +1,2 @@ 11 4 -7 -9 diff --git a/topics/investigation/size/tests/xml.bgf.baseline b/topics/investigation/size/tests/xml.bgf.baseline index aa3b1cbb..8ebdcc76 100644 --- a/topics/investigation/size/tests/xml.bgf.baseline +++ b/topics/investigation/size/tests/xml.bgf.baseline @@ -1,4 +1,2 @@ 16 10 -10 -0 diff --git a/topics/investigation/size/tests/xsd.bgf.baseline b/topics/investigation/size/tests/xsd.bgf.baseline index aa3b1cbb..8ebdcc76 100644 --- a/topics/investigation/size/tests/xsd.bgf.baseline +++ b/topics/investigation/size/tests/xsd.bgf.baseline @@ -1,4 +1,2 @@ 16 10 -10 -0 diff --git a/topics/investigation/size/top.py b/topics/investigation/size/top.py new file mode 100755 index 00000000..06add700 --- /dev/null +++ b/topics/investigation/size/top.py @@ -0,0 +1,24 @@ +#!/usr/local/bin/python +# -*- coding: utf-8 -*- +import sys +sys.path.append('../../../shared/python') +import BGF +import defined +import used + +if __name__ == "__main__": + if len(sys.argv) != 2: + print 'This tool calculates a TOP metric for any given BGF grammar.' + print 'Usage:' + print ' '+sys.argv[0]+' ' + sys.exit(1) + bgf = BGF.Grammar() + bgf.parse(sys.argv[1]) + tops = [] + usednts = used.used(bgf) + for nt in defined.defined(bgf): + if nt not in usednts: + tops.append(nt) + #print 'TOP =',len(tops) + print len(tops) + sys.exit(0) diff --git a/topics/investigation/size/used.py b/topics/investigation/size/used.py new file mode 100755 index 00000000..46eafe08 --- /dev/null +++ b/topics/investigation/size/used.py @@ -0,0 +1,25 @@ +#!/usr/local/bin/python +# -*- coding: utf-8 -*- +import sys +sys.path.append('../../../shared/python') +import BGF + +def used(g): + nts = [] + for p in g.prods: + for n in p.expr.wrapped.getXml().findall('.//nonterminal'): + if n.text not in nts: + nts.append(n.text) + return nts + +if __name__ == "__main__": + if len(sys.argv) != 2: + print 'This tool calculates a USED metric for any given BGF grammar.' + print 'Usage:' + print ' '+sys.argv[0]+' ' + sys.exit(1) + bgf = BGF.Grammar() + bgf.parse(sys.argv[1]) + #print 'USED =',len(used(bgf)) + print len(used(bgf)) + sys.exit(0) diff --git a/topics/investigation/size/var.py b/topics/investigation/size/var.py index 07d6960b..b33a7c1c 100755 --- a/topics/investigation/size/var.py +++ b/topics/investigation/size/var.py @@ -4,6 +4,16 @@ sys.path.append('../../../shared/python') import BGF +def var(g): + nts = [] + for p in g.prods: + if p.nt not in nts: + nts.append(p.nt) + for n in p.expr.wrapped.getXml().findall('.//nonterminal'): + if n.text not in nts: + nts.append(n.text) + return nts + if __name__ == "__main__": if len(sys.argv) != 2: print 'This tool calculates a VAR metric for any given BGF grammar.' @@ -12,13 +22,6 @@ sys.exit(1) bgf = BGF.Grammar() bgf.parse(sys.argv[1]) - var = [] - for p in bgf.prods: - if p.nt not in var: - var.append(p.nt) - for n in p.expr.wrapped.getXml().findall('.//nonterminal'): - if n.text not in var: - var.append(n.text) #print 'VAR =',len(var) - print len(var) + print len(var(bgf)) sys.exit(0)