Skip to content

Instantly share code, notes, and snippets.

@hsk
hsk / elvm.pl
Created December 23, 2016 16:17
% elvm on prolog
:- style_check(-singleton).
reg(a). reg(b). reg(c). reg(d). reg(sp). reg(bp).
imm(N) :- integer(N), N >= 0, MAX is 256 * 65536, N < MAX.
update([],V,[V]).
update([Reg=_|R],Reg=V,[Reg=V|R]).
update([V1|R],V,[V1|R2]) :- update(R,V,R2).
@hsk
hsk / NSON.BNF
Last active November 7, 2016 15:17
NSON BNF
## NSON BNF
bool ::= 'true' | 'false'
value ::= '"' (not('"')|'\' _)+ '"'
| ('a'|...|'z'|'A'|...|'Z'|'_')('a'|...|'z'|'A'|...|'Z'|'_'|'0'|...'9')*
number ::= ('0'|...|'9')+
| ('0'|...|'9')* '.' ('0'|...|'9')+ | ('0'|...|'9')+ '.' ('0'|...|'9')*
value ::= atom | number | bool
expression ::= value | object | array
object ::= '{' (value ':' expression ','?)* '}'
@hsk
hsk / index.html
Last active October 14, 2016 02:13
prolog
<html>
<head>
<script src="http://pengines.swi-prolog.org/vendor/jquery/jquery-2.0.3.min.js"></script>
<script src="http://pengines.swi-prolog.org/pengine/pengines.js"></script>
<script type="text/x-prolog">
/*
TLLP interpreter in Prolog
*/
:- op(1060, xfy, (&)).
:- op( 950, xfy, [-<>, =>]).
@hsk
hsk / index.html
Last active October 14, 2016 02:03
Plain JS 3
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>$title</title>
$styles
</head>
<body>
<h1>$title</h1>
@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')+