1 /* Prepare the LALR and GLR parser tables.
2 
3    Copyright (C) 2002, 2004, 2009-2015, 2018-2021 Free Software
4    Foundation, Inc.
5 
6    This file is part of Bison, the GNU Compiler Compiler.
7 
8    This program is free software: you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation, either version 3 of the License, or
11    (at your option) any later version.
12 
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
20 
21 #ifndef TABLES_H_
22 # define TABLES_H_
23 
24 # include "state.h"
25 
26 /* The parser tables consist of these tables.
27 
28    YYTRANSLATE = vector mapping yylex's token numbers into bison's
29    token numbers.
30 
31    YYTNAME = vector of string-names indexed by bison token number.
32 
33    YYTOKNUM = vector of yylex token numbers corresponding to entries
34    in YYTNAME.
35 
36    YYRLINE = vector of line-numbers of all rules.  For yydebug
37    printouts.
38 
39    YYRHS = vector of items of all rules.  This is exactly what RITEMS
40    contains.  For yydebug and for semantic parser.
41 
42    YYPRHS[R] = index in YYRHS of first item for rule R.
43 
44    YYR1[R] = symbol number of symbol that rule R derives.
45 
46    YYR2[R] = number of symbols composing right hand side of rule R.
47 
48    YYSTOS[S] = the symbol number of the symbol that leads to state S.
49 
50    YYFINAL = the state number of the termination state.
51 
52    YYTABLE = a vector filled with portions for different uses, found
53    via YYPACT and YYPGOTO, described below.
54 
55    YYLAST ( = high) the number of the last element of YYTABLE, i.e.,
56    sizeof (YYTABLE) - 1.
57 
58    YYCHECK = a vector indexed in parallel with YYTABLE.  It indicates,
59    in a roundabout way, the bounds of the portion you are trying to
60    examine.
61 
62    Suppose that the portion of YYTABLE starts at index P and the index
63    to be examined within the portion is I.  Then if YYCHECK[P+I] != I,
64    I is outside the bounds of what is actually allocated, and the
65    default (from YYDEFACT or YYDEFGOTO) should be used.  Otherwise,
66    YYTABLE[P+I] should be used.
67 
68    YYDEFACT[S] = default reduction number in state s.  Performed when
69    YYTABLE doesn't specify something else to do.  Zero means the default
70    is an error.
71 
72    YYDEFGOTO[I] = default state to go to after a reduction of a rule
73    that generates variable NTOKENS + I, except when YYTABLE specifies
74    something else to do.
75 
76    YYPACT[S] = index in YYTABLE of the portion describing state S.
77    The lookahead token's number, I, is used to index that portion of
78    YYTABLE to find out what action to perform.
79 
80    If YYPACT[S] == YYPACT_NINF, if YYPACT[S] + I is outside the bounds
81    of YYTABLE (from 0 to YYLAST), or I is outside the bounds for portion
82    S (that is, YYCHECK[YYPACT[S] + I] != I), then the default action
83    (that is, YYDEFACT[S]) should be used instead of YYTABLE.  Otherwise,
84    the value YYTABLE[YYPACT[S] + I] should be used even if
85    YYPACT[S] < 0.
86 
87    If the value in YYTABLE is positive, we shift the token and go to
88    that state.
89 
90    If the value is negative, it is minus a rule number to reduce by.
91 
92    If the value is YYTABLE_NINF, it's a syntax error.
93 
94    YYPGOTO[I] = the index in YYTABLE of the portion describing what to
95    do after reducing a rule that derives variable I + NTOKENS.  This
96    portion is indexed by the parser state number, S, as of before the
97    text for this nonterminal was read.
98 
99    If YYPGOTO[I] + S is outside the bounds of YYTABLE (from 0 to YYLAST)
100    or if S is outside the bounds of the portion for I (that is,
101    YYCHECK[YYPGOTO[I] + S] != S), then the default state (that is,
102    YYDEFGOTO[I]) should be used instead of YYTABLE.  Otherwise,
103    YYTABLE[YYPGOTO[I] + S] is the state to go to even if YYPGOTO[I] < 0.
104 
105    When the above YYPACT, YYPGOTO, and YYCHECK tests determine that a
106    value from YYTABLE should be used, that value is never zero, so it is
107    useless to check for zero.  When those tests indicate that the value
108    from YYDEFACT or YYDEFGOTO should be used instead, the value from
109    YYTABLE *might* be zero, which, as a consequence of the way in which
110    the tables are constructed, also happens to indicate that YYDEFACT or
111    YYDEFGOTO should be used.  However, the YYTABLE value cannot be
112    trusted when the YYDEFACT or YYDEFGOTO value should be used.  In
113    summary, forget about zero values in YYTABLE.
114 */
115 
116 extern int nvectors;
117 
118 typedef int base_number;
119 extern base_number *base;
120 /* A distinguished value of BASE, negative infinite.  During the
121    computation equals to BASE_MINIMUM, later mapped to BASE_NINF to
122    keep parser tables small.  */
123 extern base_number base_ninf;
124 
125 extern int *conflict_table;
126 extern int *conflict_list;
127 extern int conflict_list_cnt;
128 
129 extern base_number *table;
130 extern base_number *check;
131 /* The value used in TABLE to denote explicit syntax errors
132    (%nonassoc), a negative infinite.  */
133 extern base_number table_ninf;
134 
135 extern state_number *yydefgoto;
136 extern rule_number *yydefact;
137 extern int high;
138 
139 void tables_generate (void);
140 void tables_free (void);
141 
142 #endif /* !TABLES_H_ */
143