diff --git a/shared/rascal/src/analyse/Layers.rsc b/shared/rascal/src/analyse/Layers.rsc new file mode 100644 index 00000000..1a72f7c5 --- /dev/null +++ b/shared/rascal/src/analyse/Layers.rsc @@ -0,0 +1,61 @@ +@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI} +module analyse::Layers + +import syntax::BGF; +import syntax::XBGF; +import io::ReadBGF; +import lib::Rascalware; +import analyse::Metrics; +import normal::BGF; +import transform::XBGF; +import export::BNF; +import Relation; + +rel[str,str] detectLayers(BGFGrammar g) +{ + rel[str,str] res = {}; + rel[str,str] dres = {}; + for (n1 <- definedNs(g), n2 <- definedNs(g)) + { + BGFProdList ps1 = prodsOfN(n1,g.prods); + BGFProdList ps2 = prodsOfN(n2,g.prods); + // n2 chains to n1, but not exclusively + if ( + /p:production(_,n2,nonterminal(n1)) := ps2 + && !isEmpty(ps2 - p) + ) + res += ; + if ( + /production(_,n2,choice([*L1,nonterminal(n1),*L2])) := ps2 + && !isEmpty(L1+L2) + ) + res += ; + + for ( <- res) + if (/production(_,n1,e) := ps1 && /nonterminal(n2) := e && n1!=n2) + dres += ; + } + return dres; +} + +public void main() +{ + for (src <- ["antlr","dcg","ecore","emf","jaxb","om","python","rascal-a","rascal-c","sdf","txl","xsd"]) + //for (src <- ["python"]) + { + println("Reading ..."); + BGFGrammar g = readBGF(|home:///projects/slps/topics/convergence/guided/bgf/.bgf|); + println("Normalising ..."); + g = visit(g) + { + case selectable(s,e) => e + case terminal(_) => epsilon() + } + for (n <- [n | n <- usedNs(g), len(prodsOfN(n,g.prods))==1, len([n | /nonterminal(n) := g])==1]) + g = transform([inline(n)],g); + println("Analysing ..."); + rel[str,str] layers = detectLayers(g); + if(!isEmpty(layers)) + println("Found "); + } +} \ No newline at end of file