Created
September 6, 2013 19:52
-
-
Save osa1/6469034 to your computer and use it in GitHub Desktop.
once working K program
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
module CONCAT-SYNTAX | |
syntax Concat ::= List{Concat1, " "} | |
syntax Concat1 ::= Id | |
| "|" Concat1 "|" // quotation | |
| "[" Concat "]" | |
| Int | |
| "print" | |
| "pop" | |
| "+" | |
| "-" | |
| "dup" | |
| "apply" | |
//| "dip" | |
syntax K ::= apply(List, Concat1) | concatToConcat1(Concat) | |
endmodule | |
module CONCAT | |
imports CONCAT-SYNTAX | |
configuration | |
<k> $PGM:Concat </k> | |
<out stream="stdout"> .List </out> | |
<stack> .List </stack> | |
<someMap> .Map </someMap> | |
// rule #symNat(N) => N | |
// this rule transforms sequence syntax to process sequencing, | |
// then rules could be simply applied to C's instead of list of C:Cs | |
rule C:Concat1 Cs:Concat => C ~> Cs | |
rule <k> I:Id => . ... </k> | |
<stack> ... . => ListItem(I) </stack> | |
rule <k> I:Int => . ... </k> | |
<stack> ... . => ListItem(I) </stack> | |
rule <k> print => . ... </k> | |
<stack> ... ListItem(I) => . </stack> | |
<out> ... . => ListItem(I) </out> | |
rule <k> pop => . ... </k> | |
<stack> ... ListItem(I) => . </stack> | |
rule <k> pop => . ... </k> | |
rule <k> + => . ... </k> | |
<stack> ... (ListItem(I1:Int) ListItem(I2:Int) => ListItem(I1 +Int I2)) </stack> | |
rule <k> - => . ... </k> | |
<stack> ... (ListItem(I1:Int) ListItem(I2:Int) => ListItem(I1 -Int I2)) </stack> | |
rule <k> dup => . ... </k> | |
<stack> ... (ListItem(I) => ListItem(I) ListItem(I)) </stack> | |
rule <k> [ C:Concat ] => . ... </k> | |
<stack> ... . => ListItem([ C ]) </stack> | |
rule <k> | C:Concat1 | => . ... </k> | |
<stack> ... . => ListItem(| C |) </stack> | |
rule <k> apply => Fun ... </k> | |
<stack> ... (ListItem(| Fun |) => .) </stack> [applySingleQute] | |
// TODO: is there a list splicing operator?? | |
rule <k> apply => concatToConcat1(Funs) ... </k> | |
<stack> ... (ListItem([ Funs ]) => .) </stack> [applyQuote] | |
//rule concatToConcat1(.Concat) => . | |
//rule concatToConcat1(C Cs) => C ~> concatToConcat1(Cs) | |
rule <k> concatToConcat1(.Concat) => . ... </k> | |
rule <k> concatToConcat1(C Cs) => C ~> concatToConcat1(Cs) ... </k> | |
// FIXME: for some reason, this rule doesn't | |
// reduce .Concat ~> .Concat to .Concat. learn this. | |
rule <k> .Concat => . </k> | |
//rule .Concat => . | |
// dip -- not working | |
// rule <k> dip => . ... </k> | |
// <stack> ... (ListItem(Before) ListItem([ Funs ]) => ListItem(apply([ Funs ])) ListItem(Before)) </stack> | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment