Skip to content

Commit

Permalink
implement more efficient pruner (TODO)
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Oct 16, 2023
1 parent edb918f commit d7fe6a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fun CFG.dropVestigialProductions(
// val reachable = reachableSymbols()
val rw = toMutableSet()
.apply { removeAll { prod -> prod.RHS.any { criteria(it) && it !in nts } } }
.freeze().removeUselessSymbols()
.freeze().removeUselessSymbols()//.removeUnreachable().freeze().removeNonGenerating()

println("Removed ${size - rw.size} vestigial productions.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ fun CFG.refactorEpsilonProds(nlbls: Set<Σᐩ> = nullableNonterminals()): CFG =
* A useful symbol is both generating and reachable.
*/

// TODO: https://zerobone.net/blog/cs/non-productive-cfg-rules/
fun CFG.removeUselessSymbols(
generating: Set<Σᐩ> = genSym(),
reachable: Set<Σᐩ> = reachSym()
Expand All @@ -180,6 +181,13 @@ fun CFG.removeUselessSymbols(
// }
// .first.toSet()

//fun CFG.removeNonGenerating(generating: Set<Σᐩ> = genSym()) =
// toMutableSet().apply { removeAll { (s, _) -> s !in generating } }
//
//fun CFG.removeUnreachable() =
// toMutableSet().apply { removeAll { (s, _) -> !reachableNTs[bindex[s]] } }
// .also { println("Removed ${size - it.size} unreachable productions.") }

fun CFG.equivalenceClass(from: Σᐩ): Set<Σᐩ> = unitReachability[from] ?: setOf(from)

fun LabeledGraph.transitiveClosure(from: Set<Σᐩ>) =
Expand Down

0 comments on commit d7fe6a8

Please sign in to comment.