This file contains 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
from functools import namedtuple | |
from pprint import pprint | |
class ParseError(BaseException): pass | |
def recursive_descent_matcher(rules, start, index, tokens, debug=False): | |
def iseof(tokens, idx): | |
try: | |
x = tokens[idx] |
This file contains 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
from functools import namedtuple | |
from pprint import pprint | |
class ParseError(BaseException): pass | |
def recursive_descent_matcher(rules, start, index, tokens, debug=False): | |
def iseof(tokens, idx): | |
try: | |
x = tokens[idx] |
This file contains 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
bneg = lambda x: ('~', x) | |
band = lambda x, y: ('and', x, y) | |
bor = lambda x, y: ('or', x, y) | |
imp = lambda x, y: bor(bneg(x), y) | |
iff = lambda x, y: band(imp(x,y), imp(y,x)) | |
v = lambda x: ('var', x) | |
b0 = lambda x: band(x, bneg(x)) | |
This file contains 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 <iostream> | |
#include <mutex> | |
#include <thread> | |
#include <condition_variable> | |
using namespace std; | |
template<typename T> | |
class channel | |
{ |
This file contains 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
template <typename State, typename ...Trans> struct FSMRunner; | |
template <typename State, typename T, typename ...Ts> struct FSMRunner<State, T, Ts...> { | |
inline static void step(State &state) { | |
if (T::from == state && T::precond()) { | |
T::action(); | |
state = T::to; | |
} else { | |
FSMRunner<State, Ts...>::step(state); | |
} |
This file contains 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 <cstdint> | |
#include <iostream> | |
using namespace std; | |
/* | |
* Returns the bits in range msb to lsb from bits. The returned bits are | |
* shifted to the least signifcant bit. The bits are ordered from most to | |
* least signifcant bit; where the most signifcant bit has the index <number of | |
* bits> - 1 and the least has 0. | |
* |
This file contains 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 <iostream> | |
#include <functional> | |
using namespace std; | |
template <typename A, typename B> | |
class Either { | |
private: | |
// In a language with lambdas, a disjoint union can be implemented using |