Code Monkey home page Code Monkey logo

russ_cox_regexp's Introduction

russ_cox_regexp

Russ Cox wrote a wonderful series of articles Implementing Regular Expressions between 2007-2012 available at https://swtch.com/~rsc/regexp. The first articles point out a critical flaw in some of the most popular regular expression engines of the era that were based on backtracking. Russ contrasts the standard backtracking designs with algorithms based on finite automata. He implements versions of these differing designs, some combining multiple approaches.

There are links to source code throughout the articles and on the home page. But the sources are plain files in the webpage directory and not easy to browse or discover.

I've collected the files here for easier access.

  • dfa0.c - Generates DFA states each equivalent to possibly multiple NFA states as needed while executing the NFA as in nfa.c. DFA states are arranged in a binary search tree that acts as a cache. A DFA state is only computed if not already present in the tree. DFA states are ordered by the list of states they represent. Lists of states are sorted by the address of each state node. Two lists are equal if they contain exactly the same state nodes.

  • dfa1.c - Limits the tree of DFA states cache from dfa0.c to 32 entries to bound memory use. The cache is completely cleared if more than 32 DFA states are needed. And the tree is filled anew.

  • nfa.c - Implements Ken Thompson's algorithm to generate and run NFA for regular expression. Multiple possible next NFA states are executed in lockstep beginning with the start state.

  • nfa-perl.y - NFA-based regex engine with group captures that follow Perl behavior. Program has yacc parser for regex

  • nfa-posix.y - NFA-based regex engine with group captures that follow Posix behavior. Program has yacc parser for regex

  • regexp-bytecode.c - NFA represented as bytecode instructions for a virtual machine

  • regexp-x86.c - NFA represented as x86 instructions

  • ibm-7094.html - Description and instructions of IBM 7094 architecture

  • LICENSE - MIT License

  • timing/ - scripts to measure performance of different regex engines

russ_cox_regexp's People

Contributors

zmajeed avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.