basic grammar correctness check and unnecessary productions remove