Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deLayering is implemented as a grammar analysis
- Loading branch information
1 parent
be4cd69
commit f974d30
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 += <n1,n2>; | ||
if ( | ||
/production(_,n2,choice([*L1,nonterminal(n1),*L2])) := ps2 | ||
&& !isEmpty(L1+L2) | ||
) | ||
res += <n1,n2>; | ||
|
||
for (<n1,n2> <- res) | ||
if (/production(_,n1,e) := ps1 && /nonterminal(n2) := e && n1!=n2) | ||
dres += <n1,n2>; | ||
} | ||
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 <src>..."); | ||
BGFGrammar g = readBGF(|home:///projects/slps/topics/convergence/guided/bgf/<src>.bgf|); | ||
println("Normalising <src>..."); | ||
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 <src>..."); | ||
rel[str,str] layers = detectLayers(g); | ||
if(!isEmpty(layers)) | ||
println("Found <layers>"); | ||
} | ||
} |