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
Akademiks
4 hours agoMeg Thee Stallion spent $2 mil on lawyers to win $59k vs Milagro! 50 Cent BURIES Diddy. SNAKES HIM!
1,064 watching -
LIVE
SpartakusLIVE
4 hours agoI'M BACK from Florida || The RETURN to the Spartan Stronghold
482 watching -
1:38:45
Joker Effect
3 hours agoWhy is everything so DIFFICULT?! Cuffem, Gypsy Crusader, WVAGABOND is getting SUED?! IDuncle is mad!
23.5K1 -
54:46
Flyover Conservatives
23 hours agoInside the Kill Zones: Kidnappings, Camps & the War on Nigerian Christians Exposed - Judd Saul | FOC Show
20.6K1 -
1:02:35
MattMorseTV
5 hours ago $20.94 earned🔴We just got the CONFIRMATION.🔴
38.4K74 -
1:24:52
Glenn Greenwald
7 hours agoTrump Admin Preparing for New Regime-Change War Against Venezuela; Who Should Win Anti-Semite of the Year? See the Top 10 Finalists | SYSTEM UPDATE #551
117K67 -
23:12
Jasmin Laine
9 hours agoCBC TURNS on Carney—Poilievre Speech Goes VIRAL, ROASTS Canada’s Elites
28.1K17 -
1:16:21
The Daily Signal
7 hours ago $4.12 earned🚨BREAKING: Tim Walz Self-Destructs Over BILLIONS in Fraud Under His Watch, War Crime Allegations
25.2K8 -
9:08
China Uncensored
10 hours agoIndia And China Are Headed To Another War
10.7K10 -
12:04
Vedic compatability astrology
5 hours ago"My Persian grandmother's secret beauty potions now on Amazon"
7.79K