Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
DmitrySoshnikov / infix-to-postfix-regexp.js
Created Sep 24, 2011
Infix to postfix notation RegExp converter
View infix-to-postfix-regexp.js
/**
* Infix to postfix notation RegExp converter
*
* To implement RegExp machine (NFA, DFA) we need
* to transform first RegExp string to postfix notation
* for more convinient work with the stack. This function
* does exactly this.
*
* See: http://swtch.com/~rsc/regexp/regexp1.html
*
@hilukasz
hilukasz / Selected_layers-PS.jsx
Last active May 5, 2021
get array of selected layers in photoshop via extendscript
View Selected_layers-PS.jsx
var docRef = app.activeDocument;
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
function newGroupFromLayers(doc) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( sTID('layerSection') );
@DmitrySoshnikov
DmitrySoshnikov / stack-vm.js
Last active Mar 28, 2022
Educational Stack-based Virtual Machine
View stack-vm.js
/**
* Educational Stack-based VM.
*
* See also:
* - More complex example with recursion: https://gist.github.com/DmitrySoshnikov/afda459222e96e6002ac
* - 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
View LL-parser.js
/**
* = 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.
*
@DmitrySoshnikov
DmitrySoshnikov / LL1-parser-first-follow-sets.js
Last active Feb 27, 2022
LL(1) Parser. Parsing table, part 1: First and Follow sets.
View LL1-parser-first-follow-sets.js
/**
* LL(1) parser. Building parsing table, part 1: First and Follow sets.
*
* NOTICE: see full implementation in the Syntax tool, here:
* https://github.com/DmitrySoshnikov/syntax/blob/master/src/sets-generator.js
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style License
*
* An LL(1)-parser is a top-down, fast predictive non-recursive parser,
@DmitrySoshnikov
DmitrySoshnikov / LL1-parsing-table.js
Last active Nov 26, 2021
LL(1) Parser. Parsing table, part 2: building the table from First and Follow sets.
View LL1-parsing-table.js
/**
* 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 / lr0-items.js
Last active Jun 1, 2021
LR Parsing: Canonical collection of LR(0) items
View lr0-items.js
/**
* 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:
*
View NFA.js
/**
* NFA (Non-deterministic finite automata)
*
* A formalism for regular grammars (to recognize strings based on regular
* expressions).
*
* Regexp parser to transform AST to NFA:
* https://www.npmjs.com/package/regexp-tree
*
* NFA/DFA fragment examples:
@DmitrySoshnikov
DmitrySoshnikov / NFA-DFA-RegExp.js
Last active May 21, 2021
Classic RegExp implementation (NFA, DFA)
View NFA-DFA-RegExp.js
/**
* Classic RegExp implementation (NFA, DFA).
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT License, 2017
*/
/**
* Epsilon.
*/
@luchy0120
luchy0120 / thompson_nfa.c
Last active Aug 21, 2019
NFA Thompson Construction by Russ Cox
View thompson_nfa.c
/*
* Regular expression implementation.
* Supports only ( | ) * + ?. No escapes.
* Compiles to NFA and then simulates NFA
* using Thompson's algorithm.
*
* See also http://swtch.com/~rsc/regexp/ and
* Thompson, Ken. Regular Expression Search Algorithm,
* Communications of the ACM 11(6) (June 1968), pp. 419-422.
*