Why does this take so long to match? Is it a bug?

There is some catastrophic backtracking going on that will cause an exponential amount of processing depending on how long the non-match string is. This has to do with your nested repetitions and optional comma (even though some regex engines can determine that this wouldn’t be a match with attempting all of the extraneous repetition). This … Read more

Short example of regular expression converted to a state machine?

A rather convenient way to help look at this to use python’s little-known re.DEBUG flag on any pattern: >>> re.compile(r'<([A-Z][A-Z0-9]*)\b[^>]*>(.*?)</\1>’, re.DEBUG) literal 60 subpattern 1 in range (65, 90) max_repeat 0 65535 in range (65, 90) range (48, 57) at at_boundary max_repeat 0 65535 not_literal 62 literal 62 subpattern 2 min_repeat 0 65535 any None … Read more

How to implement a FSM – Finite State Machine in Java

The heart of a state machine is the transition table, which takes a state and a symbol (what you’re calling an event) to a new state. That’s just a two-index array of states. For sanity and type safety, declare the states and symbols as enumerations. I always add a “length” member in some way (language-specific) … Read more

state machines tutorials [closed]

State machines are very simple in C if you use function pointers. Basically you need 2 arrays – one for state function pointers and one for state transition rules. Every state function returns the code, you lookup state transition table by state and return code to find the next state and then just execute it. … Read more

Simple state machine example in C#?

Let’s start with this simple state diagram: We have: 4 states (Inactive, Active, Paused, and Exited) 5 types of state transitions (Begin Command, End Command, Pause Command, Resume Command, Exit Command). You can convert this to C# in a handful of ways, such as performing a switch statement on the current state and command, or … Read more

C state-machine design [closed]

State machines that I’ve designed before (C, not C++) have all come down to a struct array and a loop. The structure basically consists of a state and event (for look-up) and a function that returns the new state, something like: typedef struct { int st; int ev; int (*fn)(void); } tTransition; Then you define … Read more