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