Logo Search packages:      
Sourcecode: jflex version File versions

boolean java_cup::runtime::lr_parser::find_recovery_config ( boolean  debug  )  [inline, protected]

Put the (real) parse stack into error recovery configuration by popping the stack down to a state that can shift on the special error Symbol, then doing the shift. If no suitable state exists on the stack we return false

Parameters:
debug should we produce debugging messages as we parse.

Definition at line 913 of file lr_parser.java.

References debug_message(), error_sym(), get_action(), java_cup::runtime::Symbol::parse_state, shift_under_error(), stack, tos, and java_cup::runtime::Symbol::used_by_parser.

Referenced by error_recovery().

    {
      Symbol error_token;
      int act;

      if (debug) debug_message("# Finding recovery state on stack");

      /* Remember the right-position of the top symbol on the stack */
      int right_pos = ((Symbol)stack.peek()).right;
      int left_pos  = ((Symbol)stack.peek()).left;

      /* pop down until we can shift under error Symbol */
      while (!shift_under_error())
      {
        /* pop the stack */
        if (debug) 
          debug_message("# Pop stack by one, state was # " +
                        ((Symbol)stack.peek()).parse_state);
          left_pos = ((Symbol)stack.pop()).left;      
        tos--;

        /* if we have hit bottom, we fail */
        if (stack.empty()) 
          {
            if (debug) debug_message("# No recovery state found on stack");
            return false;
          }
      }

      /* state on top of the stack can shift under error, find the shift */
      act = get_action(((Symbol)stack.peek()).parse_state, error_sym());
      if (debug) 
      {
        debug_message("# Recover state found (#" + 
                  ((Symbol)stack.peek()).parse_state + ")");
        debug_message("# Shifting on error to state #" + (act-1));
      }

      /* build and shift a special error Symbol */
      error_token = new Symbol(error_sym(), left_pos, right_pos);
      error_token.parse_state = act-1;
      error_token.used_by_parser = true;
      stack.push(error_token);
      tos++;

      return true;
    }


Generated by  Doxygen 1.6.0   Back to index