Created
May 1, 2012 19:52
-
-
Save siritori/2570893 to your computer and use it in GitHub Desktop.
式木の定義的なアレ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract sig Expr { | |
lhs : lone Expr, | |
rhs : lone Expr | |
} | |
sig True extends Expr {} | |
sig False extends Expr {} | |
sig Not extends Expr {} | |
sig And extends Expr {} | |
sig Or extends Expr {} | |
fun children [e : Expr] : Expr { | |
e.^(lhs + rhs) | |
} | |
fun family [e : Expr] : Expr { | |
e.*(lhs + rhs) | |
} | |
pred op_prim[e : Expr] { | |
no children[e] | |
e in (True + False) | |
} | |
pred op_not[e : Expr] { | |
one e.lhs and no e.rhs | |
e in Not | |
} | |
pred op_two[e : Expr] { | |
one e.lhs and one e.rhs | |
e in (And + Or) | |
} | |
fact tree { | |
one root : Expr | Expr = family[root] | |
all e : Expr { | |
no family[e.lhs] & family[e.rhs] | |
not e in children[e] | |
} | |
} | |
fact operator { | |
all e : Expr | op_prim[e] or op_not[e] or op_two[e] | |
} | |
pred show { | |
} | |
run show for 8 Expr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment