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
| let () = Printexc.record_backtrace true | |
| (* Turn a regular expression from Regenerate into an RE one. *) | |
| let rec to_re r = | |
| let open Regenerate.Regex in | |
| let open Regex in | |
| let concatenation_iter i re = | |
| 1 -- (i - 1) | |
| |> List.fold_left (fun acc _ -> RE.concat re acc) re | |
| in |
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 DFA2 : Matching = struct | |
| type t1 = (int * state) ref | |
| and state = | |
| | Split of t1 * t1 | |
| | CharSet of CSet.t * t1 | |
| | Match | |
| module S = | |
| Set.Make( | |
| struct |
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
| let rec factorial n = | |
| if n = 0 then 1 | |
| else n * factorial (n - 1) | |
| let rec factorial_acc n acc = | |
| if n = 0 then acc | |
| else factorial_acc (n - 1) (n * acc) | |
| let rec factorial_cont n k = | |
| if n = 0 then k 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
| (** [explode s] returns the list of the characters of the string [s]. | |
| For example, [explode "hello"] is ['h'; 'e'; 'l'; 'l'; 'o']. *) | |
| let explode s = | |
| List.init (String.length s) (fun i -> String.get s i) | |
| let implode l = | |
| let res = Bytes.create (List.length l) in | |
| let rec imp i = function | |
| | [] -> () | |
| | c :: l -> Bytes.set res i c; imp (i + 1) l in |
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
| import sys | |
| import re | |
| s = sys.argv[1] | |
| s = re.sub('⟮', '(', s) | |
| s = re.sub('⟯', ')', s) | |
| s = re.sub('│', '|', s) | |
| s = re.sub('⭑', '*', s) | |
| s = re.sub('⁺', '+', s) | |
| s = re.sub('?', '?', s) |
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 graph = bool array array | |
| let example () = | |
| [| (* 0 1 2 3 4 *) | |
| (*0*) [| true; true; false; true; false; |]; | |
| (*1*) [| false; true; true; false; false; |]; | |
| (*2*) [| false; false; true; false; false; |]; | |
| (*3*) [| false; false; false; true; true; |]; | |
| (*4*) [| true; false; false; false; true; |]; | |
| |] |
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
| { | |
| open Lexing | |
| open Printf | |
| let newline lexbuf = | |
| let pos = lexbuf.lex_curr_p in | |
| lexbuf.lex_curr_p <- | |
| { pos with pos_lnum = pos.pos_lnum + 1; pos_bol = pos.pos_cnum } | |
| let error lexbuf msg = |
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
| rule clean = parse | |
| | '\t' | |
| { | |
| print_string " "; | |
| clean lexbuf | |
| } | |
| | (' ' | '\t')* '\n' | |
| { | |
| print_newline (); | |
| clean lexbuf |
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 <iostream> | |
| #include <vector> | |
| #include <map> | |
| #include <variant> | |
| #include <exception> | |
| #include <fstream> | |
| using namespace std; | |
| void debug(auto f) { |
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 <iostream> | |
| #include <vector> | |
| using namespace std; | |
| int main() | |
| { | |
| vector<vector<int>> dfa | |
| { | |
| // a b |