Skip to content

Instantly share code, notes, and snippets.

View SimonMeskens's full-sized avatar

Simon Meskens SimonMeskens

View GitHub Profile
@SimonMeskens
SimonMeskens / stream-machines.md
Created February 5, 2025 01:15
WIP - Stream automata for a turing machine equivalent to concatenative programming.

Copyright 2025 Simon Meskens Licensed under the MIT License

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided this license is preserved. This software is offered as-is, without any warranty.

Stream Machine: An abstract machine with a transition table, no machine state and a finite number of lazy stacks. One of the stacks is the program stack and after each transition, the top of the program stack is popped off.

@SimonMeskens
SimonMeskens / lambdastack.js
Last active February 5, 2025 01:06
Defunctionalized continuations in JS using algebraic data types
// Copyright 2025 Simon Meskens
// Licensed under the MIT License
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided this license is
// preserved. This software is offered as-is, without any warranty.
// Based on: https://www.youtube.com/watch?v=O6s8_4agu4c
// https://gist.github.com/paf31/16f25ef70eaf256fbf301b571db6d533
@SimonMeskens
SimonMeskens / direct.zig
Last active February 5, 2025 01:07
Threaded code in Zig
// Copyright 2024 Simon Meskens
// Licensed under the MIT License
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided this license is
// preserved. This software is offered as-is, without any warranty.
// https://godbolt.org/z/TK5r79esP
pub const VM = struct {
code: []const Inst,

Pick either the second or third paragraph and the final one is optional.

Copyright (c) 2024 «AUTHORS»

In the name of a free and open culture, you may do anything with this software that copyright law would normally restrict, provided this license is preserved. This software is offered as-is, without any warranty.

To the extent permitted under applicable law, worldwide, all copyright holders fully waive their copyrights to this software and dedicate it to the public domain.

This software or any derivatives of this software can only be distributed with their source code publicly available; software that is distributed with this software as part of it should also require the same. Services can only make use of this software provided that any modifications are publicly available.

const top = (stack) => stack.length - 1;
const zero = ({ left }) => left.push(0);
const pop = ({ right }) => right.pop();
const increment = ({ left }) => (left[top(left)] = (left[top(left)] + 1) % 256);
const decrement = ({ left }) =>
(left[top(left)] = (left[top(left)] + 255) % 256);
const shift = ({ left, right }) => right.push(left.pop());
@SimonMeskens
SimonMeskens / UTF-8
Last active February 4, 2025 06:01
UTF-8 Explained using one diagram
UTF-8 Code point: a bb bb cc cc dd dd ee ee ff ff
0 e ee ff ff
10 ------- ----------- ---- ERROR -----------
110 d dd ee 10 ee ff ff
1110 cc cc 10 dd dd ee 10 ee ff ff
11110 a bb 10 bb cc cc 10 dd dd ee 10 ee ff ff
111110 ------- ----------- ---- ERROR -----------
@SimonMeskens
SimonMeskens / 00Pattern.purs
Last active February 5, 2025 01:07
Brzozowski derivatives in PureScript - MIT License
module Patterns
( Pattern(..)
, unite
, concat
, repeat
, complement
, derivative
) where
import Data.Boolean (otherwise)
@SimonMeskens
SimonMeskens / lexer.js
Last active February 5, 2025 01:09
JavaScript climbing parser
// Copyright 2023 Simon Meskens
// Licensed under the MIT License
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided this license is
// preserved. This software is offered as-is, without any warranty.
const types = [
[null, /[^\P{Pattern_White_Space}\n]+/msuy],
["break", /\n/msuy],
@SimonMeskens
SimonMeskens / parser.js
Last active April 29, 2022 00:43
Tiny Parser Combinator Library
/*
Copyright 2022 Simon Meskens
Permission to use, copy, modify, and/or distribute this software for any purpose with
or without fee is hereby granted, provided this license is preserved. This software is
offered as-is, without any warranty.
Generate your own tiny license:
https://simonmeskens.github.io/SimpleLicenseCollection/
*/

Design challenge: design or share a regular expression DSL

Design a syntax for an alternative to classic regex. You can also share interesting existing solutions. An example of a regular expression to try implementing is the JSON number spec:

n = /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/

All the examples here are licensed CC0. If you would like to share a solution for addition to this gist (and later a repository), send it to me and mention that you license it under CC0. If you would like to be attributed, mention under what name.

Existing solutions