From 196bbda8f862fc2ac2c3671367604e0b624b9d33 Mon Sep 17 00:00:00 2001 From: grammarware Date: Tue, 1 Feb 2011 16:59:50 +0000 Subject: [PATCH] presentation -> investigation; LEV in Python git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@929 ab42f6e0-554d-0410-b580-99e487e6eeb2 --- topics/export/ebnf/export.py | 2 +- topics/investigation/lev/Makefile | 7 +++ topics/investigation/lev/levels.py | 56 +++++++++++++++++++ topics/investigation/lev/testperform | 5 ++ .../lev/tests/antlr.bgf.baseline | 1 + .../investigation/lev/tests/dcg.bgf.baseline | 1 + .../lev/tests/ecore.bgf.baseline | 1 + .../lev/tests/ecore2.bgf.baseline | 1 + .../lev/tests/fl_ldf.bgf.baseline | 1 + .../lev/tests/impl1.bgf.baseline | 1 + .../lev/tests/impl2.bgf.baseline | 1 + .../lev/tests/impl3.bgf.baseline | 1 + .../investigation/lev/tests/jaxb.bgf.baseline | 1 + .../investigation/lev/tests/ldf.bgf.baseline | 1 + .../investigation/lev/tests/om.bgf.baseline | 1 + .../lev/tests/read1.bgf.baseline | 1 + .../lev/tests/read2.bgf.baseline | 1 + .../lev/tests/read3.bgf.baseline | 1 + .../investigation/lev/tests/sdf.bgf.baseline | 1 + .../investigation/lev/tests/txl.bgf.baseline | 1 + .../investigation/lev/tests/xml.bgf.baseline | 1 + .../investigation/lev/tests/xsd.bgf.baseline | 1 + .../metrics/Makefile | 0 .../metrics/bgf-overview.xslt | 0 .../metrics/bottom.xpath | 0 .../metrics/listbottoms.xpath | 0 .../metrics/listtops.xpath | 0 .../metrics/nonterminals.xpath | 0 .../metrics/perxbgfcommand.xq | 0 .../metrics/productions.xpath | 0 .../metrics/top.xpath | 0 .../metrics/transformations.xpath | 0 .../subgrammar/Makefile | 0 .../subgrammar/subgrammar.py | 0 .../subgrammar/testperform | 0 .../subgrammar/tests/Apply.baseline.bgf | 0 .../subgrammar/tests/Argument.baseline.bgf | 0 .../subgrammar/tests/Binary.baseline.bgf | 0 .../subgrammar/tests/Expr.baseline.bgf | 0 .../subgrammar/tests/Fragment.baseline.bgf | 0 .../subgrammar/tests/Function.baseline.bgf | 0 .../subgrammar/tests/IfThenElse.baseline.bgf | 0 .../subgrammar/tests/Literal.baseline.bgf | 0 .../subgrammar/tests/Ops.baseline.bgf | 0 .../subgrammar/tests/Program.baseline.bgf | 0 45 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 topics/investigation/lev/Makefile create mode 100755 topics/investigation/lev/levels.py create mode 100755 topics/investigation/lev/testperform create mode 100644 topics/investigation/lev/tests/antlr.bgf.baseline create mode 100644 topics/investigation/lev/tests/dcg.bgf.baseline create mode 100644 topics/investigation/lev/tests/ecore.bgf.baseline create mode 100644 topics/investigation/lev/tests/ecore2.bgf.baseline create mode 100644 topics/investigation/lev/tests/fl_ldf.bgf.baseline create mode 100644 topics/investigation/lev/tests/impl1.bgf.baseline create mode 100644 topics/investigation/lev/tests/impl2.bgf.baseline create mode 100644 topics/investigation/lev/tests/impl3.bgf.baseline create mode 100644 topics/investigation/lev/tests/jaxb.bgf.baseline create mode 100644 topics/investigation/lev/tests/ldf.bgf.baseline create mode 100644 topics/investigation/lev/tests/om.bgf.baseline create mode 100644 topics/investigation/lev/tests/read1.bgf.baseline create mode 100644 topics/investigation/lev/tests/read2.bgf.baseline create mode 100644 topics/investigation/lev/tests/read3.bgf.baseline create mode 100644 topics/investigation/lev/tests/sdf.bgf.baseline create mode 100644 topics/investigation/lev/tests/txl.bgf.baseline create mode 100644 topics/investigation/lev/tests/xml.bgf.baseline create mode 100644 topics/investigation/lev/tests/xsd.bgf.baseline rename topics/{presentation => investigation}/metrics/Makefile (100%) rename topics/{presentation => investigation}/metrics/bgf-overview.xslt (100%) rename topics/{presentation => investigation}/metrics/bottom.xpath (100%) rename topics/{presentation => investigation}/metrics/listbottoms.xpath (100%) rename topics/{presentation => investigation}/metrics/listtops.xpath (100%) rename topics/{presentation => investigation}/metrics/nonterminals.xpath (100%) rename topics/{presentation => investigation}/metrics/perxbgfcommand.xq (100%) rename topics/{presentation => investigation}/metrics/productions.xpath (100%) rename topics/{presentation => investigation}/metrics/top.xpath (100%) rename topics/{presentation => investigation}/metrics/transformations.xpath (100%) rename topics/{presentation => investigation}/subgrammar/Makefile (100%) rename topics/{presentation => investigation}/subgrammar/subgrammar.py (100%) rename topics/{presentation => investigation}/subgrammar/testperform (100%) rename topics/{presentation => investigation}/subgrammar/tests/Apply.baseline.bgf (100%) rename topics/{presentation => investigation}/subgrammar/tests/Argument.baseline.bgf (100%) rename topics/{presentation => investigation}/subgrammar/tests/Binary.baseline.bgf (100%) rename topics/{presentation => investigation}/subgrammar/tests/Expr.baseline.bgf (100%) rename topics/{presentation => investigation}/subgrammar/tests/Fragment.baseline.bgf (100%) rename topics/{presentation => investigation}/subgrammar/tests/Function.baseline.bgf (100%) rename topics/{presentation => investigation}/subgrammar/tests/IfThenElse.baseline.bgf (100%) rename topics/{presentation => investigation}/subgrammar/tests/Literal.baseline.bgf (100%) rename topics/{presentation => investigation}/subgrammar/tests/Ops.baseline.bgf (100%) rename topics/{presentation => investigation}/subgrammar/tests/Program.baseline.bgf (100%) diff --git a/topics/export/ebnf/export.py b/topics/export/ebnf/export.py index 10a26ebd..fc3b469f 100755 --- a/topics/export/ebnf/export.py +++ b/topics/export/ebnf/export.py @@ -8,7 +8,7 @@ if __name__ == "__main__": if len(sys.argv) != 3: - print 'This tool extracts a Rascal grammar.' + print 'This tool generates a BNF representation for any given BGF grammar.' print 'Usage:' print ' bgf2bnf ' sys.exit(1) diff --git a/topics/investigation/lev/Makefile b/topics/investigation/lev/Makefile new file mode 100644 index 00000000..1984db02 --- /dev/null +++ b/topics/investigation/lev/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/lev/levels.py b/topics/investigation/lev/levels.py new file mode 100755 index 00000000..3363306b --- /dev/null +++ b/topics/investigation/lev/levels.py @@ -0,0 +1,56 @@ +#!/usr/local/bin/python +# -*- coding: utf-8 -*- +import os +import sys +sys.path.append('../../../shared/python') +import slpsns +import BGF +import elementtree.ElementTree as ET + +calls = {} + +if __name__ == "__main__": + # |>* + if len(sys.argv) != 2: + #print 'This tool generates a BNF representation for any given BGF grammar.' + print 'Usage:' + print ' bgf2bnf ' + sys.exit(1) + bgf = BGF.Grammar() + bgf.parse(sys.argv[1]) + for p in bgf.prods: + if p.nt not in calls.keys(): + calls[p.nt] = [] + for n in p.expr.wrapped.getXml().findall('.//nonterminal'): + if n.text not in calls[p.nt]: + calls[p.nt].append(n.text) + #for n in calls.keys(): + # print n,'▻',calls[n] + #print '--------------------' + for n in calls.keys(): + for x in calls[n]: + if x not in calls.keys(): + calls[x] = [] + for y in calls[x]: + if y not in calls[n]: + calls[n].append(y) + calls[n].sort() + #for n in calls.keys(): + # print n,'▻*',calls[n] + #print '--------------------' + unassigned = calls.keys() + levels = [] + while len(unassigned)>0: + nt = unassigned[0] + levels.append([]) + levels[-1].append(nt) + unassigned = unassigned[1:] + for n in calls[nt]: + if nt in calls[n]: + levels[-1].append(n) + if n in unassigned: + unassigned.remove(n) + print 'LEV =',len(levels) + #for l in levels: + # print l + sys.exit(0) diff --git a/topics/investigation/lev/testperform b/topics/investigation/lev/testperform new file mode 100755 index 00000000..8ecb3a3a --- /dev/null +++ b/topics/investigation/lev/testperform @@ -0,0 +1,5 @@ +#!/bin/sh + +echo [Test Case] `basename $1` +./levels.py $1 > $1.out || exit -1 +diff $1.out $1.baseline diff --git a/topics/investigation/lev/tests/antlr.bgf.baseline b/topics/investigation/lev/tests/antlr.bgf.baseline new file mode 100644 index 00000000..b70e0965 --- /dev/null +++ b/topics/investigation/lev/tests/antlr.bgf.baseline @@ -0,0 +1 @@ +LEV = 7 diff --git a/topics/investigation/lev/tests/dcg.bgf.baseline b/topics/investigation/lev/tests/dcg.bgf.baseline new file mode 100644 index 00000000..b70e0965 --- /dev/null +++ b/topics/investigation/lev/tests/dcg.bgf.baseline @@ -0,0 +1 @@ +LEV = 7 diff --git a/topics/investigation/lev/tests/ecore.bgf.baseline b/topics/investigation/lev/tests/ecore.bgf.baseline new file mode 100644 index 00000000..5e939361 --- /dev/null +++ b/topics/investigation/lev/tests/ecore.bgf.baseline @@ -0,0 +1 @@ +LEV = 5 diff --git a/topics/investigation/lev/tests/ecore2.bgf.baseline b/topics/investigation/lev/tests/ecore2.bgf.baseline new file mode 100644 index 00000000..2ae052cd --- /dev/null +++ b/topics/investigation/lev/tests/ecore2.bgf.baseline @@ -0,0 +1 @@ +LEV = 6 diff --git a/topics/investigation/lev/tests/fl_ldf.bgf.baseline b/topics/investigation/lev/tests/fl_ldf.bgf.baseline new file mode 100644 index 00000000..5e939361 --- /dev/null +++ b/topics/investigation/lev/tests/fl_ldf.bgf.baseline @@ -0,0 +1 @@ +LEV = 5 diff --git a/topics/investigation/lev/tests/impl1.bgf.baseline b/topics/investigation/lev/tests/impl1.bgf.baseline new file mode 100644 index 00000000..d15e1b7a --- /dev/null +++ b/topics/investigation/lev/tests/impl1.bgf.baseline @@ -0,0 +1 @@ +LEV = 83 diff --git a/topics/investigation/lev/tests/impl2.bgf.baseline b/topics/investigation/lev/tests/impl2.bgf.baseline new file mode 100644 index 00000000..acff1995 --- /dev/null +++ b/topics/investigation/lev/tests/impl2.bgf.baseline @@ -0,0 +1 @@ +LEV = 41 diff --git a/topics/investigation/lev/tests/impl3.bgf.baseline b/topics/investigation/lev/tests/impl3.bgf.baseline new file mode 100644 index 00000000..5b4ee1d0 --- /dev/null +++ b/topics/investigation/lev/tests/impl3.bgf.baseline @@ -0,0 +1 @@ +LEV = 35 diff --git a/topics/investigation/lev/tests/jaxb.bgf.baseline b/topics/investigation/lev/tests/jaxb.bgf.baseline new file mode 100644 index 00000000..8629ba2a --- /dev/null +++ b/topics/investigation/lev/tests/jaxb.bgf.baseline @@ -0,0 +1 @@ +LEV = 9 diff --git a/topics/investigation/lev/tests/ldf.bgf.baseline b/topics/investigation/lev/tests/ldf.bgf.baseline new file mode 100644 index 00000000..5e939361 --- /dev/null +++ b/topics/investigation/lev/tests/ldf.bgf.baseline @@ -0,0 +1 @@ +LEV = 5 diff --git a/topics/investigation/lev/tests/om.bgf.baseline b/topics/investigation/lev/tests/om.bgf.baseline new file mode 100644 index 00000000..c465089c --- /dev/null +++ b/topics/investigation/lev/tests/om.bgf.baseline @@ -0,0 +1 @@ +LEV = 8 diff --git a/topics/investigation/lev/tests/read1.bgf.baseline b/topics/investigation/lev/tests/read1.bgf.baseline new file mode 100644 index 00000000..6057c6af --- /dev/null +++ b/topics/investigation/lev/tests/read1.bgf.baseline @@ -0,0 +1 @@ +LEV = 97 diff --git a/topics/investigation/lev/tests/read2.bgf.baseline b/topics/investigation/lev/tests/read2.bgf.baseline new file mode 100644 index 00000000..d0bcccd5 --- /dev/null +++ b/topics/investigation/lev/tests/read2.bgf.baseline @@ -0,0 +1 @@ +LEV = 68 diff --git a/topics/investigation/lev/tests/read3.bgf.baseline b/topics/investigation/lev/tests/read3.bgf.baseline new file mode 100644 index 00000000..12eb7a1a --- /dev/null +++ b/topics/investigation/lev/tests/read3.bgf.baseline @@ -0,0 +1 @@ +LEV = 75 diff --git a/topics/investigation/lev/tests/sdf.bgf.baseline b/topics/investigation/lev/tests/sdf.bgf.baseline new file mode 100644 index 00000000..b70e0965 --- /dev/null +++ b/topics/investigation/lev/tests/sdf.bgf.baseline @@ -0,0 +1 @@ +LEV = 7 diff --git a/topics/investigation/lev/tests/txl.bgf.baseline b/topics/investigation/lev/tests/txl.bgf.baseline new file mode 100644 index 00000000..b70e0965 --- /dev/null +++ b/topics/investigation/lev/tests/txl.bgf.baseline @@ -0,0 +1 @@ +LEV = 7 diff --git a/topics/investigation/lev/tests/xml.bgf.baseline b/topics/investigation/lev/tests/xml.bgf.baseline new file mode 100644 index 00000000..b70e0965 --- /dev/null +++ b/topics/investigation/lev/tests/xml.bgf.baseline @@ -0,0 +1 @@ +LEV = 7 diff --git a/topics/investigation/lev/tests/xsd.bgf.baseline b/topics/investigation/lev/tests/xsd.bgf.baseline new file mode 100644 index 00000000..b70e0965 --- /dev/null +++ b/topics/investigation/lev/tests/xsd.bgf.baseline @@ -0,0 +1 @@ +LEV = 7 diff --git a/topics/presentation/metrics/Makefile b/topics/investigation/metrics/Makefile similarity index 100% rename from topics/presentation/metrics/Makefile rename to topics/investigation/metrics/Makefile diff --git a/topics/presentation/metrics/bgf-overview.xslt b/topics/investigation/metrics/bgf-overview.xslt similarity index 100% rename from topics/presentation/metrics/bgf-overview.xslt rename to topics/investigation/metrics/bgf-overview.xslt diff --git a/topics/presentation/metrics/bottom.xpath b/topics/investigation/metrics/bottom.xpath similarity index 100% rename from topics/presentation/metrics/bottom.xpath rename to topics/investigation/metrics/bottom.xpath diff --git a/topics/presentation/metrics/listbottoms.xpath b/topics/investigation/metrics/listbottoms.xpath similarity index 100% rename from topics/presentation/metrics/listbottoms.xpath rename to topics/investigation/metrics/listbottoms.xpath diff --git a/topics/presentation/metrics/listtops.xpath b/topics/investigation/metrics/listtops.xpath similarity index 100% rename from topics/presentation/metrics/listtops.xpath rename to topics/investigation/metrics/listtops.xpath diff --git a/topics/presentation/metrics/nonterminals.xpath b/topics/investigation/metrics/nonterminals.xpath similarity index 100% rename from topics/presentation/metrics/nonterminals.xpath rename to topics/investigation/metrics/nonterminals.xpath diff --git a/topics/presentation/metrics/perxbgfcommand.xq b/topics/investigation/metrics/perxbgfcommand.xq similarity index 100% rename from topics/presentation/metrics/perxbgfcommand.xq rename to topics/investigation/metrics/perxbgfcommand.xq diff --git a/topics/presentation/metrics/productions.xpath b/topics/investigation/metrics/productions.xpath similarity index 100% rename from topics/presentation/metrics/productions.xpath rename to topics/investigation/metrics/productions.xpath diff --git a/topics/presentation/metrics/top.xpath b/topics/investigation/metrics/top.xpath similarity index 100% rename from topics/presentation/metrics/top.xpath rename to topics/investigation/metrics/top.xpath diff --git a/topics/presentation/metrics/transformations.xpath b/topics/investigation/metrics/transformations.xpath similarity index 100% rename from topics/presentation/metrics/transformations.xpath rename to topics/investigation/metrics/transformations.xpath diff --git a/topics/presentation/subgrammar/Makefile b/topics/investigation/subgrammar/Makefile similarity index 100% rename from topics/presentation/subgrammar/Makefile rename to topics/investigation/subgrammar/Makefile diff --git a/topics/presentation/subgrammar/subgrammar.py b/topics/investigation/subgrammar/subgrammar.py similarity index 100% rename from topics/presentation/subgrammar/subgrammar.py rename to topics/investigation/subgrammar/subgrammar.py diff --git a/topics/presentation/subgrammar/testperform b/topics/investigation/subgrammar/testperform similarity index 100% rename from topics/presentation/subgrammar/testperform rename to topics/investigation/subgrammar/testperform diff --git a/topics/presentation/subgrammar/tests/Apply.baseline.bgf b/topics/investigation/subgrammar/tests/Apply.baseline.bgf similarity index 100% rename from topics/presentation/subgrammar/tests/Apply.baseline.bgf rename to topics/investigation/subgrammar/tests/Apply.baseline.bgf diff --git a/topics/presentation/subgrammar/tests/Argument.baseline.bgf b/topics/investigation/subgrammar/tests/Argument.baseline.bgf similarity index 100% rename from topics/presentation/subgrammar/tests/Argument.baseline.bgf rename to topics/investigation/subgrammar/tests/Argument.baseline.bgf diff --git a/topics/presentation/subgrammar/tests/Binary.baseline.bgf b/topics/investigation/subgrammar/tests/Binary.baseline.bgf similarity index 100% rename from topics/presentation/subgrammar/tests/Binary.baseline.bgf rename to topics/investigation/subgrammar/tests/Binary.baseline.bgf diff --git a/topics/presentation/subgrammar/tests/Expr.baseline.bgf b/topics/investigation/subgrammar/tests/Expr.baseline.bgf similarity index 100% rename from topics/presentation/subgrammar/tests/Expr.baseline.bgf rename to topics/investigation/subgrammar/tests/Expr.baseline.bgf diff --git a/topics/presentation/subgrammar/tests/Fragment.baseline.bgf b/topics/investigation/subgrammar/tests/Fragment.baseline.bgf similarity index 100% rename from topics/presentation/subgrammar/tests/Fragment.baseline.bgf rename to topics/investigation/subgrammar/tests/Fragment.baseline.bgf diff --git a/topics/presentation/subgrammar/tests/Function.baseline.bgf b/topics/investigation/subgrammar/tests/Function.baseline.bgf similarity index 100% rename from topics/presentation/subgrammar/tests/Function.baseline.bgf rename to topics/investigation/subgrammar/tests/Function.baseline.bgf diff --git a/topics/presentation/subgrammar/tests/IfThenElse.baseline.bgf b/topics/investigation/subgrammar/tests/IfThenElse.baseline.bgf similarity index 100% rename from topics/presentation/subgrammar/tests/IfThenElse.baseline.bgf rename to topics/investigation/subgrammar/tests/IfThenElse.baseline.bgf diff --git a/topics/presentation/subgrammar/tests/Literal.baseline.bgf b/topics/investigation/subgrammar/tests/Literal.baseline.bgf similarity index 100% rename from topics/presentation/subgrammar/tests/Literal.baseline.bgf rename to topics/investigation/subgrammar/tests/Literal.baseline.bgf diff --git a/topics/presentation/subgrammar/tests/Ops.baseline.bgf b/topics/investigation/subgrammar/tests/Ops.baseline.bgf similarity index 100% rename from topics/presentation/subgrammar/tests/Ops.baseline.bgf rename to topics/investigation/subgrammar/tests/Ops.baseline.bgf diff --git a/topics/presentation/subgrammar/tests/Program.baseline.bgf b/topics/investigation/subgrammar/tests/Program.baseline.bgf similarity index 100% rename from topics/presentation/subgrammar/tests/Program.baseline.bgf rename to topics/investigation/subgrammar/tests/Program.baseline.bgf