Skip to content

Instantly share code, notes, and snippets.

@hsk
hsk / SortOfWhile.pro
Last active October 13, 2016 23:47
hoare.pl
/* Syntax of SortOfWhile */
% Statements
stm(skip()).
stm((S1; S2)) :- stm(S1), stm(S2).
stm(X = E) :- atom(X), aexp(E).
stm(if(E, S1, S2)) :- bexp(E), stm(S1), stm(S2).
stm(while(E; S)) :- bexp(E), stm(S).
stm(or(S1, S2)) :- stm(S1), stm(S2).
stm(par(S1, S2)) :- stm(S1), stm(S2).
@hsk
hsk / anf.pl
Last active October 11, 2016 05:47
Evaluation contexts
/*
構文
x, y, z 変数
v ::= 値
 λ(x:T)t ラムダ
s, t, u ::= 項
 x 変数
 v 値
 x y 関数適用
@hsk
hsk / orelang.pl
Last active September 30, 2016 10:51
:- initialization(main).
eval1(Ctx,L,Ctx_,V) :- print_term(L,[]),nl,eval(Ctx,L,Ctx_,V),!.
eval(Ctx,["set",X,E],[X=V|Ctx_],null) :- eval1(Ctx, E, Ctx_, V).
eval(Ctx,["get",X],Ctx,V) :- member(X=V, Ctx).
eval(Ctx,["+",E1,E2],Ctx2,V) :- eval1(Ctx,E1,Ctx1,V1),eval1(Ctx1,E2,Ctx2,V2), V is V1 + V2.
eval(Ctx,["=",E1,E2],Ctx2,V) :- eval1(Ctx,E1,Ctx1,V1),eval1(Ctx1,E2,Ctx2,V2), (V1 = V2,V=true;V=false).
eval(Ctx,["until",E1,E2],Ctx3,null) :-
eval1(Ctx,E1,Ctx1,V1),
(V1=true,Ctx3=Ctx1; eval1(Ctx1,E2,Ctx2,_),eval1(Ctx2,["until",E1,E2],Ctx3,_)).
eval(Ctx,["step"|[]],Ctx,null).
@hsk
hsk / FeatherWeightJava.pl
Last active October 5, 2016 06:42
tapl on prolog
/*
Featherweight Java on Prolog
Featherweight Javaは形式化されたJavaのシンプルなサブセットです。
Featherweight Java on PrologはProlog上のDSLとしてFeatherweight Javaを実装したものです。
Featherweight Java on Prologの構文はProlog上で実装しやすい形に書き換えてあります:
構文
CL ::= クラス宣言:
%{
open Source
open Types
open Kernel
open Ast
open Script
(* Error handling *)

lit language spec

Syntax Summary

Lexical Syntax

white_space ::= ' ' | '\r' | '\n' | '\t'
ident       ::= ('a'|...|'z'|'A'|..|'Z'|'_')('a'|...|'z'|'A'|..|'Z'|'_'|'0'|...|'9')*
number      ::= ('0'|...|'9')+
# Klassic言語仕様
## Klassicの開発ポリシー
基本的にScalaを改良しつつ、最初はコアな機能を作成し、パーシャルファンクション等の細かい機能は後からつける。
EOF ::= not(elem(".", (ch: Char) => ch != CharSequenceReader.EofCh), "EOF Expected")
LINEFEED ::= ("\r\n" | "\r" | "\n")
SEMICOLON ::= ";"
@hsk
hsk / gist:d1b4274a7153da9c7db3
Created December 4, 2015 02:26
atom transparent style.less
/*
* Your Stylesheet
*
* This stylesheet is loaded when Atom starts up and is reloaded automatically
* when it is changed.
*
* If you are unfamiliar with LESS, you can read more about it here:
* http://www.lesscss.org
*/
@textfade: rgba(0,0,0,1.0);
@hsk
hsk / calc.ml
Last active October 8, 2015 11:01
calc.ml
type c =
| Int of int
| Add
| Sub
| Load of string
| Save of string
| Ret
let rec lookup e v =
match e with
@hsk
hsk / a.scala
Last active August 29, 2015 14:24
named visitor
package a
trait E {
def visit[T](v:EVisitor[T]):T
}
class EInt(a:Int) extends E {
def visit[T](v:EVisitor[T]):T = v.EInt(a)
}
class EBin(a:E,op:String,b:E) extends E {
def visit[T](v:EVisitor[T]):T = v.EBin(a,op,b)
}