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
package main | |
import ( | |
"time" | |
) | |
func main() { | |
} | |
// The essential of the code piece is this interface. |
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
package main | |
import ( | |
"fmt" | |
) | |
type Expression struct { | |
OP byte | |
X interface{} | |
Y interface{} |
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
package main | |
import "fmt" | |
import "time" | |
import "math/rand" | |
var jumpTable = [32]func(){ | |
noop, noop, noop, noop, | |
noop, noop, noop, noop, | |
noop, noop, noop, noop, |
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 Ast = struct | |
type t = | |
Int of int | |
| Bool of bool | |
| Var of string | |
| App of t * t | |
| Fun of string * t | |
| If of t * t * t | |
| Plus of t * t | |
| Equal of t * t |
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
type 'a parser_t = char list -> ('a * char list) option | |
let satisfy pred = function [] -> None | x::xs -> if pred x then Some(x,xs) else None;; | |
let range a b = satisfy (fun x -> x>=a && x <=b);; | |
let exactly x = satisfy ((=) x);; | |
let (<|>) p q = fun x -> match p x with Some _ as res -> res | None -> q x;; | |
let (>>=) m f = fun l -> match m l with | |
| None -> None | |
| Some(res, l1) -> f res l1;; | |
let return x = fun l -> Some(x, l);; |
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
// search a trie to scan a token | |
ch := ch0 | |
node := &ruleTable | |
for { | |
if node.childs[ch] == nil || s.r.eof() { | |
break | |
} | |
node = node.childs[ch] | |
s.r.inc() | |
ch = s.r.peek() |
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
switch ch0 { | |
case '|': | |
s.r.inc() | |
if s.r.peek() == '|' { | |
s.r.inc() | |
return oror | |
} | |
return '|' | |
case '&': | |
s.r.inc() |
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
#lang racket | |
(define ready-queue '()) | |
(define list-append | |
(lambda (ls x) | |
(if (null? ls) | |
(cons x '()) | |
(cons (car ls) (list-append (cdr ls) x))))) | |
;; 定义队列操作的函数 |
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
#lang racket | |
;;定义阶乘函数 | |
(define (fact n) | |
(if (= n 1) | |
1 | |
(* n (fact (- n 1))))) | |
;;由于我们不能使用define,那么把fact作为参数名 | |
(lambda (f) | |
(lambda (n) |
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 <stdio.h> | |
#include <sys/socket.h> | |
#include <errno.h> | |
#include <string.h> | |
#include <sys/types.h> | |
#include <netinet/in.h> | |
#include <arpa/inet.h> | |
#include <unistd.h> | |
int child(int, int); |