Instantly share code, notes, and snippets.

View lang1-parser.cljc
(def lang1-parser
(instaparse.core/parser
"prog = (spaces? expr spaces? <';'> spaces?)*
<expr> = assig | add-sub
assig = varname spaces? <'='> spaces? expr
<add-sub> = mult-div | add | sub
add = add-sub spaces? <'+'> spaces? mult-div
sub = add-sub spaces? <'-'> spaces? mult-div
<mult-div> = factor | mult |div
mult = mult-div spaces? <'*'> spaces? factor
View lang0-parser.cljs
(def lang0-parser
(instaparse.core/parser
"prog = (spaces? expr spaces? <';'> spaces?)*
<expr> = assig | add-sub
assig = varname spaces? <'='> spaces? expr
<add-sub> = mult-div | add | sub
add = add-sub spaces? <'+'> spaces? mult-div
sub = add-sub spaces? <'-'> spaces? mult-div
<mult-div> = factor | mult |div
mult = mult-div spaces? <'*'> spaces? factor
View arith-parser.cljc
(def arith-parser
(instaparse.core/parser
"prog = spaces? add-sub spaces?
<add-sub> = mult-div | add | sub
add = add-sub spaces? <'+'> spaces? mult-div
sub = add-sub spaces? <'-'> spaces? mult-div
<mult-div> = term | mult | div
mult = mult-div spaces? <'*'> spaces? term
div = mult-div spaces? <'/'> spaces? term
<term> = number | <'('> add-sub <')'>
View add-mult-parser.cljc
(def addmult-parser
(instaparse.core/parser
"prog= spaces? add-sub spaces?
<add-sub> = mult-div | add | sub
add= add-sub spaces? <'+'> spaces? mult-div
sub= add-sub spaces? <'-'> spaces? mult-div
<mult-div> = number | mult | div
mult= mult-div spaces? <'*'> spaces? number
div= mult-div spaces? <'/'> spaces? number
number= #'-?[0-9]+'
View add-sub-parser.cljc
(def addsub-parser
(instaparse.core/parser
"prog= spaces? add-sub spaces?
<add-sub> = number | add | sub
add= add-sub spaces? <'+'> spaces? number
sub= add-sub spaces? <'-'> spaces? number
number= #'-?[0-9]+'
<spaces> = <#'\\s+'>"))
View lang0-parser.cljs
(def const-parser
(instaparse.core/parser
"prog= spaces? number spaces?
number=#'-?[0-9]+'
<spaces> = <#'[\\s]'+>"))
(const-parser " -123456 ")
View quicksort.java
public static void swap(int[] data, int i, int j){
int tmp= data[i];
data[i]= data[j];
data[j]= tmp;
}
public static int partition(int[] data, int begin, int end, int pivotIdx){
swap(data, pivotIdx, --end);
pivotIdx= end;
int pivot= data[pivotIdx];
View core.clj
(ns kingdomino.core
(:require [instaparse.core :as insta])
(:gen-class))
(def size 100)
(def delta-sides 5)
(def ncols 2)
(def delta-dominos 10)
(def colors {:clay "#cc6600" :field "#ffff66" :water "#33ccff" :pasture "#00cc00" :forest "#669900" :mine "#5c5c3d"})
View chaos-polygons.cxx
#include <iostream>
#include <tuple>
#include <cmath>
#include <cstdlib>
#include <iterator>
#include <vector>
#include <algorithm>
#include <string>
// STEPS=100;for i in $(seq $((3 * $STEPS)) $((8 * $STEPS))); do ./chaos-polygons $(bc -l <<< "scale=2;$i / $STEPS") > generated-cmax-100-$i.pgm; done
// for i in generated-cmax-100-*.pgm; do convert $i ${i%.pgm}.png; done
View core.clj
(ns clojr.core
(:require [instaparse.core :as insta])
(:import (clojure.lang DynamicClassLoader)))
(import '[clojure.asm ClassWriter Type Opcodes]
'[clojure.asm.commons Method GeneratorAdapter])
(def parser
(insta/parser
"prog = expr (<#'[\\n]+'> expr?)*