This file contains hidden or 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
Decl "data declaration" | |
= Data name:TName params:TParam* Equals first:Constructor rest:Alternative* { | |
return { | |
name: name, | |
params: params, | |
constructors: [first].concat(rest) | |
}; | |
} | |
Data "data keyword" |
This file contains hidden or 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
start | |
= (d:die _ { return d })* | |
number | |
= [0-9] | |
nonzero | |
= [1-9] | |
diesize |
This file contains hidden or 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
#include <math.h> | |
double my_log(double x) { | |
static const double log2 = 0.693147; | |
double y, logy; | |
int n; | |
// factor x = y * 2^n, where 1 <= y < 2 | |
// frexp gives us the range 0.5 <= y < 1 |
This file contains hidden or 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
macro lazy { | |
rule { $e:expr } => { | |
new function() { | |
this.done = false; | |
this.valueOf = function() { | |
if(!this.done) { | |
this.done = true; | |
this.value = $e; | |
} | |
return this.value; |
This file contains hidden or 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
var rm_lr = function(name, grammar) { | |
var p_with = grammar[name].filter(function(x) { return x[0] == name; }), | |
p_wo = grammar[name].filter(function(x) { return x[0] != name; }); | |
grammar[name] = p_wo.concat(p_wo.map(function(wo) { | |
return wo.concat([name + "'"]); | |
})); | |
grammar[name + "'"] = [['e']].concat(p_with.map(function(x) { | |
return x.slice(1).concat([name + "'"]); |
This file contains hidden or 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
macro lam { | |
rule { $x:ident $y:expr -> $body:expr } => { | |
(function($x) { return lam $y -> $body; }) | |
} | |
rule { $x:ident -> $body:expr } => { | |
(function($x) { return $body; }) | |
} | |
} |
This file contains hidden or 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(zipr). | |
-export([new/1, cur/1, to_list/1, next/1, prev/1, addl/2, addr/2]). | |
new(X) -> {[], X, []}. | |
cur({_L, X, _R}) -> X. | |
to_list({L, X, R}) -> lists:reverse(L) ++ [X] ++ R. | |
next({L, X, [H|R]}) -> {[X]++L, H, R}. | |
prev({[H|L], X, R}) -> {L, X, [H]++R}. | |
addl({L, X, R}, X1) -> {L, X1, [X]++R}. | |
addr({L, X, R}, X1) -> {[X]++L, X1, R}. |
This file contains hidden or 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
{-# LANGUAGE DeriveFunctor #-} | |
import Text.ParserCombinators.Parsec | |
import Data.Functor.Foldable | |
import qualified Data.Set as S | |
data FormF a = Var Char | |
| Not a | |
| And a a | |
| Or a a |
This file contains hidden or 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
intro = [ | |
'=======================================', | |
'VVTB (Very Very Tiny Basic) interpreter', | |
'(c) 2012 Forest Belton (case)', | |
'=======================================' | |
] | |
prgm = {} | |
vars = {} |
This file contains hidden or 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
var tenyr = (function() { | |
"use strict"; | |
var regbuf = new ArrayBuffer(4 * 16); | |
var regs = new Int32Array(regbuf); | |
var mem = {}; | |
var hooks = []; | |
var add_hook = function(hook) { | |
hooks.push(hook); |