generalized HAM parsing