completed left recursion removal.
some basic checks may be missing, will be improved in later commits