lalr.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Compute lookahead criteria for bison,
  2. Copyright (C) 1984, 1986, 1989, 2000, 2002, 2004, 2006-2007,
  3. 2009-2015, 2018-2021 Free Software Foundation, Inc.
  4. This file is part of Bison, the GNU Compiler Compiler.
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  15. #ifndef LALR_H_
  16. # define LALR_H_
  17. # include <bitset.h>
  18. # include <bitsetv.h>
  19. /* Import the definition of RULE_T. */
  20. # include "gram.h"
  21. /* Import the definition of CORE, TRANSITIONS and REDUCTIONS. */
  22. # include "state.h"
  23. /** Build the LALR(1) automaton.
  24. Find which rules need lookahead in each state, and which lookahead
  25. tokens they accept.
  26. Also builds:
  27. - #goto_map
  28. - #from_state
  29. - #to_state
  30. - #goto_follows
  31. */
  32. void lalr (void);
  33. /**
  34. * Set #nLA and allocate all reduction lookahead sets. Normally invoked by
  35. * #lalr.
  36. */
  37. void initialize_LA (void);
  38. /**
  39. * Build only:
  40. * - #goto_map
  41. * - #from_state
  42. * - #to_state
  43. * Normally invoked by #lalr.
  44. */
  45. void set_goto_map (void);
  46. /**
  47. * Update state numbers recorded in #goto_map, #from_state, and #to_state such
  48. * that:
  49. * - \c nstates_old is the old number of states.
  50. * - Where \c i is the old state number, <tt>old_to_new[i]</tt> is either:
  51. * - \c nstates_old if state \c i is removed because it is unreachable.
  52. * Thus, remove all goto entries involving this state.
  53. * - The new state number.
  54. */
  55. void lalr_update_state_numbers (state_number old_to_new[],
  56. state_number nstates_old);
  57. /** Release the information related to lookahead tokens.
  58. Can be performed once the action tables are computed. */
  59. void lalr_free (void);
  60. typedef size_t goto_number;
  61. # define GOTO_NUMBER_MAXIMUM ((goto_number) -1)
  62. /** Index into #from_state and #to_state.
  63. All the transitions that accept a particular variable are grouped
  64. together in FROM_STATE and TO_STATE, with indexes from GOTO_MAP[I -
  65. NTOKENS] to GOTO_MAP[I - NTOKENS + 1] - 1 (including both). */
  66. extern goto_number *goto_map;
  67. /** The size of #from_state and #to_state. */
  68. extern goto_number ngotos;
  69. /** State number which a transition leads from. */
  70. extern state_number *from_state;
  71. /** State number it leads to. */
  72. extern state_number *to_state;
  73. /** The number of the goto from state SRC labeled with nterm SYM. */
  74. goto_number map_goto (state_number src, symbol_number sym);
  75. /* goto_follows[i] is the set of tokens following goto i. */
  76. extern bitsetv goto_follows;
  77. #endif /* !LALR_H_ */