Logo Search packages:      
Sourcecode: jflex version File versions

final short java_cup::runtime::lr_parser::get_action ( int  state,
int  sym 
) [inline, protected]

Fetch an action from the action table. The table is broken up into rows, one per state (rows are indexed directly by state number). Within each row, a list of index, value pairs are given (as sequential entries in the table), and the list is terminated by a default entry (denoted with a Symbol index of -1). To find the proper entry in a row we do a linear or binary search (depending on the size of the row).

state the state index of the action being accessed.
sym the Symbol index of the action being accessed.

Definition at line 424 of file lr_parser.java.

References action_tab.

Referenced by debug_parse(), find_recovery_config(), parse(), parse_lookahead(), shift_under_error(), and try_parse_ahead().

      short tag;
      int first, last, probe;
      short[] row = action_tab[state];

      /* linear search if we are < 10 entries */
      if (row.length < 20)
        for (probe = 0; probe < row.length; probe++)
          /* is this entry labeled with our Symbol or the default? */
          tag = row[probe++];
          if (tag == sym || tag == -1)
              /* return the next entry */
              return row[probe];
      /* otherwise binary search */
        first = 0; 
        last = (row.length-1)/2 - 1;  /* leave out trailing default entry */
        while (first <= last)
            probe = (first+last)/2;
            if (sym == row[probe*2])
            return row[probe*2+1];
            else if (sym > row[probe*2])
            first = probe+1;
              last = probe-1;

        /* not found, use the default at the end */
        return row[row.length-1];

      /* shouldn't happened, but if we run off the end we return the 
       default (error == 0) */
      return 0;

Generated by  Doxygen 1.6.0   Back to index