Logo Search packages:      
Sourcecode: jflex version File versions

boolean java_cup::runtime::lr_parser::error_recovery ( boolean  debug  )  throws java.lang.Exception [inline, protected]

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.

debug should we produce debugging messages as we parse.

Definition at line 839 of file lr_parser.java.

References debug_message(), EOF_sym(), find_recovery_config(), lookahead, parse_lookahead(), read_lookahead(), restart_lookahead(), and try_parse_ahead().

Referenced by debug_parse(), and parse().

      if (debug) debug_message("# Attempting error recovery");

      /* first pop the stack back into a state that can shift on error and 
       do that shift (if that fails, we fail) */
      if (!find_recovery_config(debug))
        if (debug) debug_message("# Error recovery fails");
        return false;

      /* read ahead to create lookahead we can parse multiple times */

      /* repeatedly try to parse forward until we make it the required dist */
      for (;;)
        /* try to parse forward, if it makes it, bail out of loop */
        if (debug) debug_message("# Trying to parse ahead");
        if (try_parse_ahead(debug))

        /* if we are now at EOF, we have failed */
        if (lookahead[0].sym == EOF_sym()) 
            if (debug) debug_message("# Error recovery fails at EOF");
            return false;

        /* otherwise, we consume another Symbol and try again */
        // BUG FIX by Bruce Hutton
        // Computer Science Department, University of Auckland,
        // Auckland, New Zealand.
        // It is the first token that is being consumed, not the one 
        // we were up to parsing
        if (debug) 
            debug_message("# Consuming Symbol #" + lookahead[ 0 ].sym);

      /* we have consumed to a point where we can parse forward */
      if (debug) debug_message("# Parse-ahead ok, going back to normal parse");

      /* do the real parse (including actions) across the lookahead */

      /* we have success */
      return true;

Generated by  Doxygen 1.6.0   Back to index