Created
February 13, 2020 22:28
-
-
Save GrahamCampbell/c8d84d42e3913065d1f9859fd8aeb8dd to your computer and use it in GitHub Desktop.
The Improved GP 2 Compiler
This file contains 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
Main = (init; Reduce!; if flag then break)!; if flag then fail | |
Reduce = up!; try Delete else set_flag | |
Delete = {del0, del1, del1_d, del21, del21_d, del22, del22_d} | |
init(x: list) | |
[ (n1, x) | ] | |
=> | |
[ (n1(R), x) | ] | |
interface = {n1} | |
up(a,x,y: list) | |
[ (n1(R), x) (n2, y) | (e1, n2, n1, a) ] | |
=> | |
[ (n1, x) (n2(R), y) | (e1, n2, n1, a # dashed) ] | |
interface = {n1, n2} | |
del0(x: list) | |
[ (n1(R), x) | ] | |
=> | |
[ | ] | |
interface = {} | |
del1(a,x,y: list) | |
[ (n1, x) (n2(R), y) | (e1, n2, n1, a) ] | |
=> | |
[ (n1(R), x) | ] | |
interface = {n1} | |
del1_d(a,x,y: list) | |
[ (n1, x) (n2(R), y) | (e1, n2, n1, a # dashed) ] | |
=> | |
[ (n1(R), x) | ] | |
interface = {n1} | |
del21(a,b,x,y: list) | |
[ (n1, x) (n2(R), y) | (e1, n2, n1, a) (e2, n2, n1, b) ] | |
=> | |
[ (n1(R), x) | ] | |
interface = {n1} | |
del21_d(a,b,x,y: list) | |
[ (n1, x) (n2(R), y) | (e1, n2, n1, a # dashed) (e2, n2, n1, b) ] | |
=> | |
[ (n1(R), x) | ] | |
interface = {n1} | |
del22(a,b,x,y,z: list) | |
[ (n1, x) (n2, y) (n3(R), z) | (e1, n3, n1, a) (e2, n3, n2, b) ] | |
=> | |
[ (n1(R), x) (n2, y) | ] | |
interface = {n1, n2} | |
del22_d(a,b,x,y,z: list) | |
[ (n1, x) (n2, y) (n3(R), z) | (e1, n3, n1, a # dashed) (e2, n3, n2, b) ] | |
=> | |
[ (n1(R), x) (n2, y) | ] | |
interface = {n1, n2} | |
set_flag(x: list) | |
[ (n1(R), x) | ] | |
=> | |
[ (n1(R), x # grey) | ] | |
interface = {n1} | |
flag(x: list) | |
[ (n1(R), x # grey) | ] | |
=> | |
[ (n1(R), x # grey) | ] | |
interface = {n1} |
This file contains 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
Main = try init then (DFS!; Check) | |
DFS = fwd!; try bck else break | |
Check = if match then fail | |
init(x: list) | |
[ (n1, x) | ] | |
=> | |
[ (n1(R), x # grey) | ] | |
interface={n1} | |
fwd(x,y,n: list) | |
[ (n1(R), x # grey) (n2, y) | (e1(B), n1, n2, n) ] | |
=> | |
[ (n1, x # grey) (n2(R), y # grey) | (e1(B), n1, n2, n # dashed) ] | |
interface={n1,n2} | |
bck(x,y,n: list) | |
[ (n1, x # grey) (n2(R), y # grey) | (e1(B), n1, n2, n # dashed) ] | |
=> | |
[ (n1(R), x # grey) (n2, y # blue) | (e1(B), n1, n2, n) ] | |
interface={n1,n2} | |
match(x,z: list) | |
[ (n1(R), x # grey) (n2, z) | ] | |
=> | |
[ (n1(R), x # grey) (n2, z) | ] | |
interface={n1,n2} |
This file contains 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
Main = try init then (gen!; del); finish | |
init(n: int) | |
[ (n0(R), n) | ] | |
=> | |
[ (n0(R), n) (n1(R), n-1) | (e0, n0, n1, empty) ] | |
interface = {n0} | |
where n > 1 | |
gen(n,m: int) | |
[ (n0(R), n) (n1(R), m) | (e0, n0, n1, empty) ] | |
=> | |
[ (n0, n) (n1(R), m) (n2(R), m-1) | (e0, n1, n2, empty) ] | |
interface = {n0, n1} | |
where m > 1 | |
del(n,m: int) | |
[ (n0(R), n) (n1(R), m) | (e0, n0, n1, empty) ] | |
=> | |
[ (n0, n) (n1(R), m) | ] | |
interface = {n0, n1} | |
finish() | |
[ (n0(R), 1) | ] | |
=> | |
[ (n0, 1) | ] | |
interface = {n0} |
This file contains 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
Main = init; Reduce!; Unmark; if Check then fail | |
Reduce = {prune0, prune1, push} | |
Unmark = try unmark; try unmark | |
Check = {two_nodes, has_loop} | |
init(x: list) | |
[ (n1, x) | ] | |
=> | |
[ (n1(R), x) | ] | |
interface = {n1} | |
prune0(a,x,y: list) | |
[ (n1, x) (n2(R), y) | (e1, n1, n2, a) ] | |
=> | |
[ (n1(R), x) | ] | |
interface = {n1} | |
prune1(a,x,y: list) | |
[ (n1, x # grey) (n2(R), y) | (e1, n1, n2, a) ] | |
=> | |
[ (n1(R), x) | ] | |
interface = {n1} | |
push(a,x,y: list) | |
[ (n1(R), x) (n2, y) | (e1, n1, n2, a) ] | |
=> | |
[ (n1, x # grey) (n2(R), y) | (e1, n1, n2, a) ] | |
interface = {n1, n2} | |
unmark(x: list) | |
[ (n1, x # grey) | ] | |
=> | |
[ (n1, x) | ] | |
interface = {n1} | |
two_nodes(x,y: list) | |
[ (n1, x) (n2, y) | ] | |
=> | |
[ (n1, x) (n2, y) | ] | |
interface = {n1, n2} | |
has_loop(a,x: list) | |
[ (n1, x) | (e1, n1, n1, a) ] | |
=> | |
[ (n1, x) | (e1, n1, n1, a) ] | |
interface = {n1} |
This file contains 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
Main = link! | |
link(a,b,x,y,z: list) | |
[ (n0, x) (n1, y) (n2, z) | | |
(e0, n0, n1, a) (e1, n1, n2, b) ] | |
=> | |
[ (n0, x) (n1, y) (n2, z) | | |
(e0, n0, n1, a) (e1, n1, n2, b) (e2, n0, n2, empty) ] | |
interface = {n0, n1, n2} | |
where not edge(n0, n2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment