]>
git.saurik.com Git - bison.git/blob - src/state.h
1 /* Type definitions for nondeterministic finite state machine for bison,
2 Copyright (C) 1984, 1989 Free Software Foundation, Inc.
4 This file is part of Bison, the GNU Compiler Compiler.
6 Bison is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 Bison is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Bison; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* These type definitions are used to represent a nondeterministic
23 finite state machine that parses the specified grammar.
24 This information is generated by the function generate_states
27 Each state of the machine is described by a set of items --
28 particular positions in particular rules -- that are the possible
29 places where parsing could continue when the machine is in this state.
30 These symbols at these items are the allowable inputs that can follow now.
32 A core represents one state. States are numbered in the number field.
33 When generate_states is finished, the starting state is state 0
34 and nstates is the number of states. (A transition to a state
35 whose state number is nstates indicates termination.) All the cores
36 are chained together and first_state points to the first one (state 0).
38 For each state there is a particular symbol which must have been the
39 last thing accepted to reach that state. It is the accessing_symbol
42 Each core contains a vector of nitems items which are the indices
43 in the ritems vector of the items that are selected in this state.
45 The link field is used for chaining buckets that hash states by
46 their itemsets. This is for recognizing equivalent states and
47 combining them when the states are generated.
49 The two types of transitions are shifts (push the lookahead token
50 and read another) and reductions (combine the last n things on the
51 stack via a rule, replace them with the symbol that the rule derives,
52 and leave the lookahead token alone). When the states are generated,
53 these transitions are represented in two other lists.
55 Each shifts structure describes the possible shift transitions out
56 of one state, the state whose number is in the number field.
57 The shifts structures are linked through next and first_shift points to them.
58 Each contains a vector of numbers of the states that shift transitions
59 can go to. The accessing_symbol fields of those states' cores say what kind
60 of input leads to them.
62 A shift to state zero should be ignored. Conflict resolution
63 deletes shifts by changing them to zero.
65 Each reductions structure describes the possible reductions at the state
66 whose number is in the number field. The data is a list of nreds rules,
67 represented by their rule numbers. first_reduction points to the list
70 Conflict resolution can decide that certain tokens in certain
71 states should explicitly be errors (for implementing %nonassoc).
72 For each state, the tokens that are errors for this reason
73 are recorded in an errs structure, which has the state number
74 in its number field. The rest of the errs structure is full
77 There is at least one shift transition present in state zero.
78 It leads to a next-to-final state whose accessing_symbol is
79 the grammar's start symbol. The next-to-final state has one shift
80 to the final state, whose accessing_symbol is zero (end of input).
81 The final state has one shift, which goes to the termination state
82 (whose number is nstates-1).
83 The reason for the extra state at the end is to placate the parser's
84 strategy of making all decisions one token ahead of its actions. */
93 short accessing_symbol
;
126 struct reductions
*next
;
136 extern core
*first_state
;
137 extern shifts
*first_shift
;
138 extern reductions
*first_reduction
;