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.
-
LIVE
SpartakusLIVE
2 hours ago#1 Hacker/Scammer PLUNGES into CRYPTO || !crypto !spartacoin
270 watching -
53:15
Kimberly Guilfoyle
5 hours agoCalifornia Residents Demand Answers, Live with Rep Vince Fong, Mike Davis, and Paul Peterson | Ep. 188
40.8K55 -
1:49:51
Redacted News
4 hours agoEMERGENCY! 10 MILLION UNDER FIRE WARNING & 100 MPH WINDS, NEWSOM UNVEILS CALIFORNIA 2.0 PLAN
125K164 -
49:33
Candace Show Podcast
4 hours agoI Respond To Mr. And Mr. Macron | Candace Ep 131
99.6K237 -
1:58:04
Revenge of the Cis
5 hours agoEpisode 1429: Catch And Release
37.4K2 -
2:00:01
Film Threat
10 hours agoVERSUS: HOLLYWOOD IS STILL ON FIRE | Film Threat Versus
22K1 -
12:33
Silver Dragons
4 hours agoSilver Price Crushed Today - NEW TREND STARTING?
20.2K2 -
1:02:03
In The Litter Box w/ Jewels & Catturd
23 hours agoRecall Newscum & Bass! | In the Litter Box w/ Jewels & Catturd – Ep. 718 – 1/13/2025
97.2K36 -
3:19:58
Tate Speech by Andrew Tate
11 hours agoEMERGENCY MEETING EPISODE 101 - STRENGTH AND HONOR
193K70 -
1:48:09
The Quartering
7 hours agoLA Fires Are About To Get Way Worse, Trump Vs Vance On J6 Pardons, Brett Cooper Bombshell & More
118K50