feat: Implement Chapter9

Also provides proper associativity on the operators, to avoid
  ambiguous parses.

  This completes all of the examples in the Spoofax Tutorial/Reference
  that use the propositional signature.
This commit is contained in:
Glen Whitney 2021-01-22 09:29:57 -08:00
parent fddc94a906
commit ba130ecb0f
17 changed files with 402 additions and 25 deletions

9
trans/prop-dnf10.str Normal file
View file

@ -0,0 +1,9 @@
module prop-dnf10
imports libstrategolib signatures/- prop-laws
strategies
proptr10(s) = Not(s) <+ And(s, s) <+ Or(s, s) <+ Impl(s, s) <+ Eq(s, s)
propbu10(s) = try(proptr10(propbu10(s))); s
strategies
dnf10 = propbu10(try(DN <+ (DefI <+ DefE <+ DMA <+ DMO <+ DAOL <+ DAOR); dnf10))
cnf10 = propbu10(try(DN <+ (DefI <+ DefE <+ DMA <+ DMO <+ DOAL <+ DOAR); cnf10))

6
trans/prop-dnf11.str Normal file
View file

@ -0,0 +1,6 @@
module prop-dnf11
imports libstrategolib prop-laws
strategies
dnf11 = bottomup(try(DN <+ (DefI <+ DefE <+ DMA <+ DMO <+ DAOL <+ DAOR); dnf11))
cnf11 = bottomup(try(DN <+ (DefI <+ DefE <+ DMA <+ DMO <+ DOAL <+ DOAR); cnf11))

14
trans/prop-dnf4.str Normal file
View file

@ -0,0 +1,14 @@
module prop-dnf4
imports libstrategolib prop-laws
rules
dnf4 : True() -> True()
dnf4 : False() -> False()
dnf4 : Atom(x) -> Atom(x)
dnf4 : Not(x) -> <dnfred4> Not (<dnf4>x)
dnf4 : And(x, y) -> <dnfred4> And (<dnf4>x, <dnf4>y)
dnf4 : Or(x, y) -> Or (<dnf4>x, <dnf4>y)
dnf4 : Impl(x, y) -> <dnfred4> Impl(<dnf4>x, <dnf4>y)
dnf4 : Eq(x, y) -> <dnfred4> Eq (<dnf4>x, <dnf4>y)
strategies
dnfred4 = try(DN <+ (DefI <+ DefE <+ DMA <+ DMO <+ DAOL <+ DAOR); dnf4)

12
trans/prop-dnf5.str Normal file
View file

@ -0,0 +1,12 @@
module prop-dnf5
imports libstrategolib prop-laws
rules
dnft5 : Not(x) -> <dnfred5> Not (<dnf5>x)
dnft5 : And(x, y) -> <dnfred5> And (<dnf5>x, <dnf5>y)
dnft5 : Or(x, y) -> Or (<dnf5>x, <dnf5>y)
dnft5 : Impl(x, y) -> <dnfred5> Impl(<dnf5>x, <dnf5>y)
dnft5 : Eq(x, y) -> <dnfred5> Eq (<dnf5>x, <dnf5>y)
strategies
dnf5 = try(dnft5)
dnfred5 = try(DN <+ (DefI <+ DefE <+ DMA <+ DMO <+ DAOL <+ DAOR); dnf5)

12
trans/prop-dnf6.str Normal file
View file

@ -0,0 +1,12 @@
module prop-dnf6
imports libstrategolib prop-laws
rules
dnft6 : Not(x) -> Not (<dnf6>x)
dnft6 : And(x, y) -> And (<dnf6>x, <dnf6>y)
dnft6 : Or(x, y) -> Or (<dnf6>x, <dnf6>y)
dnft6 : Impl(x, y) -> Impl(<dnf6>x, <dnf6>y)
dnft6 : Eq(x, y) -> Eq (<dnf6>x, <dnf6>y)
strategies
dnf6 = try(dnft6); dnfred6
dnfred6 = try(DN <+ (DefI <+ DefE <+ DMA <+ DMO <+ DAOL <+ DAOR); dnf6)

14
trans/prop-dnf7.str Normal file
View file

@ -0,0 +1,14 @@
module prop-dnf7
imports libstrategolib prop-laws
rules
proptr7(s) : Not(x) -> Not (<s>x)
proptr7(s) : And(x, y) -> And (<s>x, <s>y)
proptr7(s) : Or(x, y) -> Or (<s>x, <s>y)
proptr7(s) : Impl(x, y) -> Impl(<s>x, <s>y)
proptr7(s) : Eq(x, y) -> Eq (<s>x, <s>y)
strategies
dnf7 = try(proptr7(dnf7)); dnfred7
dnfred7 = try(DN <+ (DefI <+ DefE <+ DMA <+ DMO <+ DAOL <+ DAOR); dnf7)
cnf7 = try(proptr7(cnf7)); cnfred7
cnfred7 = try(DN <+ (DefI <+ DefE <+ DMA <+ DMO <+ DOAL <+ DOAR); cnf7)

10
trans/prop-dnf8.str Normal file
View file

@ -0,0 +1,10 @@
module prop-dnf8
imports libstrategolib prop-laws prop-dnf7
strategies
propbu8(s) = try(proptr7(propbu8(s))); s
strategies
dnf8 = propbu8(dnfred8)
dnfred8 = try(DN <+ (DefI <+ DefE <+ DMA <+ DMO <+ DAOL <+ DAOR); dnf8)
cnf8 = propbu8(cnfred8)
cnfred8 = try(DN <+ (DefI <+ DefE <+ DMA <+ DMO <+ DOAL <+ DOAR); cnf8)

6
trans/prop-dnf9.str Normal file
View file

@ -0,0 +1,6 @@
module prop-dnf9
imports libstrategolib prop-laws prop-dnf8
strategies
dnf9 = propbu8(try(DN <+ (DefI <+ DefE <+ DMA <+ DMO <+ DAOL <+ DAOR); dnf9))
cnf9 = propbu8(try(DN <+ (DefI <+ DefE <+ DMA <+ DMO <+ DOAL <+ DOAR); cnf9))

View file

@ -82,7 +82,7 @@ included into the `editor/Main.esv` file, like so:
replace: ['^\s*$']
terminate: 'provider\s*:' !} [ ... rest of file suppressed for brevity. ]
```
It's just the one line `Manual` in the `imports` section that we have added. The
It's just the one line "Manual" in the `imports` section that we have added. The
`editor/Manual.esv` implementing the submenu is also very simple:
```esv
{! ../editor/Manual.esv terminate: dnf !}

View file

@ -18,5 +18,5 @@ rules
strategies
dnf4 = innermost(DefI <+ DefE <+ DAOL <+ DAOR <+ DN <+ DMA <+ DMO)
cnf4 = innermost(DefI <+ DefE <+ DOAL <+ DOAR <+ DN <+ DMA <+ DMO)
dnf-laws = innermost(DefI <+ DefE <+ DAOL <+ DAOR <+ DN <+ DMA <+ DMO)
cnf-laws = innermost(DefI <+ DefE <+ DOAL <+ DOAR <+ DN <+ DMA <+ DMO)

18
trans/sec9_1.str Normal file
View file

@ -0,0 +1,18 @@
module sec9_1
imports libstrategolib signatures/- prop-laws prop-desugar
strategies
conj(s) = And(conj(s), conj(s)) <+ s
disj(s) = Or (disj(s), disj(s)) <+ s
// Conjunctive normal form
conj-nf = conj(disj(Not(Atom(id)) <+ Atom(id)))
// Disjunctive normal form
disj-nf = disj(conj(Not(Atom(id)) <+ Atom(id)))
// Second exercise, Section 9.1.2
path-dep-xform = DN <+ IDefI
inner-soln = repeat(oncebu(path-dep-xform))
outer-soln = repeat(oncetd(path-dep-xform))
random-soln = repeat(rec x(one(x) + path-dep-xform))

14
trans/sec9_2.str Normal file
View file

@ -0,0 +1,14 @@
module sec9_2
imports prop-eval2 prop-desugar
rules
DefT : True() -> Impl(False(), False())
strategies
eval1 = bottomup(try(Eval))
eval2 = topdown(try(Eval))
desugar2 = bottomup(try(DefI <+ DefE))
impl-nf1 = topdown(repeat(DefT <+ DefN <+ DefA2 <+ DefO1 <+ DefE))
impl-nf2 = topdown(try(DefT <+ DefN <+ DefA2 <+ DefO1 <+ DefE))

View file

@ -16,6 +16,16 @@ imports
chap6
chap7
chap8
prop-dnf4
prop-dnf5
prop-dnf6
prop-dnf7
prop-dnf8
prop-dnf9
prop-dnf10
sec9_1
prop-dnf11
sec9_2
rules // Debugging