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.
-
21:40
Bitcoin Policy Institute
7 hours agoCongressman Warren Davidson Unveils the “Bitcoin for America Act” | Spotlight Series #1
27.1K -
LIVE
LFA TV
21 hours agoLIVE & BREAKING NEWS! | THURSDAY 11/20/25
1,049 watching -
LIVE
freecastle
8 hours agoTAKE UP YOUR CROSS- Let your eyes LOOK directly FORWARD, and your gaze be STRAIGHT before YOU!
26 watching -
1:25:51
DeVory Darkins
6 hours agoDemocrats caught in corruption scheme as JD Vance issues MAJOR UPDATE
155K76 -
1:48:48
MattMorseTV
6 hours ago $41.25 earned🔴Sedition Charges INBOUND.🔴WH Press Conference.🔴
69K176 -
9:06
Jamesons Travels
22 hours ago $5.39 earnedMilitary Veterans in Congress Tell Troops to Refuse Trump's Orders
39.1K62 -
1:42:47
The Bold Lib
4 hours agoBOLDCHAT: Unemployment | AI | Birth Rates w/ANGELA BELCAMINO
27K2 -
20:34
ArynneWexler
8 hours agoNew Poll: Women Are Done With America | NN8
29.1K47 -
59:30
The White House
7 hours agoPress Secretary Karoline Leavitt Briefs Members of the Media, Nov. 20, 2025
67.1K32 -
2:06:37
Steven Crowder
9 hours agoJasmine Crockett's Epstein Idiocy & the Absolute State of the Democrat Party
636K434