59 lines
1.6 KiB
Plaintext
59 lines
1.6 KiB
Plaintext
|
/** md
|
||
|
Title: Running a Strategy, continued
|
||
|
|
||
|
## Disjunctive Normal Form
|
||
|
|
||
|
The next Stratego example, in {! ../docrefs/sec4.2.md !}, extends
|
||
|
`prop-eval-rules` to convert SPL propositions into disjunctive normal form (DNF).
|
||
|
Once again, we can place the Stratego code in `trans/prop-dnf-rules.str`:
|
||
|
|
||
|
```Stratego
|
||
|
**/
|
||
|
/** md Include this code in documentation: */
|
||
|
module prop-dnf-rules
|
||
|
imports prop-eval-rules
|
||
|
rules
|
||
|
E : Impl(x, y) -> Or(Not(x), y)
|
||
|
E : Eq(x, y) -> And(Impl(x, y), Impl(y, x))
|
||
|
|
||
|
E : Not(Not(x)) -> x
|
||
|
|
||
|
E : Not(And(x, y)) -> Or(Not(x), Not(y))
|
||
|
E : Not(Or(x, y)) -> And(Not(x), Not(y))
|
||
|
|
||
|
E : And(Or(x, y), z) -> Or(And(x, z), And(y, z))
|
||
|
E : And(z, Or(x, y)) -> Or(And(z, x), And(z, y))
|
||
|
/* end of code inclusion **/
|
||
|
/** md rest of documentation
|
||
|
```
|
||
|
and create a `trans/prop-dnf.str` that defines a strategy for applying the
|
||
|
DNF rules and supplies the glue needed between ESV and Stratego:
|
||
|
```Stratego
|
||
|
{! prop-dnf.str !}
|
||
|
```
|
||
|
Now just importing `prop-dnf` in `trans/spoofax-propositional-language.str`
|
||
|
and adding a menu item to `editor/Manual.esv`:
|
||
|
```ESV
|
||
|
...
|
||
|
{! ../editor/Manual.esv extract: {start: menus} !}
|
||
|
```
|
||
|
should suffice to make the dnf strategy available in the "Spoofax > Manual"
|
||
|
menu.
|
||
|
|
||
|
Indeed, we can try it out on `syntax/examples/sec4.2_test3.spl`:
|
||
|
```SPL
|
||
|
{! ../syntax/examples/sec4.2_test3.spl !}
|
||
|
```
|
||
|
to produce
|
||
|
```
|
||
|
{! ../syntax/examples/sec4.2_test3.dnf.aterm !}
|
||
|
```
|
||
|
as verified in the manual (again, modulo the"ATom" typo in the manual).
|
||
|
|
||
|
However, we also want to use this second example to show another method of
|
||
|
running Stratego strategies from the Eclipse IDE.
|
||
|
|
||
|
## Spoofax Testing Language
|
||
|
|
||
|
CONTINUE FROM HERE
|
||
|
**/
|