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.
-
28:37
marcushouse
22 hours ago $8.93 earnedSpaceX Just Dropped the Biggest Starship Lander Update in Years! 🤯
26.8K9 -
14:54
The Kevin Trudeau Show Limitless
3 days agoThe Hidden Force Running Your Life
109K25 -
2:16:35
DLDAfterDark
9 hours ago $10.00 earnedIs The "SnapPocalypse" A Real Concern? Are You Prepared For SHTF? What Are Some Considerations?
28.1K11 -
19:58
TampaAerialMedia
21 hours ago $9.45 earnedKEY LARGO - Florida Keys Part 1 - Snorkeling, Restaurants,
44.1K19 -
1:23
Memology 101
2 days ago $8.80 earnedFar-left ghoul wants conservatives DEAD, warns Dems to get on board or THEY ARE NEXT
35K69 -
3:27:27
SavageJayGatsby
11 hours ago🔥🌶️ Spicy Saturday – BITE Edition! 🌶️🔥
60.2K7 -
26:09
Exploring With Nug
21 hours ago $12.58 earned13 Cold Cases in New Orleans What We Discovered Beneath the Surface!
55.2K27 -
27:39
MYLUNCHBREAK CHANNEL PAGE
15 hours agoDestroying Time.
137K42 -
3:27:19
Mally_Mouse
11 hours ago🌶️ 🥵Spicy BITE Saturday!! 🥵🌶️- Let's Play: Minecraft Christmas Adventure!!
135K12 -
2:14:31
Side Scrollers Podcast
16 hours agoSide Scrollers INVITE ONLY - Live From Dreamhack
161K16