Redo cycle detection

Instead of breaking cycles in the automaton we detect them during expression
construction which allows us to handle them more gracefully.

Change-Id: I3485ae3ca14af8bf0a5f30617de0dcc26bb9f049