feat: implement Chapter 7

This commit is contained in:
Glen Whitney 2021-01-20 11:05:33 -08:00
parent 76456b2c21
commit 98bb2088e4
3 changed files with 55 additions and 0 deletions

View File

@ -161,3 +161,42 @@ test sec6_2_dnf_exercise_ex [[
p = q p = q
]] run better-dnf to Or(And(Not(Atom("p")),Not(Atom("q"))), ]] run better-dnf to Or(And(Not(Atom("p")),Not(Atom("q"))),
And(Atom("q"),Atom("p"))) And(Atom("q"),Atom("p")))
/** md
### Chapter 7
The content and style of chapter 7 are similar to chapter 6. Again, there is a
`trans/chap7.str` Stratego file defining several of the rules used in the examples
from the chapter. As before, the examples with a different signature are recast
into the SPL signature. Specifically, `Z` becomes `False`, `S(x)` becomes
`Impl(True(), x)`, and `P` becomes `Or`.
**/
test sec7_2_b_ex [[
(1 -> 0) | 0
]] run B to Or(False(), Impl(True(), False()))
test sec7_2_b_a_ex [[
(1 -> 0) | 0
]] run BthenA to Impl(True(), False())
test sec7_2_b_b_fails [[
(1 -> 0) | 0
]] run Btwice fails
test sec7_2_local_choice_fails [[
(1 -> 0) | 0
]] run maybeB-id-thenB fails
test sec7_2_seq_no_dist_over_choice_ex [[
(1 -> 0) | 0
]] run maybeBtwice-idthenB to Or(False(), Impl(True(), False()))
test sec7_3_repeat_small_ex [[
(1 -> 0) | 0
]] run repeatmaybeAB to Impl(True(), False())
test sec7_3_repeat_big_ex [[
(1 -> (1 -> (1 -> (1 -> 0)))) | 0
]] run repeatmaybeAB to Impl(True(), Impl(True(), Impl(True(),
Impl(True(), False()))))

15
trans/chap7.str Normal file
View File

@ -0,0 +1,15 @@
module chap7
imports libstrategolib signatures/-
rules
A : Or(False(), x) -> x
B : Or(Impl(True(),x), y) -> Or(x, Impl(True(), y))
strategies
BthenA = B; A
Btwice = B; B
maybeB-id-thenB = (B <+ id); B
maybeBtwice-idthenB = Btwice <+ (id; B)
repeatmaybeAB = repeat(A <+ B)

View File

@ -14,6 +14,7 @@ imports
prop-eval2 prop-eval2
prop-desugar prop-desugar
chap6 chap6
chap7
rules // Debugging rules // Debugging