home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / online / source / c / compilers / Bison.sit.hqx / Bison / Source / state.h < prev    next >
Text File  |  1992-08-21  |  5KB  |  145 lines

  1. /***********************************************************
  2.  *
  3.  * Macintosh/MPW version of GNU Bison 1.18
  4.  * Please read the README_MPW file for more information
  5.  *
  6.  ***********************************************************/
  7.  
  8. /* Type definitions for nondeterministic finite state machine for bison,
  9.    Copyright (C) 1984, 1989 Free Software Foundation, Inc.
  10.  
  11. This file is part of Bison, the GNU Compiler Compiler.
  12.  
  13. Bison is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2, or (at your option)
  16. any later version.
  17.  
  18. Bison is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with Bison; see the file COPYING.  If not, write to
  25. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  26.  
  27.  
  28. /* These type definitions are used to represent a nondeterministic
  29.    finite state machine that parses the specified grammar.
  30.    This information is generated by the function generate_states
  31.    in the file LR0.
  32.  
  33. Each state of the machine is described by a set of items --
  34. particular positions in particular rules -- that are the possible
  35. places where parsing could continue when the machine is in this state.
  36. These symbols at these items are the allowable inputs that can follow now.
  37.  
  38. A core represents one state.  States are numbered in the number field.
  39. When generate_states is finished, the starting state is state 0
  40. and nstates is the number of states.  (A transition to a state
  41. whose state number is nstates indicates termination.)  All the cores
  42. are chained together and first_state points to the first one (state 0).
  43.  
  44. For each state there is a particular symbol which must have been the
  45. last thing accepted to reach that state.  It is the accessing_symbol
  46. of the core.
  47.  
  48. Each core contains a vector of nitems items which are the indices
  49. in the ritems vector of the items that are selected in this state.
  50.  
  51. The link field is used for chaining buckets that hash states by
  52. their itemsets.  This is for recognizing equivalent states and
  53. combining them when the states are generated.
  54.  
  55. The two types of transitions are shifts (push the lookahead token
  56. and read another) and reductions (combine the last n things on the
  57. stack via a rule, replace them with the symbol that the rule derives,
  58. and leave the lookahead token alone).  When the states are generated,
  59. these transitions are represented in two other lists.
  60.  
  61. Each shifts structure describes the possible shift transitions out
  62. of one state, the state whose number is in the number field.
  63. The shifts structures are linked through next and first_shift points to them.
  64. Each contains a vector of numbers of the states that shift transitions
  65. can go to.  The accessing_symbol fields of those states' cores say what kind
  66. of input leads to them.
  67.  
  68. A shift to state zero should be ignored.  Conflict resolution
  69. deletes shifts by changing them to zero.
  70.  
  71. Each reductions structure describes the possible reductions at the state
  72. whose number is in the number field.  The data is a list of nreds rules,
  73. represented by their rule numbers.   first_reduction points to the list
  74. of these structures.
  75.  
  76. Conflict resolution can decide that certain tokens in certain
  77. states should explicitly be errors (for implementing %nonassoc).
  78. For each state, the tokens that are errors for this reason
  79. are recorded in an errs structure, which has the state number
  80. in its number field.  The rest of the errs structure is full
  81. of token numbers.
  82.  
  83. There is at least one shift transition present in state zero.
  84. It leads to a next-to-final state whose accessing_symbol is
  85. the grammar's start symbol.  The next-to-final state has one shift
  86. to the final state, whose accessing_symbol is zero (end of input).
  87. The final state has one shift, which goes to the termination state
  88. (whose number is nstates-1).
  89. The reason for the extra state at the end is to placate the parser's
  90. strategy of making all decisions one token ahead of its actions.  */
  91.  
  92.  
  93. typedef
  94.   struct core
  95.     {
  96.       struct core *next;
  97.       struct core *link;
  98.       short number;
  99.       short accessing_symbol;
  100.       short nitems;
  101.       short items[1];
  102.     }
  103.   core;
  104.  
  105.  
  106.  
  107. typedef
  108.   struct shifts
  109.     {
  110.       struct shifts *next;
  111.       short number;
  112.       short nshifts;
  113.       short shifts[1];
  114.     }
  115.   shifts;
  116.  
  117.  
  118.  
  119. typedef
  120.   struct errs
  121.     {
  122.       short nerrs;
  123.       short errs[1];
  124.     }
  125.   errs;
  126.  
  127.  
  128.  
  129. typedef
  130.   struct reductions
  131.     {
  132.       struct reductions *next;
  133.       short number;
  134.       short nreds;
  135.       short rules[1];
  136.     }
  137.   reductions;
  138.  
  139.  
  140.  
  141. extern int nstates;
  142. extern core *first_state;
  143. extern shifts *first_shift;
  144. extern reductions *first_reduction;
  145.