handle segfault when handling grammar