Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9ef08e
commit d975329
Showing
6 changed files
with
87 additions
and
5 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
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
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,28 @@ | ||
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI} | ||
@wiki{InlineLazy} | ||
module mutate::InlineLazy | ||
|
||
import lib::Rascalware; | ||
import syntax::BGF; | ||
import syntax::XBGF; | ||
import transform::library::Util; | ||
import transform::XBGF; | ||
import diff::GDT; | ||
|
||
// if a nonterminal has one production rule and one occurrence in the grammar, it is inlined | ||
public BGFGrammar inlineLazy(BGFGrammar g) | ||
{ | ||
ns = allNs(g.prods); | ||
BGFGrammar g1 = grammar([],[]), g2 = g; | ||
// keep rewriting | ||
while(!gdts(g1,g2)) | ||
{ | ||
g1 = g2; | ||
lazy = {nt | nt <- ns, len({p | p:production(_,nt,_) <- g1.prods})==1} // defined by one prod | ||
& {nt | nt <- ns, len([1 | /nonterminal(nt) := g1.prods])==1}; // occur once | ||
g2 = vtransform([inline(nt) | nt <- lazy],g1); | ||
println("-----second stage------"); | ||
} | ||
// TODO: might want to change to non-verbal transform if bored to see messages | ||
return g1; | ||
} |
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,31 @@ | ||
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI} | ||
@wiki{InlinePlus} | ||
module mutate::InlinePlus | ||
|
||
import lib::Rascalware; | ||
import syntax::BGF; | ||
import syntax::XBGF; | ||
import transform::library::Util; | ||
import transform::XBGF; | ||
import IO; | ||
|
||
// (1) inline all nonterminals defined as pluses of other nonterminals | ||
// (2) massage x+? to x* if necessary | ||
public BGFGrammar inlinePlus(BGFGrammar g) | ||
{ | ||
ns = allNs(g.prods); | ||
todo = ({nt | p:production(_,nt,plus(nonterminal(_))) <- g.prods} // defined as plus | ||
& {nt | nt <- ns, len({p | p:production(_,nt,_) <- g.prods})==1}) // not defined otherwise | ||
- toSet(g.roots); | ||
//println({nt | p:production(_,nt,plus(nonterminal(_))) <- g.prods}); | ||
//println({nt | nt <- ns, len({p | p:production(_,nt,_) <- g.prods})==1}); | ||
//println(todo); | ||
//println(g.roots); | ||
//g2 = vtransform([inline(nt) | nt <- todo],g); | ||
// TODO: might want to change to non-verbal transform if bored to see messages | ||
return visit(vtransform([inline(nt) | nt <- todo],g)) | ||
{ | ||
case optional(plus(nonterminal(nt))) => star(nonterminal(nt)) | ||
}; | ||
} | ||
|
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,25 @@ | ||
@contributor{Vadim Zaytsev - vadim@grammarware.net - SWAT, CWI} | ||
@wiki{SubGrammar, DeYaccifyAll, UnchainAll, InlineLazy, InlinePlus} | ||
module mutate::Mutations | ||
|
||
extend mutate::SubGrammar; | ||
extend mutate::DeYaccify; | ||
extend mutate::InlineChains; | ||
extend mutate::InlineLazy; | ||
extend mutate::InlinePlus; | ||
|
||
import syntax::BGF; | ||
import normal::BGF; | ||
import IO; | ||
|
||
alias MutationList = list[BGFGrammar(BGFGrammar)]; | ||
|
||
public BGFGrammar mutate(MutationList script, BGFGrammar g) | ||
{ | ||
for (m <- script) | ||
{ | ||
println("[Mutation] <m>"); | ||
g = normalise(m(g)); | ||
} | ||
return g; | ||
} |
2 changes: 1 addition & 1 deletion
2
shared/rascal/src/mutate/Subgrammar.rsc → shared/rascal/src/mutate/SubGrammar.rsc
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