Skip to content

Instantly share code, notes, and snippets.

@hsk
hsk / dachs_grammer.md
Last active August 29, 2015 14:21
dachs language grammer

キーワード

true false do end var new begin let in as if unless then elseif else static_array pointer typeof ret case when for ensure init copy cast class import

symbol ::= expression の形式で文法要素を表します。( ... ) はグループを (^ ... ) は否定、|は選択、{ ... } は0回以上の繰り返し、{^ ... } が否定の0回以上の繰り返し、+ は1回以上の繰り返しを表します。

eol         ::= '\n' /* end of line */
eoi         ::= end of input
eps         ::= qi::eps
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/variant/recursive_variant.hpp>
#include <boost/variant/apply_visitor.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
#include <iostream>
#include <vector>
#include <string>
#define rw boost::recursive_wrapper
printi(i:int):void = printf("%d\n", i)
A:trait {
p():void = printi(1)
}
C <: A = struct(i:int) {
p():void = printi(i)
}
#include <stdio.h>
extern "C" {
void printi(int i) {
printf("%d\n", i);
}
// 型クラスA
typedef void (*A_p)(struct A*);
struct A {
#include <stdio.h>
extern "C" {
void printi(int i) {
printf("%d\n", i);
}
typedef void (*A_p)(struct A*);
struct A {
static void _new(struct A* self) {
use std::f64::consts::PI;
trait Shape { fn new(area: f64) -> Self; }
struct Circle { radius: f64 }
struct Square { length: f64 }
impl Shape for Circle {
fn new(area: f64) -> Circle { Circle { radius: (area / PI).sqrt() } }
}
impl Shape for Square {
fn new(area: f64) -> Square { Square { length: area.sqrt() } }
var traits = {};
var insts = {};
function trait(name, methods) {
traits[name] = methods;
insts[name] = {};
}
function struct(typeName, params, traitNames, bodys) {
var traits = {};
var insts = {};
function trait(name, methods) {
traits[name] = methods;
insts[name] = {};
}
function struct(name, params, impls, body) {
function findTraitName(x) {
package set
object main extends App {
def power[A](t: Set[A]): Set[Set[A]] = {
@annotation.tailrec
def pwr(t: Set[A], ps: Set[Set[A]]): Set[Set[A]] =
if (t.isEmpty) ps
else pwr(t.tail, ps ++ (ps map (_ + t.head)))
pwr(t, Set(Set.empty[A])) //Powerset of ∅ is {∅}
}
@hsk
hsk / set.ml
Last active August 29, 2015 14:03
open Format
let pp_ls f ppf ls =
let rec loop ppf = function
| [] -> ()
| [x] -> fprintf ppf "%a@?" f x
| x::xs -> fprintf ppf "%a, %a" f x loop xs
in
fprintf ppf "{%a}@?" loop ls
let pp_i ppf i = fprintf ppf "%d@?" i