Skip to content

Commit

Permalink
very concise implementation of {p◇q}
Browse files Browse the repository at this point in the history
  • Loading branch information
grammarware committed Jul 6, 2012
1 parent 9c19872 commit 4e56d92
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
27 changes: 23 additions & 4 deletions shared/rascal/src/analyse/Prodsigs.rsc
Expand Up @@ -75,19 +75,23 @@ default bool weqps(Signature p, Signature q) = geqps(p,q,equivfp,false);
// footprint-comparator-parametrised equivalence
bool geqps(Signature p, Signature q, bool(Footprint,Footprint) cmp, bool strong)// = p == q;
{
println("[?] Checking <pp(p)> and <pp(q)> for <strong?"strong":"weak"> equivalence.");
if (strong && len(p) != len(q)) return false;
for (<n,pi> <- p)
{
bool match = false;
//for(<m,xi> <- q, cmp(pi,xi))
for(<m,xi> <- q, cmp(pi,xi))
if (match)
return false; // multiple matches!
else
{
// TODO: make recursive
println(" [?] <n> == <m> as <pp(pi)>?");
//if (match)
// return false; // multiple matches!
//else
{
match = true;
q -= {<m,xi>};
}
}
if (strong && !match)
return false;
}
Expand All @@ -114,6 +118,21 @@ NameMatch makenamematch(Signature p, Signature q)
return nm;
}

set[NameMatch] makenamematches(BGFExpression e1, BGFExpression e2) = makenamematches(makesig(e1),makesig(e2));
set[NameMatch] makenamematches(BGFProduction p1, BGFProduction p2) = makenamematches(makesig(p1),makesig(p2));
set[NameMatch] makenamematches({}, {}) = {};
set[NameMatch] makenamematches(Signature p, {}) = {{<c,""> | <c,_> <- p}};
set[NameMatch] makenamematches({}, Signature q) = {{<"",c> | <c,_> <- q}};
set[NameMatch] makenamematches(Signature p, Signature q) =
{
*{m + {<a,b>} | m <- makenamematches(domainX(p,{a}), domainX(q,{b}))}
|
<a,pi> <- p, <b,xi> <- q, equivfp(pi,xi)
};


rel[&T,&T] relmult (rel[&T,&T] xs, rel[&T,&T] ys) = {<x,y> | x <- xs, y <- ys};

public str pp(Signature sig) = "\<"+joinStrings(["<n>: <pp(f)>" | <n,f> <- sig],", ")+"\>";
public str pp(fpnt()) = "1";
public str pp(fpopt()) = "?";
Expand Down
11 changes: 8 additions & 3 deletions shared/rascal/src/converge/PureGuided.rsc
Expand Up @@ -20,7 +20,7 @@ import Relation;
list[str] sources =
//["antlr","dcg","ecore","emf","jaxb","om","python","rascal-a","rascal-c","sdf","txl","xsd"];
//["emf","jaxb","om","rascal-c","sdf","xsd"];
["xsd"];
["txl"];
// atom/expr: antlr, dcg
// arg/string: ecore, rascal-a
// good: emf, jaxb, om, rascal-c, sdf, xsd
Expand Down Expand Up @@ -92,7 +92,7 @@ tuple[NameMatch,BGFProdList,BGFProdList]
}
truenm = {};
for (<a,b> <- nm-known)
if ((a==b) && a in domain(known))
if ((a==b) && a in known<0>)
println("Reconfirmed <a>");
else
{
Expand Down Expand Up @@ -121,7 +121,7 @@ tuple[NameMatch,BGFProdList,BGFProdList]
}
truenm = {};
for (<a,b> <- nm-known)
if ((a==b) && a in domain(known))
if ((a==b) && a in known<0>)
println("Reconfirmed <a>");
else
{
Expand Down Expand Up @@ -201,6 +201,11 @@ NameMatch converge(BGFGrammar master, BGFGrammar servant)

public void main()
{
//Signature s1 = {<"a",fpnt()>,<"b",fpnt()>,<"c",fpmany([fpnt(),fpplus()])>,<"z",fpmany([fpnt(),fpplus()])>};
//Signature s2 = {<"x",fpnt()>,<"y",fpmany([fpnt(),fpplus()])>};
//println("\t<pp(s1)>\nvs\n\t<pp(s2)>");
//println("<analyse::Prodsigs::makenamematches(s1,s2)>");
//return;
master = loadSimpleGrammar(|home:///projects/slps/topics/convergence/guided/bgf/master.bgf|);
for (src <- sources)
{
Expand Down
1 change: 1 addition & 0 deletions shared/rascal/src/lib/Rascalware.rsc
Expand Up @@ -21,6 +21,7 @@ public void print(str s) = IO::print(s);
public void println(str s) = IO::println(s);

// joins a list of strings with a separator
public str joinStrings([], _) = "";
public str joinStrings(list[str] ss, str w) = (ss[0] | it + w + s | s <- tail(ss));

//public bool multiseteq(list[&T] xs, list[&T] ys) = sort(xs) == sort(ys);
Expand Down

0 comments on commit 4e56d92

Please sign in to comment.