protected boolean error_recovery(boolean debug) throws java.lang.Exception {
  if (debug)   debug_message("# Attempting error recovery");
  if (!find_recovery_config(debug)) {
    if (debug)     debug_message("# Error recovery fails");
    return false;
  }
  read_lookahead();
  for (; ; ) {
    if (debug)     debug_message("# Trying to parse ahead");
    if (try_parse_ahead(debug)) {
      break;
    }
    if (lookahead[0].sym == EOF_sym()) {
      if (debug)       debug_message("# Error recovery fails at EOF");
      return false;
    }
    if (debug)     debug_message("# Consuming Symbol #" + lookahead[0].sym);
    restart_lookahead();
  }
  if (debug)   debug_message("# Parse-ahead ok, going back to normal parse");
  parse_lookahead(debug);
  return true;
}

protected boolean error_recovery ( boolean debug ) throws java . lang . Exception { if ( debug ) debug_message ( "# Attempting error recovery" ) ; if ( ! find_recovery_config ( debug ) ) { if ( debug ) debug_message ( "# Error recovery fails" ) ; return false ; } read_lookahead ( ) ; for ( ; ; ) { if ( debug ) debug_message ( "# Trying to parse ahead" ) ; if ( try_parse_ahead ( debug ) ) { break ; } if ( lookahead [ 0 ] . sym == EOF_sym ( ) ) { if ( debug ) debug_message ( "# Error recovery fails at EOF" ) ; return false ; } if ( debug ) debug_message ( "# Consuming Symbol #" + lookahead [ 0 ] . sym ) ; restart_lookahead ( ) ; } if ( debug ) debug_message ( "# Parse-ahead ok, going back to normal parse" ) ; parse_lookahead ( debug ) ; return true ; }
attempt to recover from a syntax error . this returns false if recovery fails , true if it succeeds . recovery happens in 4 steps . first we pop the parse stack down to a point at which we have a shift out of the top - most state on the error symbol . this represents the initial error recovery configuration . if no such configuration is found , then we fail . next a small number of " lookahead " or " parse ahead " symbols are read into a buffer . the size of this buffer is determined by error_sync_size ( ) and determines how many symbols beyond the error must be matched to consider the recovery a success . next , we begin to discard symbols in attempt to get past the point of error to a point where we can continue parsing . after each symbol , we attempt to " parse ahead " though the buffered lookahead symbols . the " parse ahead " process simulates that actual parse , but does not modify the real parser ' s configuration , nor execute any actions . if we can parse all the stored symbols without error , then the recovery is considered a success . once a successful recovery point is determined , we do an actual parse over the stored input - - modifying the real parse configuration and executing all actions . finally , we return the the normal parser to continue with the overall parse .
