Fixed left recursion detection algorithm