3 ms·
Ken Thompson's regular-expression matcher also worked this way. It used two arrays of jump instructions: one jump for each current NFA state, jumping into the m
by abecedarius 12y ago
Ken Thompson's regular-expression matcher also worked this way. It used two arrays of jump instructions: one jump for each current NFA state, jumping into the machine code that had been compiled for the regex. These jumps were actually calls using self-modifying code as in the OP (but for IBM 709 instead of MIX). But the new wrinkle was, it also wrote more jump instructions into the other array, for the next-state set of the NFA matcher.
Unlike the MIX, the IBM 709 had a jump-through-register instruction, so self-modifying code wasn't necessary. I found that Thompson's code could've been more compact and about as fast (sometimes faster, sometimes slower) using such indirect jumps only, at the cost of needing to use all of the registers.
- abecedarius 12y ago(The compiled code for an NFA state could append jump instructions to the current state set as well as the next-state set, to implement the | operator. Just noting this for completeness.)