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