Premium Only Content
Compiler From Scratch: Phase 1 - Tokenizer Generator 004: Regex Pattern to NFA
Streamed on 2024-08-09 (https://www.twitch.tv/thediscouragerofhesitancy)
Zero Dependencies Programming!
With some stolen code out of the way to store all of our state I can start the Pattern to NFA processing. This process involves stepping through a regex pattern one character at a time. Depending on the character we either add a "fragment" to our list of fragments, or we update some state, like "Are we inside square brackets?" or "Are we escaping the next character?".
Then we run through the list multiple times, once for each precedence of operator. If an operator at the current precedence level is found, we reduce the list by moving any neighboring elements to the proper relationship under the current operator. If everything parses correctly, we end up with one fragment at the end which contains the root state of our NFA. A decent amount of code was stolen from my old sandbox as there is a lot of detailed bookkeeping involved in these processes.
I then added the ability to log the NFA as a formatted table, as well as a tree. I think the table is easier to read and trace.
Then I started adding new features to my Regex to NFA converter, starting with non-greedy modifiers. The cardinality operators (+, *, and ?) can be made non-greedy by putting "?" after them. Strangely, this is a very simple change that just involves swapping the left and right out pointers for the given state. However, during this change I found a bug in my "+" implementation which I had to fix, and due to the time elapsed since I had last played in the sandbox, it took me longer than it should have. But in the end, I got it all working.
-
46:26
Sarah Westall
12 hours agoWhat’s Behind the Silver Surge? Large Institutions Cashing In w/ Andy Schectman
47.8K3 -
6:42:10
Turning Point USA
17 hours agoLIVE NOW: AMFEST DAY 2 - VIVEK, JACK POSOBIEC, MEGYN KELLY, ALEX CLARK AND MORE…
1.32M189 -
1:14:37
Flyover Conservatives
1 day agoHow to Win 2026 Before It Starts — Clay Clark’s Goal-Setting Blueprint | FOC Show
48.2K1 -
12:52
The Kevin Trudeau Show Limitless
2 days agoBeyond Good And Bad: The Hidden Reality Code
95.6K21 -
1:03:11
BonginoReport
13 hours agoBrown U Security Failures EXPOSED - Nightly Scroll w/ Hayley Caronia (Ep.201)
168K49 -
51:09
Patriots With Grit
9 hours agoWill A.I. Replace Doctors? | Dr. Stella Immanuel MD
31.6K4 -
4:10:32
Nerdrotic
15 hours ago $18.19 earnedHollywood's DOOMSDAY! WB FIRESALE! - Friday Night Tights 385 w Zachary Levi
90K22 -
12:25:53
LFA TV
1 day agoLIVE & BREAKING NEWS! | FRIDAY 12/19/25
208K31 -
1:08:59
Edge of Wonder
12 hours agoNASA’s Intergalactic Spacecraft, Real Dwarves Spotted & Research Roundup
31.9K7 -
1:21:27
Kim Iversen
14 hours agoPutin Says Russia is Ready for WAR With Europe
51.5K105