Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
DmitrySoshnikov / lr0-items.js
Last active February 15, 2023 14:56
LR Parsing: Canonical collection of LR(0) items
/**
* LR-parsing.
*
* Canonical collection of LR(0) items.
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style License (C) 2015
*
* See this "rock-painting" to get the picture of what we're building here:
*
@DmitrySoshnikov
DmitrySoshnikov / LL1-parsing-table.js
Last active February 15, 2023 14:55
LL(1) Parser. Parsing table, part 2: building the table from First and Follow sets.
/**
* Building LL(1) parsing table from First and Follow sets.
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style License
*
* This diff is a continuation of what we started in the previous two diffs:
*
* Dependencies:
*
@DmitrySoshnikov
DmitrySoshnikov / LL-parser.js
Last active February 15, 2023 14:54
LL-parser
/**
* = LL parser =
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style license
*
* Often one can see manually written LL parsers implemented as
* recursive descent. Approach in this diff is a classical parse table
* state machine.
*
/**
* int16, and uint16 numbers in JS.
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*/
const assert = require('assert');
/**
* Converts a number to signed 16-bit integer.
@DmitrySoshnikov
DmitrySoshnikov / reference-counting-gc.js
Last active September 30, 2022 00:19
Reference counting GC
/**
* Automatic Reference Counting (ARC) Garbage Collection technique.
*
* This diff describes Reference counting GC technique.
* See also previous lesson on Mark and Sweep GC:
* https://gist.github.com/4391763
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style License
*/
@DmitrySoshnikov
DmitrySoshnikov / postfix-eval.js
Created September 23, 2011 19:54
Simple postfix notation math evaluator
/**
* Postfix notation math evaluator
* See: http://en.wikipedia.org/wiki/Reverse_Polish_notation
*
* See also prefix notation example:
* https://github.com/DmitrySoshnikov/Essentials-of-interpretation/blob/master/src/notes/note-1.js
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style License
*/
@DmitrySoshnikov
DmitrySoshnikov / agent-smith.js
Last active April 5, 2022 19:32
Agents example
// agent-smith.js
/**
* Receive shared array buffer in this worker.
*/
onmessage = (message) => {
// Worker's view of the shared data.
let heapArray = new Int32Array(message.data);
let indexToModify = 1;
@DmitrySoshnikov
DmitrySoshnikov / stack-vm-recursion.js
Last active March 23, 2022 07:09
Educational Stack-based VM with recursion example
/**
* Educational Stack-based VM.
*
* See also:
* - A simplified example without recursion: https://gist.github.com/DmitrySoshnikov/76e1cfb930df8d36145c
* - Register-based VM example: https://gist.github.com/DmitrySoshnikov/6407781
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* http://dmitrysoshnikov.com
* MIT Stye License (C) 2015
@DmitrySoshnikov
DmitrySoshnikov / rust-dynamic-lazy-static.md
Last active January 22, 2022 05:29
Rust notes: dynamic and global static objects

Rust notes: dynamic and global static objects

Level: novices, n00bs

Rust is a statically typed language, which helps preventing runtime bugs, and ensures memory safety at compile time, that is with no runtime costs. However, sometimes one may need using dynamic values. Also, Rust doesn't support "out of the box" complex static structures, which still can be solved with some lazy initialization tricks.

Below are some notes on dynamic data types, and global static objects in Rust programming language.

Dynamic objects

@DmitrySoshnikov
DmitrySoshnikov / Map.prototype.map.md
Last active January 3, 2022 15:41
Map.prototype.map

Map.prototype.map ( callbackfn [ , thisArg ] )

The map method calls MapTransform abstract operation passing this value as M, callbackfn, thisArg as is, and false as updateKey.

The length property of the map method is 1.

Map.prototype.mapEntries ( callbackfn [ , thisArg ] )

The mapEntries method calls MapTransform abstract operation passing this value as M, callbackfn, thisArg as is, and true as updateKey.