add infinite recursion checking to BNF parser