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.
-
12:54
Brad Owen Poker
14 hours ago $2.82 earnedI Make Final Table! I’m Going To $10,400 WPT World Championship!!
22.6K1 -
10:00
TheMightyMcClures
22 days ago $2.55 earnedWe Fed 500 Families!
24.1K4 -
6:23
The Shannon Joy Show
14 hours agoWas Covid a MILITARY OPERATION?
21.9K10 -
LIVE
The Bubba Army
23 hours agoTRUMP SIGNS EPSTEIN BILL! - Bubba the Love Sponge® Show | 11/20/25
1,365 watching -
27:24
DeVory Darkins
22 hours agoTrump secures RECORD BREAKING INVESTMENT as Charlotte Schools issue SHOCKING Update
47K49 -
34:15
ZeeeMedia
18 hours agoPolice Demand Government Critic Hands Over His BLOOD | Daily Pulse Ep 147
75.4K41 -
1:47:50
Side Scrollers Podcast
17 hours agoSide Scrollers Presents: OVERCOCKED
42.6K14 -
3:33:22
HLL8LLY
6 hours ago $1.73 earnedBattlefield 6 Live Gameplay
14.6K3 -
34:04
Code Blue Cam
21 hours agoTeen Plays Real-Life GTA… Ends Horrifically
31.7K11 -
13:33
MattMorseTV
19 hours ago $37.95 earnedThey actually TOOK THE BAIT…
90.9K72