feat: Finish Chapter 5
This commit is contained in:
parent
a33c1585d6
commit
d5a19e0d69
@ -1,7 +1,7 @@
|
|||||||
/** md
|
/** md
|
||||||
Title: The Remaining Tests
|
Title: The Remaining Tests
|
||||||
|
|
||||||
## Programmable Rewriting strategies
|
## Programmable Rewriting Strategies
|
||||||
|
|
||||||
The manual then begins to discuss "programmable rewriting strategies" in
|
The manual then begins to discuss "programmable rewriting strategies" in
|
||||||
[Section 5.2](http://www.metaborg.org/en/latest/source/langdev/meta/lang/stratego/strategoxt/05-rewriting-strategies.html#programmable-rewriting-strategies)
|
[Section 5.2](http://www.metaborg.org/en/latest/source/langdev/meta/lang/stratego/strategoxt/05-rewriting-strategies.html#programmable-rewriting-strategies)
|
||||||
@ -54,12 +54,13 @@ test sec5_1_2_test1_cnf_ex [[
|
|||||||
Or(Not(Atom("r")), Atom("q"))),
|
Or(Not(Atom("r")), Atom("q"))),
|
||||||
Atom("p"))
|
Atom("p"))
|
||||||
|
|
||||||
test sec5_1_2_test1_both_ex [[
|
test sec5_1_2_test1_both [[
|
||||||
(r -> p & q) & p
|
(r -> p & q) & p
|
||||||
]] run dcnf to (Or(And(Not(Atom("r")),Atom("p")),And(And(Atom("p"),Atom("q")),Atom("p"))),
|
]] run dcnf to Atom("x")
|
||||||
And(And(Or(Not(Atom("r")), Atom("p")),
|
//(Or(And(Not(Atom("r")),Atom("p")),And(And(Atom("p"),Atom("q")),Atom("p"))),
|
||||||
Or(Not(Atom("r")), Atom("q"))),
|
// And(And(Or(Not(Atom("r")), Atom("p")),
|
||||||
Atom("p")))
|
// Or(Not(Atom("r")), Atom("q"))),
|
||||||
|
// Atom("p")))
|
||||||
|
|
||||||
test sec5_3_1_test1_dnf_ex [[
|
test sec5_3_1_test1_dnf_ex [[
|
||||||
(r -> p & q) & p
|
(r -> p & q) & p
|
||||||
@ -70,3 +71,23 @@ test sec5_3_1_test1_cnf_ex [[
|
|||||||
]] run cnf4 to And(And(Or(Not(Atom("r")), Atom("p")),
|
]] run cnf4 to And(And(Or(Not(Atom("r")), Atom("p")),
|
||||||
Or(Not(Atom("r")), Atom("q"))),
|
Or(Not(Atom("r")), Atom("q"))),
|
||||||
Atom("p"))
|
Atom("p"))
|
||||||
|
|
||||||
|
test sec5_3_2_eval_up_ex [[
|
||||||
|
(1 -> p & q) & p
|
||||||
|
]] run eval-up to And(And(Atom("p"),Atom("q")),Atom("p"))
|
||||||
|
|
||||||
|
test sec5_3_2_eval_down_ex [[
|
||||||
|
(1 -> p & q) & p
|
||||||
|
]] run eval-down to And(And(Atom("p"),Atom("q")),Atom("p"))
|
||||||
|
|
||||||
|
test sec5_3_2_desugar_ex [[
|
||||||
|
(1 -> p & q) & p
|
||||||
|
]] run desugar to And(Or(Not(True()),And(Atom("p"),Atom("q"))),Atom("p"))
|
||||||
|
|
||||||
|
test sec5_3_2_impl_nf_ex [[
|
||||||
|
(1 -> p & q) & p
|
||||||
|
]] run impl-nf to Impl(Impl(Impl(True(),Impl(Impl(Atom("p"),
|
||||||
|
Impl(Atom("q"),False())),
|
||||||
|
False())),
|
||||||
|
Impl(Atom("p"),False())),
|
||||||
|
False())
|
||||||
|
22
trans/prop-desugar.str
Normal file
22
trans/prop-desugar.str
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
module prop-desugar
|
||||||
|
imports libstrategolib signatures/-
|
||||||
|
|
||||||
|
rules
|
||||||
|
|
||||||
|
DefN : Not(x) -> Impl(x, False())
|
||||||
|
DefI : Impl(x, y) -> Or(Not(x), y)
|
||||||
|
DefE : Eq(x, y) -> And(Impl(x, y), Impl(y, x))
|
||||||
|
DefO1 : Or(x, y) -> Impl(Not(x), y)
|
||||||
|
DefO2 : Or(x, y) -> Not(And(Not(x), Not(y)))
|
||||||
|
DefA1 : And(x, y) -> Not(Or(Not(x), Not(y)))
|
||||||
|
DefA2 : And(x, y) -> Not(Impl(x, Not(y)))
|
||||||
|
|
||||||
|
IDefI : Or(Not(x), y) -> Impl(x, y)
|
||||||
|
|
||||||
|
IDefE : And(Impl(x, y), Impl(y, x)) -> Eq(x, y)
|
||||||
|
|
||||||
|
strategies
|
||||||
|
|
||||||
|
desugar = topdown(try(DefI <+ DefE))
|
||||||
|
|
||||||
|
impl-nf = topdown(repeat(DefN <+ DefA2 <+ DefO1 <+ DefE))
|
@ -67,7 +67,7 @@ So, we can just take our `test3` expression above and make it a part of
|
|||||||
an SPT test suite, which we will call `test/manual-suite.spt`:
|
an SPT test suite, which we will call `test/manual-suite.spt`:
|
||||||
```SPT
|
```SPT
|
||||||
{! ../test/manual-suite.spt extract:
|
{! ../test/manual-suite.spt extract:
|
||||||
start: '\*\*/'
|
start: '\*\*[/]'
|
||||||
terminate: '(.*run dnf)' !}
|
terminate: '(.*run dnf)' !}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ what the transformation actually produced. So we add just a bit to
|
|||||||
`test/manual-suite.spt`:
|
`test/manual-suite.spt`:
|
||||||
```SPT
|
```SPT
|
||||||
{! ../test/manual-suite.spt extract:
|
{! ../test/manual-suite.spt extract:
|
||||||
start: '\*\*/'
|
start: '\*\*[/]'
|
||||||
terminate: '(.*run dnf.*)$' !}
|
terminate: '(.*run dnf.*)$' !}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
27
trans/prop-eval2.str
Normal file
27
trans/prop-eval2.str
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
module prop-eval2
|
||||||
|
imports libstrategolib signatures/-
|
||||||
|
rules
|
||||||
|
|
||||||
|
Eval : Not(True()) -> False()
|
||||||
|
Eval : Not(False()) -> True()
|
||||||
|
Eval : And(True(), x) -> x
|
||||||
|
Eval : And(x, True()) -> x
|
||||||
|
Eval : And(False(), x) -> False()
|
||||||
|
Eval : And(x, False()) -> False()
|
||||||
|
Eval : Or(True(), x) -> True()
|
||||||
|
Eval : Or(x, True()) -> True()
|
||||||
|
Eval : Or(False(), x) -> x
|
||||||
|
Eval : Or(x, False()) -> x
|
||||||
|
Eval : Impl(True(), x) -> x
|
||||||
|
Eval : Impl(x, True()) -> True()
|
||||||
|
Eval : Impl(False(), x) -> True()
|
||||||
|
Eval : Impl(x, False()) -> Not(x)
|
||||||
|
Eval : Eq(False(), x) -> Not(x)
|
||||||
|
Eval : Eq(x, False()) -> Not(x)
|
||||||
|
Eval : Eq(True(), x) -> x
|
||||||
|
Eval : Eq(x, True()) -> x
|
||||||
|
|
||||||
|
strategies
|
||||||
|
|
||||||
|
eval-up = bottomup(repeat(Eval))
|
||||||
|
eval-down = downup(repeat(Eval))
|
@ -19,4 +19,4 @@ rules
|
|||||||
strategies
|
strategies
|
||||||
|
|
||||||
dnf4 = innermost(DefI <+ DefE <+ DAOL <+ DAOR <+ DN <+ DMA <+ DMO)
|
dnf4 = innermost(DefI <+ DefE <+ DAOL <+ DAOR <+ DN <+ DMA <+ DMO)
|
||||||
cnf4 = innermost(DefI <+ DefE <+ DOAL <+ DOAR <+ DN <+ DMA <+ DMO)
|
cnf4 = innermost(DefI <+ DefE <+ DOAL <+ DOAR <+ DN <+ DMA <+ DMO)
|
||||||
|
@ -11,6 +11,8 @@ imports
|
|||||||
prop-dnf3
|
prop-dnf3
|
||||||
prop-cnf3
|
prop-cnf3
|
||||||
prop-laws
|
prop-laws
|
||||||
|
prop-eval2
|
||||||
|
prop-desugar
|
||||||
|
|
||||||
rules // Debugging
|
rules // Debugging
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user