]>
Commit | Line | Data |
---|---|---|
f7d4d87a | 1 | /* Data definitions for internal representation of bison's input, |
b2ed6e58 | 2 | Copyright 1984, 1986, 1989, 1992, 2001 Free Software Foundation, Inc. |
f7d4d87a | 3 | |
b2ca4022 | 4 | This file is part of Bison, the GNU Compiler Compiler. |
f7d4d87a | 5 | |
b2ca4022 AD |
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) | |
9 | any later version. | |
f7d4d87a | 10 | |
b2ca4022 AD |
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. | |
f7d4d87a | 15 | |
b2ca4022 AD |
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. */ | |
f7d4d87a | 20 | |
b2ca4022 AD |
21 | #ifndef GRAM_H_ |
22 | # define GRAM_H_ | |
f7d4d87a DM |
23 | |
24 | /* representation of the grammar rules: | |
25 | ||
b2ca4022 AD |
26 | ntokens is the number of tokens, and nvars is the number of |
27 | variables (nonterminals). nsyms is the total number, ntokens + | |
28 | nvars. | |
f7d4d87a | 29 | |
b2ca4022 AD |
30 | (the true number of token values assigned is ntokens reduced by one |
31 | for each alias declaration) | |
9f690211 | 32 | |
b2ca4022 AD |
33 | Each symbol (either token or variable) receives a symbol number. |
34 | Numbers 0 to ntokens-1 are for tokens, and ntokens to nsyms-1 are | |
35 | for variables. Symbol number zero is the end-of-input token. This | |
36 | token is counted in ntokens. | |
f7d4d87a | 37 | |
b2ca4022 AD |
38 | The rules receive rule numbers 1 to nrules in the order they are |
39 | written. Actions and guards are accessed via the rule number. | |
f7d4d87a | 40 | |
b2ed6e58 | 41 | The rules themselves are described by several arrays: amongst which |
1a2b5d37 | 42 | RITEM, and RULES. |
b2ed6e58 | 43 | |
1a2b5d37 | 44 | RULES is an array of struct rule_s, which members are: |
b2ed6e58 | 45 | |
1a2b5d37 | 46 | RULES[R].lhs -- the symbol number of the left hand side of |
b2ed6e58 AD |
47 | rule R. If -1, the rule has been thrown out by reduce.c and should |
48 | be ignored. | |
49 | ||
1a2b5d37 | 50 | RULES[R].rhs -- the index in RITEM of the beginning of the |
b2ca4022 | 51 | portion for rule R. |
f7d4d87a | 52 | |
1a2b5d37 | 53 | RULES[R].prec -- the precedence level of R. |
652a871c | 54 | |
1a2b5d37 | 55 | RULES[R].precsym -- the symbol-number of the symbol in %prec |
652a871c AD |
56 | for R (if any). |
57 | ||
1a2b5d37 | 58 | RULES[R].assoc -- the associativity of R. |
e41dc700 | 59 | |
1a2b5d37 | 60 | RULES[R].line -- the line where R was defined. |
652a871c | 61 | |
1a2b5d37 | 62 | RULES[R].useful -- TRUE iff the rule is used. |
68f1e3ed | 63 | |
b2ed6e58 AD |
64 | The right hand side is stored as symbol numbers in a portion of |
65 | RITEM. | |
f7d4d87a | 66 | |
b2ca4022 AD |
67 | The length of the portion is one greater than the number of symbols |
68 | in the rule's right hand side. The last element in the portion | |
69 | contains minus R, which identifies it as the end of a portion and | |
70 | says which rule it is for. | |
f7d4d87a | 71 | |
b2ed6e58 | 72 | The portions of RITEM come in order of increasing rule number and |
b2ca4022 AD |
73 | are followed by an element which is zero to mark the end. nitems |
74 | is the total length of ritem, not counting the final zero. Each | |
75 | element of ritem is called an "item" and its index in ritem is an | |
76 | item number. | |
f7d4d87a | 77 | |
b2ca4022 AD |
78 | Item numbers are used in the finite state machine to represent |
79 | places that parsing can get to. | |
f7d4d87a | 80 | |
5a670b1e | 81 | SYMBOLS[I]->PREC records the precedence level of each symbol. |
f7d4d87a | 82 | |
b2ca4022 AD |
83 | Precedence levels are assigned in increasing order starting with 1 |
84 | so that numerically higher precedence values mean tighter binding | |
85 | as they ought to. Zero as a symbol or rule's precedence means none | |
86 | is assigned. | |
f7d4d87a | 87 | |
b2ca4022 | 88 | Associativities are recorded similarly in rassoc and sassoc. */ |
f7d4d87a DM |
89 | |
90 | ||
91 | #define ISTOKEN(s) ((s) < ntokens) | |
92 | #define ISVAR(s) ((s) >= ntokens) | |
93 | ||
f7d4d87a DM |
94 | extern int nitems; |
95 | extern int nrules; | |
96 | extern int nsyms; | |
97 | extern int ntokens; | |
98 | extern int nvars; | |
99 | ||
100 | extern short *ritem; | |
75142d45 | 101 | extern int nritems; |
b2ed6e58 | 102 | |
f7d4d87a DM |
103 | extern int start_symbol; |
104 | ||
f7d4d87a | 105 | /* associativity values in elements of rassoc, sassoc. */ |
d7020c20 AD |
106 | typedef enum |
107 | { | |
108 | right_assoc, | |
109 | left_assoc, | |
110 | non_assoc | |
111 | } associativity; | |
f7d4d87a | 112 | |
f7d4d87a | 113 | |
652a871c AD |
114 | typedef struct rule_s |
115 | { | |
116 | short lhs; | |
117 | short rhs; | |
118 | short prec; | |
119 | short precsym; | |
120 | short assoc; | |
e41dc700 | 121 | short line; |
68f1e3ed | 122 | bool useful; |
f499b062 | 123 | |
3f96f4dc AD |
124 | const char *action; |
125 | short action_line; | |
f499b062 AD |
126 | |
127 | const char *guard; | |
128 | short guard_line; | |
652a871c AD |
129 | } rule_t; |
130 | ||
1a2b5d37 | 131 | extern struct rule_s *rules; |
652a871c | 132 | |
0e78e603 AD |
133 | /* Table of the symbols, indexed by the symbol number. */ |
134 | extern struct bucket **symbols; | |
135 | ||
b2ca4022 AD |
136 | /* token translation table: indexed by a token number as returned by |
137 | the user's yylex routine, it yields the internal token number used | |
342b8b6e | 138 | by the parser and throughout bison. */ |
f7d4d87a DM |
139 | |
140 | extern short *token_translations; | |
f7d4d87a DM |
141 | extern int max_user_token_number; |
142 | ||
b2ca4022 AD |
143 | /* SEMANTIC_PARSER is nonzero if the input file says to use the hairy |
144 | parser that provides for semantic error recovery. If it is zero, | |
145 | the yacc-compatible simplified parser is used. */ | |
f7d4d87a DM |
146 | |
147 | extern int semantic_parser; | |
148 | ||
b2ca4022 AD |
149 | /* PURE_PARSER is nonzero if should generate a parser that is all pure |
150 | and reentrant. */ | |
f7d4d87a DM |
151 | |
152 | extern int pure_parser; | |
153 | ||
b2ca4022 | 154 | /* ERROR_TOKEN_NUMBER is the token number of the error token. */ |
f7d4d87a DM |
155 | |
156 | extern int error_token_number; | |
3067fbef AD |
157 | |
158 | ||
159 | /* Dump RITEM for traces. */ | |
c2713865 AD |
160 | void ritem_print PARAMS ((FILE *out)); |
161 | ||
162 | /* Return the size of the longest rule RHS. */ | |
163 | size_t ritem_longest_rhs PARAMS ((void)); | |
164 | ||
b2ca4022 | 165 | #endif /* !GRAM_H_ */ |