| @@ -1,1685 +1,1686 @@ | | | @@ -1,1685 +1,1686 @@ |
1 | %{ | | 1 | %{ |
2 | /* $NetBSD: cgram.y,v 1.46 2009/10/02 19:01:13 christos Exp $ */ | | 2 | /* $NetBSD: cgram.y,v 1.47 2009/10/03 01:35:20 christos Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. | | 5 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. |
6 | * Copyright (c) 1994, 1995 Jochen Pohl | | 6 | * Copyright (c) 1994, 1995 Jochen Pohl |
7 | * All Rights Reserved. | | 7 | * All Rights Reserved. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
15 | * notice, this list of conditions and the following disclaimer in the | | 15 | * notice, this list of conditions and the following disclaimer in the |
16 | * documentation and/or other materials provided with the distribution. | | 16 | * documentation and/or other materials provided with the distribution. |
17 | * 3. All advertising materials mentioning features or use of this software | | 17 | * 3. All advertising materials mentioning features or use of this software |
18 | * must display the following acknowledgement: | | 18 | * must display the following acknowledgement: |
19 | * This product includes software developed by Jochen Pohl for | | 19 | * This product includes software developed by Jochen Pohl for |
20 | * The NetBSD Project. | | 20 | * The NetBSD Project. |
21 | * 4. The name of the author may not be used to endorse or promote products | | 21 | * 4. The name of the author may not be used to endorse or promote products |
22 | * derived from this software without specific prior written permission. | | 22 | * derived from this software without specific prior written permission. |
23 | * | | 23 | * |
24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 24 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 25 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 26 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 27 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 28 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 33 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
34 | */ | | 34 | */ |
35 | | | 35 | |
36 | #include <sys/cdefs.h> | | 36 | #include <sys/cdefs.h> |
37 | #if defined(__RCSID) && !defined(lint) | | 37 | #if defined(__RCSID) && !defined(lint) |
38 | __RCSID("$NetBSD: cgram.y,v 1.46 2009/10/02 19:01:13 christos Exp $"); | | 38 | __RCSID("$NetBSD: cgram.y,v 1.47 2009/10/03 01:35:20 christos Exp $"); |
39 | #endif | | 39 | #endif |
40 | | | 40 | |
41 | #include <stdlib.h> | | 41 | #include <stdlib.h> |
42 | #include <string.h> | | 42 | #include <string.h> |
43 | #include <limits.h> | | 43 | #include <limits.h> |
44 | | | 44 | |
45 | #include "lint1.h" | | 45 | #include "lint1.h" |
46 | | | 46 | |
47 | extern char *yytext; | | 47 | extern char *yytext; |
48 | /* | | 48 | /* |
49 | * Contains the level of current declaration. 0 is extern. | | 49 | * Contains the level of current declaration. 0 is extern. |
50 | * Used for symbol table entries. | | 50 | * Used for symbol table entries. |
51 | */ | | 51 | */ |
52 | int blklev; | | 52 | int blklev; |
53 | | | 53 | |
54 | /* | | 54 | /* |
55 | * level for memory allocation. Normaly the same as blklev. | | 55 | * level for memory allocation. Normaly the same as blklev. |
56 | * An exeption is the declaration of arguments in prototypes. Memory | | 56 | * An exeption is the declaration of arguments in prototypes. Memory |
57 | * for these can't be freed after the declaration, but symbols must | | 57 | * for these can't be freed after the declaration, but symbols must |
58 | * be removed from the symbol table after the declaration. | | 58 | * be removed from the symbol table after the declaration. |
59 | */ | | 59 | */ |
60 | int mblklev; | | 60 | int mblklev; |
61 | | | 61 | |
62 | /* | | 62 | /* |
63 | * Save the no-warns state and restore it to avoid the problem where | | 63 | * Save the no-warns state and restore it to avoid the problem where |
64 | * if (expr) { stmt } / * NOLINT * / stmt; | | 64 | * if (expr) { stmt } / * NOLINT * / stmt; |
65 | */ | | 65 | */ |
66 | static int onowarn = -1; | | 66 | static int onowarn = -1; |
67 | | | 67 | |
68 | static int toicon(tnode_t *, int); | | 68 | static int toicon(tnode_t *, int); |
69 | static void idecl(sym_t *, int, sbuf_t *); | | 69 | static void idecl(sym_t *, int, sbuf_t *); |
70 | static void ignuptorp(void); | | 70 | static void ignuptorp(void); |
71 | | | 71 | |
72 | #ifdef DEBUG | | 72 | #ifdef DEBUG |
73 | static inline void CLRWFLGS(const char *file, size_t line); | | 73 | static inline void CLRWFLGS(const char *file, size_t line); |
74 | static inline void CLRWFLGS(const char *file, size_t line) | | 74 | static inline void CLRWFLGS(const char *file, size_t line) |
75 | { | | 75 | { |
76 | printf("%s, %d: clear flags %s %zu\n", curr_pos.p_file, | | 76 | printf("%s, %d: clear flags %s %zu\n", curr_pos.p_file, |
77 | curr_pos.p_line, file, line); | | 77 | curr_pos.p_line, file, line); |
78 | clrwflgs(); | | 78 | clrwflgs(); |
79 | onowarn = -1; | | 79 | onowarn = -1; |
80 | } | | 80 | } |
81 | | | 81 | |
82 | static inline void SAVE(const char *file, size_t line); | | 82 | static inline void SAVE(const char *file, size_t line); |
83 | static inline void SAVE(const char *file, size_t line) | | 83 | static inline void SAVE(const char *file, size_t line) |
84 | { | | 84 | { |
85 | if (onowarn != -1) | | 85 | if (onowarn != -1) |
86 | abort(); | | 86 | abort(); |
87 | printf("%s, %d: save flags %s %zu = %d\n", curr_pos.p_file, | | 87 | printf("%s, %d: save flags %s %zu = %d\n", curr_pos.p_file, |
88 | curr_pos.p_line, file, line, nowarn); | | 88 | curr_pos.p_line, file, line, nowarn); |
89 | onowarn = nowarn; | | 89 | onowarn = nowarn; |
90 | } | | 90 | } |
91 | | | 91 | |
92 | static inline void RESTORE(const char *file, size_t line); | | 92 | static inline void RESTORE(const char *file, size_t line); |
93 | static inline void RESTORE(const char *file, size_t line) | | 93 | static inline void RESTORE(const char *file, size_t line) |
94 | { | | 94 | { |
95 | if (onowarn != -1) { | | 95 | if (onowarn != -1) { |
96 | nowarn = onowarn; | | 96 | nowarn = onowarn; |
97 | printf("%s, %d: restore flags %s %zu = %d\n", curr_pos.p_file, | | 97 | printf("%s, %d: restore flags %s %zu = %d\n", curr_pos.p_file, |
98 | curr_pos.p_line, file, line, nowarn); | | 98 | curr_pos.p_line, file, line, nowarn); |
99 | onowarn = -1; | | 99 | onowarn = -1; |
100 | } else | | 100 | } else |
101 | CLRWFLGS(file, line); | | 101 | CLRWFLGS(file, line); |
102 | } | | 102 | } |
103 | #else | | 103 | #else |
104 | #define CLRWFLGS(f, l) clrwflgs(), onowarn = -1 | | 104 | #define CLRWFLGS(f, l) clrwflgs(), onowarn = -1 |
105 | #define SAVE(f, l) onowarn = nowarn | | 105 | #define SAVE(f, l) onowarn = nowarn |
106 | #define RESTORE(f, l) (void)(onowarn == -1 ? (clrwflgs(), 0) : (nowarn = onowarn)) | | 106 | #define RESTORE(f, l) (void)(onowarn == -1 ? (clrwflgs(), 0) : (nowarn = onowarn)) |
107 | #endif | | 107 | #endif |
108 | %} | | 108 | %} |
109 | | | 109 | |
110 | %expect 3 | | 110 | %expect 3 |
111 | | | 111 | |
112 | %union { | | 112 | %union { |
113 | int y_int; | | 113 | int y_int; |
114 | val_t *y_val; | | 114 | val_t *y_val; |
115 | sbuf_t *y_sb; | | 115 | sbuf_t *y_sb; |
116 | sym_t *y_sym; | | 116 | sym_t *y_sym; |
117 | op_t y_op; | | 117 | op_t y_op; |
118 | scl_t y_scl; | | 118 | scl_t y_scl; |
119 | tspec_t y_tspec; | | 119 | tspec_t y_tspec; |
120 | tqual_t y_tqual; | | 120 | tqual_t y_tqual; |
121 | type_t *y_type; | | 121 | type_t *y_type; |
122 | tnode_t *y_tnode; | | 122 | tnode_t *y_tnode; |
123 | range_t y_range; | | 123 | range_t y_range; |
124 | strg_t *y_strg; | | 124 | strg_t *y_strg; |
125 | pqinf_t *y_pqinf; | | 125 | pqinf_t *y_pqinf; |
126 | }; | | 126 | }; |
127 | | | 127 | |
128 | %token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPARN T_RPARN | | 128 | %token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPARN T_RPARN |
129 | %token <y_op> T_STROP | | 129 | %token <y_op> T_STROP |
130 | %token <y_op> T_UNOP | | 130 | %token <y_op> T_UNOP |
131 | %token <y_op> T_INCDEC | | 131 | %token <y_op> T_INCDEC |
132 | %token T_SIZEOF | | 132 | %token T_SIZEOF |
133 | %token T_ALIGNOF | | 133 | %token T_ALIGNOF |
134 | %token <y_op> T_MULT | | 134 | %token <y_op> T_MULT |
135 | %token <y_op> T_DIVOP | | 135 | %token <y_op> T_DIVOP |
136 | %token <y_op> T_ADDOP | | 136 | %token <y_op> T_ADDOP |
137 | %token <y_op> T_SHFTOP | | 137 | %token <y_op> T_SHFTOP |
138 | %token <y_op> T_RELOP | | 138 | %token <y_op> T_RELOP |
139 | %token <y_op> T_EQOP | | 139 | %token <y_op> T_EQOP |
140 | %token <y_op> T_AND | | 140 | %token <y_op> T_AND |
141 | %token <y_op> T_XOR | | 141 | %token <y_op> T_XOR |
142 | %token <y_op> T_OR | | 142 | %token <y_op> T_OR |
143 | %token <y_op> T_LOGAND | | 143 | %token <y_op> T_LOGAND |
144 | %token <y_op> T_LOGOR | | 144 | %token <y_op> T_LOGOR |
145 | %token T_QUEST | | 145 | %token T_QUEST |
146 | %token T_COLON | | 146 | %token T_COLON |
147 | %token <y_op> T_ASSIGN | | 147 | %token <y_op> T_ASSIGN |
148 | %token <y_op> T_OPASS | | 148 | %token <y_op> T_OPASS |
149 | %token T_COMMA | | 149 | %token T_COMMA |
150 | %token T_SEMI | | 150 | %token T_SEMI |
151 | %token T_ELLIPSE | | 151 | %token T_ELLIPSE |
152 | %token T_REAL | | 152 | %token T_REAL |
153 | %token T_IMAG | | 153 | %token T_IMAG |
154 | | | 154 | |
155 | /* storage classes (extern, static, auto, register and typedef) */ | | 155 | /* storage classes (extern, static, auto, register and typedef) */ |
156 | %token <y_scl> T_SCLASS | | 156 | %token <y_scl> T_SCLASS |
157 | | | 157 | |
158 | /* types (char, int, short, long, unsigned, signed, float, double, void) */ | | 158 | /* types (char, int, short, long, unsigned, signed, float, double, void) */ |
159 | %token <y_tspec> T_TYPE | | 159 | %token <y_tspec> T_TYPE |
160 | | | 160 | |
161 | /* qualifiers (const, volatile) */ | | 161 | /* qualifiers (const, volatile) */ |
162 | %token <y_tqual> T_QUAL | | 162 | %token <y_tqual> T_QUAL |
163 | | | 163 | |
164 | /* struct or union */ | | 164 | /* struct or union */ |
165 | %token <y_tspec> T_SOU | | 165 | %token <y_tspec> T_SOU |
166 | | | 166 | |
167 | /* enum */ | | 167 | /* enum */ |
168 | %token T_ENUM | | 168 | %token T_ENUM |
169 | | | 169 | |
170 | /* remaining keywords */ | | 170 | /* remaining keywords */ |
171 | %token T_CASE | | 171 | %token T_CASE |
172 | %token T_DEFAULT | | 172 | %token T_DEFAULT |
173 | %token T_IF | | 173 | %token T_IF |
174 | %token T_ELSE | | 174 | %token T_ELSE |
175 | %token T_SWITCH | | 175 | %token T_SWITCH |
176 | %token T_DO | | 176 | %token T_DO |
177 | %token T_WHILE | | 177 | %token T_WHILE |
178 | %token T_FOR | | 178 | %token T_FOR |
179 | %token T_GOTO | | 179 | %token T_GOTO |
180 | %token T_CONTINUE | | 180 | %token T_CONTINUE |
181 | %token T_BREAK | | 181 | %token T_BREAK |
182 | %token T_RETURN | | 182 | %token T_RETURN |
183 | %token T_ASM | | 183 | %token T_ASM |
184 | %token T_SYMBOLRENAME | | 184 | %token T_SYMBOLRENAME |
185 | %token T_PACKED | | 185 | %token T_PACKED |
186 | /* Type Attributes */ | | 186 | /* Type Attributes */ |
187 | %token <y_type> T_ATTRIBUTE | | 187 | %token <y_type> T_ATTRIBUTE |
188 | %token <y_type> T_AT_ALIGNED | | 188 | %token <y_type> T_AT_ALIGNED |
189 | %token <y_type> T_AT_DEPRECATED | | 189 | %token <y_type> T_AT_DEPRECATED |
190 | %token <y_type> T_AT_MAY_ALIAS | | 190 | %token <y_type> T_AT_MAY_ALIAS |
191 | %token <y_type> T_AT_PACKED | | 191 | %token <y_type> T_AT_PACKED |
192 | %token <y_type> T_AT_TUINION | | 192 | %token <y_type> T_AT_TUINION |
193 | %token <y_type> T_AT_TUNION | | 193 | %token <y_type> T_AT_TUNION |
194 | %token <y_type> T_AT_UNUSED | | 194 | %token <y_type> T_AT_UNUSED |
195 | | | 195 | |
196 | | | 196 | |
197 | | | 197 | |
198 | %left T_COMMA | | 198 | %left T_COMMA |
199 | %right T_ASSIGN T_OPASS | | 199 | %right T_ASSIGN T_OPASS |
200 | %right T_QUEST T_COLON | | 200 | %right T_QUEST T_COLON |
201 | %left T_LOGOR | | 201 | %left T_LOGOR |
202 | %left T_LOGAND | | 202 | %left T_LOGAND |
203 | %left T_OR | | 203 | %left T_OR |
204 | %left T_XOR | | 204 | %left T_XOR |
205 | %left T_AND | | 205 | %left T_AND |
206 | %left T_EQOP | | 206 | %left T_EQOP |
207 | %left T_RELOP | | 207 | %left T_RELOP |
208 | %left T_SHFTOP | | 208 | %left T_SHFTOP |
209 | %left T_ADDOP | | 209 | %left T_ADDOP |
210 | %left T_MULT T_DIVOP | | 210 | %left T_MULT T_DIVOP |
211 | %right T_UNOP T_INCDEC T_SIZEOF T_ALIGNOF T_REAL T_IMAG | | 211 | %right T_UNOP T_INCDEC T_SIZEOF T_ALIGNOF T_REAL T_IMAG |
212 | %left T_LPARN T_LBRACK T_STROP | | 212 | %left T_LPARN T_LBRACK T_STROP |
213 | | | 213 | |
214 | %token <y_sb> T_NAME | | 214 | %token <y_sb> T_NAME |
215 | %token <y_sb> T_TYPENAME | | 215 | %token <y_sb> T_TYPENAME |
216 | %token <y_val> T_CON | | 216 | %token <y_val> T_CON |
217 | %token <y_strg> T_STRING | | 217 | %token <y_strg> T_STRING |
218 | | | 218 | |
219 | %type <y_sym> func_decl | | 219 | %type <y_sym> func_decl |
220 | %type <y_sym> notype_decl | | 220 | %type <y_sym> notype_decl |
221 | %type <y_sym> type_decl | | 221 | %type <y_sym> type_decl |
222 | %type <y_type> typespec | | 222 | %type <y_type> typespec |
223 | %type <y_type> clrtyp_typespec | | 223 | %type <y_type> clrtyp_typespec |
224 | %type <y_type> notype_typespec | | 224 | %type <y_type> notype_typespec |
225 | %type <y_type> struct_spec | | 225 | %type <y_type> struct_spec |
226 | %type <y_type> enum_spec | | 226 | %type <y_type> enum_spec |
227 | %type <y_type> type_attribute | | 227 | %type <y_type> type_attribute |
228 | %type <y_type> type_attribute_spec | | 228 | %type <y_type> type_attribute_spec |
229 | %type <y_sym> struct_tag | | 229 | %type <y_sym> struct_tag |
230 | %type <y_sym> enum_tag | | 230 | %type <y_sym> enum_tag |
231 | %type <y_tspec> struct | | 231 | %type <y_tspec> struct |
232 | %type <y_sym> struct_declaration | | 232 | %type <y_sym> struct_declaration |
233 | %type <y_sb> identifier | | 233 | %type <y_sb> identifier |
234 | %type <y_sym> member_declaration_list_with_rbrace | | 234 | %type <y_sym> member_declaration_list_with_rbrace |
235 | %type <y_sym> member_declaration_list | | 235 | %type <y_sym> member_declaration_list |
236 | %type <y_sym> member_declaration | | 236 | %type <y_sym> member_declaration |
237 | %type <y_sym> notype_member_decls | | 237 | %type <y_sym> notype_member_decls |
238 | %type <y_sym> type_member_decls | | 238 | %type <y_sym> type_member_decls |
239 | %type <y_sym> notype_member_decl | | 239 | %type <y_sym> notype_member_decl |
240 | %type <y_sym> type_member_decl | | 240 | %type <y_sym> type_member_decl |
241 | %type <y_tnode> constant | | 241 | %type <y_tnode> constant |
242 | %type <y_sym> enum_declaration | | 242 | %type <y_sym> enum_declaration |
243 | %type <y_sym> enums_with_opt_comma | | 243 | %type <y_sym> enums_with_opt_comma |
244 | %type <y_sym> enums | | 244 | %type <y_sym> enums |
245 | %type <y_sym> enumerator | | 245 | %type <y_sym> enumerator |
246 | %type <y_sym> ename | | 246 | %type <y_sym> ename |
247 | %type <y_sym> notype_direct_decl | | 247 | %type <y_sym> notype_direct_decl |
248 | %type <y_sym> type_direct_decl | | 248 | %type <y_sym> type_direct_decl |
249 | %type <y_pqinf> pointer | | 249 | %type <y_pqinf> pointer |
250 | %type <y_pqinf> asterisk | | 250 | %type <y_pqinf> asterisk |
251 | %type <y_sym> param_decl | | 251 | %type <y_sym> param_decl |
252 | %type <y_sym> param_list | | 252 | %type <y_sym> param_list |
253 | %type <y_sym> abs_decl_param_list | | 253 | %type <y_sym> abs_decl_param_list |
254 | %type <y_sym> direct_param_decl | | 254 | %type <y_sym> direct_param_decl |
255 | %type <y_sym> notype_param_decl | | 255 | %type <y_sym> notype_param_decl |
256 | %type <y_sym> direct_notype_param_decl | | 256 | %type <y_sym> direct_notype_param_decl |
257 | %type <y_pqinf> type_qualifier_list | | 257 | %type <y_pqinf> type_qualifier_list |
258 | %type <y_pqinf> type_qualifier | | 258 | %type <y_pqinf> type_qualifier |
259 | %type <y_sym> identifier_list | | 259 | %type <y_sym> identifier_list |
260 | %type <y_sym> abs_decl | | 260 | %type <y_sym> abs_decl |
261 | %type <y_sym> direct_abs_decl | | 261 | %type <y_sym> direct_abs_decl |
262 | %type <y_sym> vararg_parameter_type_list | | 262 | %type <y_sym> vararg_parameter_type_list |
263 | %type <y_sym> parameter_type_list | | 263 | %type <y_sym> parameter_type_list |
264 | %type <y_sym> parameter_declaration | | 264 | %type <y_sym> parameter_declaration |
265 | %type <y_tnode> expr | | 265 | %type <y_tnode> expr |
266 | %type <y_tnode> expr_stmnt_val | | 266 | %type <y_tnode> expr_stmnt_val |
267 | %type <y_tnode> expr_stmnt_list | | 267 | %type <y_tnode> expr_stmnt_list |
268 | %type <y_tnode> term | | 268 | %type <y_tnode> term |
269 | %type <y_tnode> func_arg_list | | 269 | %type <y_tnode> func_arg_list |
270 | %type <y_op> point_or_arrow | | 270 | %type <y_op> point_or_arrow |
271 | %type <y_type> type_name | | 271 | %type <y_type> type_name |
272 | %type <y_sym> abstract_declaration | | 272 | %type <y_sym> abstract_declaration |
273 | %type <y_tnode> do_while_expr | | 273 | %type <y_tnode> do_while_expr |
274 | %type <y_tnode> opt_expr | | 274 | %type <y_tnode> opt_expr |
275 | %type <y_strg> string | | 275 | %type <y_strg> string |
276 | %type <y_strg> string2 | | 276 | %type <y_strg> string2 |
277 | %type <y_sb> opt_asm_or_symbolrename | | 277 | %type <y_sb> opt_asm_or_symbolrename |
278 | %type <y_range> range | | 278 | %type <y_range> range |
279 | %type <y_range> lorange | | 279 | %type <y_range> lorange |
280 | | | 280 | |
281 | | | 281 | |
282 | %% | | 282 | %% |
283 | | | 283 | |
284 | program: | | 284 | program: |
285 | /* empty */ { | | 285 | /* empty */ { |
286 | if (sflag) { | | 286 | if (sflag) { |
287 | /* empty translation unit */ | | 287 | /* empty translation unit */ |
288 | error(272); | | 288 | error(272); |
289 | } else if (!tflag) { | | 289 | } else if (!tflag) { |
290 | /* empty translation unit */ | | 290 | /* empty translation unit */ |
291 | warning(272); | | 291 | warning(272); |
292 | } | | 292 | } |
293 | } | | 293 | } |
294 | | translation_unit | | 294 | | translation_unit |
295 | ; | | 295 | ; |
296 | | | 296 | |
297 | translation_unit: | | 297 | translation_unit: |
298 | ext_decl | | 298 | ext_decl |
299 | | translation_unit ext_decl | | 299 | | translation_unit ext_decl |
300 | ; | | 300 | ; |
301 | | | 301 | |
302 | ext_decl: | | 302 | ext_decl: |
303 | asm_stmnt | | 303 | asm_stmnt |
304 | | func_def { | | 304 | | func_def { |
305 | glclup(0); | | 305 | glclup(0); |
306 | CLRWFLGS(__FILE__, __LINE__); | | 306 | CLRWFLGS(__FILE__, __LINE__); |
307 | } | | 307 | } |
308 | | data_def { | | 308 | | data_def { |
309 | glclup(0); | | 309 | glclup(0); |
310 | CLRWFLGS(__FILE__, __LINE__); | | 310 | CLRWFLGS(__FILE__, __LINE__); |
311 | } | | 311 | } |
312 | ; | | 312 | ; |
313 | | | 313 | |
314 | data_def: | | 314 | data_def: |
315 | T_SEMI { | | 315 | T_SEMI { |
316 | if (sflag) { | | 316 | if (sflag) { |
317 | /* syntax error: empty declaration */ | | 317 | /* syntax error: empty declaration */ |
318 | error(0); | | 318 | error(0); |
319 | } else if (!tflag) { | | 319 | } else if (!tflag) { |
320 | /* syntax error: empty declaration */ | | 320 | /* syntax error: empty declaration */ |
321 | warning(0); | | 321 | warning(0); |
322 | } | | 322 | } |
323 | } | | 323 | } |
324 | | clrtyp deftyp notype_init_decls T_SEMI { | | 324 | | clrtyp deftyp notype_init_decls T_SEMI { |
325 | if (sflag) { | | 325 | if (sflag) { |
326 | /* old style declaration; add "int" */ | | 326 | /* old style declaration; add "int" */ |
327 | error(1); | | 327 | error(1); |
328 | } else if (!tflag) { | | 328 | } else if (!tflag) { |
329 | /* old style declaration; add "int" */ | | 329 | /* old style declaration; add "int" */ |
330 | warning(1); | | 330 | warning(1); |
331 | } | | 331 | } |
332 | } | | 332 | } |
333 | | declmods deftyp T_SEMI { | | 333 | | declmods deftyp T_SEMI { |
334 | if (dcs->d_scl == TYPEDEF) { | | 334 | if (dcs->d_scl == TYPEDEF) { |
335 | /* typedef declares no type name */ | | 335 | /* typedef declares no type name */ |
336 | warning(72); | | 336 | warning(72); |
337 | } else { | | 337 | } else { |
338 | /* empty declaration */ | | 338 | /* empty declaration */ |
339 | warning(2); | | 339 | warning(2); |
340 | } | | 340 | } |
341 | } | | 341 | } |
342 | | declmods deftyp notype_init_decls T_SEMI | | 342 | | declmods deftyp notype_init_decls T_SEMI |
343 | | declspecs deftyp T_SEMI { | | 343 | | declspecs deftyp T_SEMI { |
344 | if (dcs->d_scl == TYPEDEF) { | | 344 | if (dcs->d_scl == TYPEDEF) { |
345 | /* typedef declares no type name */ | | 345 | /* typedef declares no type name */ |
346 | warning(72); | | 346 | warning(72); |
347 | } else if (!dcs->d_nedecl) { | | 347 | } else if (!dcs->d_nedecl) { |
348 | /* empty declaration */ | | 348 | /* empty declaration */ |
349 | warning(2); | | 349 | warning(2); |
350 | } | | 350 | } |
351 | } | | 351 | } |
352 | | declspecs deftyp type_init_decls T_SEMI | | 352 | | declspecs deftyp type_init_decls T_SEMI |
353 | | error T_SEMI { | | 353 | | error T_SEMI { |
354 | globclup(); | | 354 | globclup(); |
355 | } | | 355 | } |
356 | | error T_RBRACE { | | 356 | | error T_RBRACE { |
357 | globclup(); | | 357 | globclup(); |
358 | } | | 358 | } |
359 | ; | | 359 | ; |
360 | | | 360 | |
361 | func_def: | | 361 | func_def: |
362 | func_decl { | | 362 | func_decl { |
363 | if ($1->s_type->t_tspec != FUNC) { | | 363 | if ($1->s_type->t_tspec != FUNC) { |
364 | /* syntax error */ | | 364 | /* syntax error */ |
365 | error(249, yytext); | | 365 | error(249, yytext); |
366 | YYERROR; | | 366 | YYERROR; |
367 | } | | 367 | } |
368 | if ($1->s_type->t_typedef) { | | 368 | if ($1->s_type->t_typedef) { |
369 | /* ()-less function definition */ | | 369 | /* ()-less function definition */ |
370 | error(64); | | 370 | error(64); |
371 | YYERROR; | | 371 | YYERROR; |
372 | } | | 372 | } |
373 | funcdef($1); | | 373 | funcdef($1); |
374 | blklev++; | | 374 | blklev++; |
375 | pushdecl(ARG); | | 375 | pushdecl(ARG); |
376 | if (nowarn) | | 376 | if (nowarn) |
377 | $1->s_used = 1; | | 377 | $1->s_used = 1; |
378 | } opt_arg_declaration_list { | | 378 | } opt_arg_declaration_list { |
379 | popdecl(); | | 379 | popdecl(); |
380 | blklev--; | | 380 | blklev--; |
381 | cluparg(); | | 381 | cluparg(); |
382 | pushctrl(0); | | 382 | pushctrl(0); |
383 | } comp_stmnt { | | 383 | } comp_stmnt { |
384 | funcend(); | | 384 | funcend(); |
385 | popctrl(0); | | 385 | popctrl(0); |
386 | } | | 386 | } |
387 | ; | | 387 | ; |
388 | | | 388 | |
389 | func_decl: | | 389 | func_decl: |
390 | clrtyp deftyp notype_decl { | | 390 | clrtyp deftyp notype_decl { |
391 | $$ = $3; | | 391 | $$ = $3; |
392 | } | | 392 | } |
393 | | declmods deftyp notype_decl { | | 393 | | declmods deftyp notype_decl { |
394 | $$ = $3; | | 394 | $$ = $3; |
395 | } | | 395 | } |
396 | | declspecs deftyp type_decl { | | 396 | | declspecs deftyp type_decl { |
397 | $$ = $3; | | 397 | $$ = $3; |
398 | } | | 398 | } |
399 | ; | | 399 | ; |
400 | | | 400 | |
401 | opt_arg_declaration_list: | | 401 | opt_arg_declaration_list: |
402 | /* empty */ | | 402 | /* empty */ |
403 | | arg_declaration_list | | 403 | | arg_declaration_list |
404 | ; | | 404 | ; |
405 | | | 405 | |
406 | arg_declaration_list: | | 406 | arg_declaration_list: |
407 | arg_declaration | | 407 | arg_declaration |
408 | | arg_declaration_list arg_declaration | | 408 | | arg_declaration_list arg_declaration |
409 | /* XXX or better "arg_declaration error" ? */ | | 409 | /* XXX or better "arg_declaration error" ? */ |
410 | | error | | 410 | | error |
411 | ; | | 411 | ; |
412 | | | 412 | |
413 | /* | | 413 | /* |
414 | * "arg_declaration" is separated from "declaration" because it | | 414 | * "arg_declaration" is separated from "declaration" because it |
415 | * needs other error handling. | | 415 | * needs other error handling. |
416 | */ | | 416 | */ |
417 | | | 417 | |
418 | arg_declaration: | | 418 | arg_declaration: |
419 | declmods deftyp T_SEMI { | | 419 | declmods deftyp T_SEMI { |
420 | /* empty declaration */ | | 420 | /* empty declaration */ |
421 | warning(2); | | 421 | warning(2); |
422 | } | | 422 | } |
423 | | declmods deftyp notype_init_decls T_SEMI | | 423 | | declmods deftyp notype_init_decls T_SEMI |
424 | | declspecs deftyp T_SEMI { | | 424 | | declspecs deftyp T_SEMI { |
425 | if (!dcs->d_nedecl) { | | 425 | if (!dcs->d_nedecl) { |
426 | /* empty declaration */ | | 426 | /* empty declaration */ |
427 | warning(2); | | 427 | warning(2); |
428 | } else { | | 428 | } else { |
429 | tspec_t ts = dcs->d_type->t_tspec; | | 429 | tspec_t ts = dcs->d_type->t_tspec; |
430 | /* %s declared in argument declaration list */ | | 430 | /* %s declared in argument declaration list */ |
431 | warning(3, ts == STRUCT ? "struct" : | | 431 | warning(3, ts == STRUCT ? "struct" : |
432 | (ts == UNION ? "union" : "enum")); | | 432 | (ts == UNION ? "union" : "enum")); |
433 | } | | 433 | } |
434 | } | | 434 | } |
435 | | declspecs deftyp type_init_decls T_SEMI { | | 435 | | declspecs deftyp type_init_decls T_SEMI { |
436 | if (dcs->d_nedecl) { | | 436 | if (dcs->d_nedecl) { |
437 | tspec_t ts = dcs->d_type->t_tspec; | | 437 | tspec_t ts = dcs->d_type->t_tspec; |
438 | /* %s declared in argument declaration list */ | | 438 | /* %s declared in argument declaration list */ |
439 | warning(3, ts == STRUCT ? "struct" : | | 439 | warning(3, ts == STRUCT ? "struct" : |
440 | (ts == UNION ? "union" : "enum")); | | 440 | (ts == UNION ? "union" : "enum")); |
441 | } | | 441 | } |
442 | } | | 442 | } |
443 | | declmods error | | 443 | | declmods error |
444 | | declspecs error | | 444 | | declspecs error |
445 | ; | | 445 | ; |
446 | | | 446 | |
447 | declaration: | | 447 | declaration: |
448 | declmods deftyp T_SEMI { | | 448 | declmods deftyp T_SEMI { |
449 | if (dcs->d_scl == TYPEDEF) { | | 449 | if (dcs->d_scl == TYPEDEF) { |
450 | /* typedef declares no type name */ | | 450 | /* typedef declares no type name */ |
451 | warning(72); | | 451 | warning(72); |
452 | } else { | | 452 | } else { |
453 | /* empty declaration */ | | 453 | /* empty declaration */ |
454 | warning(2); | | 454 | warning(2); |
455 | } | | 455 | } |
456 | } | | 456 | } |
457 | | declmods deftyp notype_init_decls T_SEMI | | 457 | | declmods deftyp notype_init_decls T_SEMI |
458 | | declspecs deftyp T_SEMI { | | 458 | | declspecs deftyp T_SEMI { |
459 | if (dcs->d_scl == TYPEDEF) { | | 459 | if (dcs->d_scl == TYPEDEF) { |
460 | /* typedef declares no type name */ | | 460 | /* typedef declares no type name */ |
461 | warning(72); | | 461 | warning(72); |
462 | } else if (!dcs->d_nedecl) { | | 462 | } else if (!dcs->d_nedecl) { |
463 | /* empty declaration */ | | 463 | /* empty declaration */ |
464 | warning(2); | | 464 | warning(2); |
465 | } | | 465 | } |
466 | } | | 466 | } |
467 | | declspecs deftyp type_init_decls T_SEMI | | 467 | | declspecs deftyp type_init_decls T_SEMI |
468 | | error T_SEMI | | 468 | | error T_SEMI |
469 | ; | | 469 | ; |
470 | | | 470 | |
471 | type_attribute_spec: | | 471 | type_attribute_spec: |
472 | T_AT_DEPRECATED | | 472 | T_AT_DEPRECATED |
473 | | T_AT_ALIGNED T_LPARN constant T_RPARN | | 473 | | T_AT_ALIGNED T_LPARN constant T_RPARN |
474 | | T_AT_MAY_ALIAS | | 474 | | T_AT_MAY_ALIAS |
475 | | T_AT_PACKED { | | 475 | | T_AT_PACKED { |
476 | addpacked(); | | 476 | addpacked(); |
477 | } | | 477 | } |
478 | | T_AT_TUNION | | 478 | | T_AT_TUNION |
479 | | T_AT_UNUSED | | 479 | | T_AT_UNUSED |
480 | ; | | 480 | ; |
481 | | | 481 | |
482 | type_attribute: | | 482 | type_attribute: |
483 | T_ATTRIBUTE T_LPARN T_LPARN type_attribute_spec T_RPARN T_RPARN | | 483 | T_ATTRIBUTE T_LPARN T_LPARN type_attribute_spec T_RPARN T_RPARN |
484 | | T_PACKED { | | 484 | | T_PACKED { |
485 | addpacked(); | | 485 | addpacked(); |
486 | } | | 486 | } |
487 | ; | | 487 | ; |
488 | | | 488 | |
489 | clrtyp: | | 489 | clrtyp: |
490 | { | | 490 | { |
491 | clrtyp(); | | 491 | clrtyp(); |
492 | } | | 492 | } |
493 | ; | | 493 | ; |
494 | | | 494 | |
495 | deftyp: | | 495 | deftyp: |
496 | /* empty */ { | | 496 | /* empty */ { |
497 | deftyp(); | | 497 | deftyp(); |
498 | } | | 498 | } |
499 | ; | | 499 | ; |
500 | | | 500 | |
501 | declspecs: | | 501 | declspecs: |
502 | clrtyp_typespec { | | 502 | clrtyp_typespec { |
503 | addtype($1); | | 503 | addtype($1); |
504 | } | | 504 | } |
505 | | declmods typespec { | | 505 | | declmods typespec { |
506 | addtype($2); | | 506 | addtype($2); |
507 | } | | 507 | } |
508 | | declspecs type_attribute | | 508 | | declspecs type_attribute |
509 | | declspecs declmod | | 509 | | declspecs declmod |
510 | | declspecs notype_typespec { | | 510 | | declspecs notype_typespec { |
511 | addtype($2); | | 511 | addtype($2); |
512 | } | | 512 | } |
513 | ; | | 513 | ; |
514 | | | 514 | |
515 | declmods: | | 515 | declmods: |
516 | clrtyp T_QUAL { | | 516 | clrtyp T_QUAL { |
517 | addqual($2); | | 517 | addqual($2); |
518 | } | | 518 | } |
519 | | clrtyp T_SCLASS { | | 519 | | clrtyp T_SCLASS { |
520 | addscl($2); | | 520 | addscl($2); |
521 | } | | 521 | } |
522 | | declmods declmod | | 522 | | declmods declmod |
523 | ; | | 523 | ; |
524 | | | 524 | |
525 | declmod: | | 525 | declmod: |
526 | T_QUAL { | | 526 | T_QUAL { |
527 | addqual($1); | | 527 | addqual($1); |
528 | } | | 528 | } |
529 | | T_SCLASS { | | 529 | | T_SCLASS { |
530 | addscl($1); | | 530 | addscl($1); |
531 | } | | 531 | } |
532 | ; | | 532 | ; |
533 | | | 533 | |
534 | clrtyp_typespec: | | 534 | clrtyp_typespec: |
535 | clrtyp notype_typespec { | | 535 | clrtyp notype_typespec { |
536 | $$ = $2; | | 536 | $$ = $2; |
537 | } | | 537 | } |
538 | | T_TYPENAME clrtyp { | | 538 | | T_TYPENAME clrtyp { |
539 | $$ = getsym($1)->s_type; | | 539 | $$ = getsym($1)->s_type; |
540 | } | | 540 | } |
541 | ; | | 541 | ; |
542 | | | 542 | |
543 | typespec: | | 543 | typespec: |
544 | notype_typespec { | | 544 | notype_typespec { |
545 | $$ = $1; | | 545 | $$ = $1; |
546 | } | | 546 | } |
547 | | T_TYPENAME { | | 547 | | T_TYPENAME { |
548 | $$ = getsym($1)->s_type; | | 548 | $$ = getsym($1)->s_type; |
549 | } | | 549 | } |
550 | ; | | 550 | ; |
551 | | | 551 | |
552 | notype_typespec: | | 552 | notype_typespec: |
553 | T_TYPE { | | 553 | T_TYPE { |
554 | $$ = gettyp($1); | | 554 | $$ = gettyp($1); |
555 | } | | 555 | } |
556 | | struct_spec { | | 556 | | struct_spec { |
557 | popdecl(); | | 557 | popdecl(); |
558 | $$ = $1; | | 558 | $$ = $1; |
559 | } | | 559 | } |
560 | | enum_spec { | | 560 | | enum_spec { |
561 | popdecl(); | | 561 | popdecl(); |
562 | $$ = $1; | | 562 | $$ = $1; |
563 | } | | 563 | } |
564 | ; | | 564 | ; |
565 | | | 565 | |
566 | struct_spec: | | 566 | struct_spec: |
567 | struct struct_tag { | | 567 | struct struct_tag { |
568 | /* | | 568 | /* |
569 | * STDC requires that "struct a;" always introduces | | 569 | * STDC requires that "struct a;" always introduces |
570 | * a new tag if "a" is not declared at current level | | 570 | * a new tag if "a" is not declared at current level |
571 | * | | 571 | * |
572 | * yychar is valid because otherwise the parser would | | 572 | * yychar is valid because otherwise the parser would |
573 | * not been able to deceide if he must shift or reduce | | 573 | * not been able to deceide if he must shift or reduce |
574 | */ | | 574 | */ |
575 | $$ = mktag($2, $1, 0, yychar == T_SEMI); | | 575 | $$ = mktag($2, $1, 0, yychar == T_SEMI); |
576 | } | | 576 | } |
577 | | struct struct_tag { | | 577 | | struct struct_tag { |
578 | dcs->d_tagtyp = mktag($2, $1, 1, 0); | | 578 | dcs->d_tagtyp = mktag($2, $1, 1, 0); |
579 | } struct_declaration { | | 579 | } struct_declaration { |
580 | $$ = compltag(dcs->d_tagtyp, $4); | | 580 | $$ = compltag(dcs->d_tagtyp, $4); |
581 | } | | 581 | } |
582 | | struct { | | 582 | | struct { |
583 | dcs->d_tagtyp = mktag(NULL, $1, 1, 0); | | 583 | dcs->d_tagtyp = mktag(NULL, $1, 1, 0); |
584 | } struct_declaration { | | 584 | } struct_declaration { |
585 | $$ = compltag(dcs->d_tagtyp, $3); | | 585 | $$ = compltag(dcs->d_tagtyp, $3); |
586 | } | | 586 | } |
587 | | struct error { | | 587 | | struct error { |
588 | symtyp = FVFT; | | 588 | symtyp = FVFT; |
589 | $$ = gettyp(INT); | | 589 | $$ = gettyp(INT); |
590 | } | | 590 | } |
591 | ; | | 591 | ; |
592 | | | 592 | |
593 | struct: | | 593 | struct: |
594 | struct type_attribute | | 594 | struct type_attribute |
595 | | T_SOU { | | 595 | | T_SOU { |
596 | symtyp = FTAG; | | 596 | symtyp = FTAG; |
597 | pushdecl($1 == STRUCT ? MOS : MOU); | | 597 | pushdecl($1 == STRUCT ? MOS : MOU); |
598 | dcs->d_offset = 0; | | 598 | dcs->d_offset = 0; |
599 | dcs->d_stralign = CHAR_BIT; | | 599 | dcs->d_stralign = CHAR_BIT; |
600 | $$ = $1; | | 600 | $$ = $1; |
601 | } | | 601 | } |
602 | ; | | 602 | ; |
603 | | | 603 | |
604 | struct_tag: | | 604 | struct_tag: |
605 | identifier { | | 605 | identifier { |
606 | $$ = getsym($1); | | 606 | $$ = getsym($1); |
607 | } | | 607 | } |
608 | ; | | 608 | ; |
609 | | | 609 | |
610 | struct_declaration: | | 610 | struct_declaration: |
611 | struct_decl_lbrace member_declaration_list_with_rbrace { | | 611 | struct_decl_lbrace member_declaration_list_with_rbrace { |
612 | $$ = $2; | | 612 | $$ = $2; |
613 | } | | 613 | } |
614 | ; | | 614 | ; |
615 | | | 615 | |
616 | struct_decl_lbrace: | | 616 | struct_decl_lbrace: |
617 | T_LBRACE { | | 617 | T_LBRACE { |
618 | symtyp = FVFT; | | 618 | symtyp = FVFT; |
619 | } | | 619 | } |
620 | ; | | 620 | ; |
621 | | | 621 | |
622 | member_declaration_list_with_rbrace: | | 622 | member_declaration_list_with_rbrace: |
623 | member_declaration_list T_SEMI T_RBRACE { | | 623 | member_declaration_list T_SEMI T_RBRACE { |
624 | $$ = $1; | | 624 | $$ = $1; |
625 | } | | 625 | } |
626 | | member_declaration_list T_RBRACE { | | 626 | | member_declaration_list T_RBRACE { |
627 | if (sflag) { | | 627 | if (sflag) { |
628 | /* syntax req. ";" after last struct/union member */ | | 628 | /* syntax req. ";" after last struct/union member */ |
629 | error(66); | | 629 | error(66); |
630 | } else { | | 630 | } else { |
631 | /* syntax req. ";" after last struct/union member */ | | 631 | /* syntax req. ";" after last struct/union member */ |
632 | warning(66); | | 632 | warning(66); |
633 | } | | 633 | } |
634 | $$ = $1; | | 634 | $$ = $1; |
635 | } | | 635 | } |
636 | | T_RBRACE { | | 636 | | T_RBRACE { |
637 | $$ = NULL; | | 637 | $$ = NULL; |
638 | } | | 638 | } |
639 | ; | | 639 | ; |
640 | | | 640 | |
641 | member_declaration_list: | | 641 | member_declaration_list: |
642 | member_declaration { | | 642 | member_declaration { |
643 | $$ = $1; | | 643 | $$ = $1; |
644 | } | | 644 | } |
645 | | member_declaration_list T_SEMI member_declaration { | | 645 | | member_declaration_list T_SEMI member_declaration { |
646 | $$ = lnklst($1, $3); | | 646 | $$ = lnklst($1, $3); |
647 | } | | 647 | } |
648 | ; | | 648 | ; |
649 | | | 649 | |
650 | member_declaration: | | 650 | member_declaration: |
651 | noclass_declmods deftyp { | | 651 | noclass_declmods deftyp { |
652 | /* too late, i know, but getsym() compensates it */ | | 652 | /* too late, i know, but getsym() compensates it */ |
653 | symtyp = FMOS; | | 653 | symtyp = FMOS; |
654 | } notype_member_decls { | | 654 | } notype_member_decls { |
655 | symtyp = FVFT; | | 655 | symtyp = FVFT; |
656 | $$ = $4; | | 656 | $$ = $4; |
657 | } | | 657 | } |
658 | | noclass_declspecs deftyp { | | 658 | | noclass_declspecs deftyp { |
659 | symtyp = FMOS; | | 659 | symtyp = FMOS; |
660 | } type_member_decls { | | 660 | } type_member_decls { |
661 | symtyp = FVFT; | | 661 | symtyp = FVFT; |
662 | $$ = $4; | | 662 | $$ = $4; |
663 | } | | 663 | } |
664 | | noclass_declmods deftyp { | | 664 | | noclass_declmods deftyp { |
665 | /* struct or union member must be named */ | | 665 | /* struct or union member must be named */ |
666 | warning(49); | | 666 | warning(49); |
667 | $$ = NULL; | | 667 | $$ = NULL; |
668 | } | | 668 | } |
669 | | noclass_declspecs deftyp { | | 669 | | noclass_declspecs deftyp { |
670 | /* struct or union member must be named */ | | 670 | /* struct or union member must be named */ |
671 | warning(49); | | 671 | warning(49); |
672 | $$ = NULL; | | 672 | $$ = NULL; |
673 | } | | 673 | } |
674 | | error { | | 674 | | error { |
675 | symtyp = FVFT; | | 675 | symtyp = FVFT; |
676 | $$ = NULL; | | 676 | $$ = NULL; |
677 | } | | 677 | } |
678 | ; | | 678 | ; |
679 | | | 679 | |
680 | noclass_declspecs: | | 680 | noclass_declspecs: |
681 | clrtyp_typespec { | | 681 | clrtyp_typespec { |
682 | addtype($1); | | 682 | addtype($1); |
683 | } | | 683 | } |
684 | | noclass_declmods typespec { | | 684 | | noclass_declmods typespec { |
685 | addtype($2); | | 685 | addtype($2); |
686 | } | | 686 | } |
| | | 687 | | noclass_declspecs type_attribute |
687 | | noclass_declspecs T_QUAL { | | 688 | | noclass_declspecs T_QUAL { |
688 | addqual($2); | | 689 | addqual($2); |
689 | } | | 690 | } |
690 | | noclass_declspecs notype_typespec { | | 691 | | noclass_declspecs notype_typespec { |
691 | addtype($2); | | 692 | addtype($2); |
692 | } | | 693 | } |
693 | ; | | 694 | ; |
694 | | | 695 | |
695 | noclass_declmods: | | 696 | noclass_declmods: |
696 | clrtyp T_QUAL { | | 697 | clrtyp T_QUAL { |
697 | addqual($2); | | 698 | addqual($2); |
698 | } | | 699 | } |
699 | | noclass_declmods T_QUAL { | | 700 | | noclass_declmods T_QUAL { |
700 | addqual($2); | | 701 | addqual($2); |
701 | } | | 702 | } |
702 | ; | | 703 | ; |
703 | | | 704 | |
704 | notype_member_decls: | | 705 | notype_member_decls: |
705 | notype_member_decl { | | 706 | notype_member_decl { |
706 | $$ = decl1str($1); | | 707 | $$ = decl1str($1); |
707 | } | | 708 | } |
708 | | notype_member_decls { | | 709 | | notype_member_decls { |
709 | symtyp = FMOS; | | 710 | symtyp = FMOS; |
710 | } T_COMMA type_member_decl { | | 711 | } T_COMMA type_member_decl { |
711 | $$ = lnklst($1, decl1str($4)); | | 712 | $$ = lnklst($1, decl1str($4)); |
712 | } | | 713 | } |
713 | ; | | 714 | ; |
714 | | | 715 | |
715 | type_member_decls: | | 716 | type_member_decls: |
716 | type_member_decl { | | 717 | type_member_decl { |
717 | $$ = decl1str($1); | | 718 | $$ = decl1str($1); |
718 | } | | 719 | } |
719 | | type_member_decls { | | 720 | | type_member_decls { |
720 | symtyp = FMOS; | | 721 | symtyp = FMOS; |
721 | } T_COMMA type_member_decl { | | 722 | } T_COMMA type_member_decl { |
722 | $$ = lnklst($1, decl1str($4)); | | 723 | $$ = lnklst($1, decl1str($4)); |
723 | } | | 724 | } |
724 | ; | | 725 | ; |
725 | | | 726 | |
726 | notype_member_decl: | | 727 | notype_member_decl: |
727 | notype_decl { | | 728 | notype_decl { |
728 | $$ = $1; | | 729 | $$ = $1; |
729 | } | | 730 | } |
730 | | notype_decl T_COLON constant { | | 731 | | notype_decl T_COLON constant { |
731 | $$ = bitfield($1, toicon($3, 1)); | | 732 | $$ = bitfield($1, toicon($3, 1)); |
732 | } | | 733 | } |
733 | | { | | 734 | | { |
734 | symtyp = FVFT; | | 735 | symtyp = FVFT; |
735 | } T_COLON constant { | | 736 | } T_COLON constant { |
736 | $$ = bitfield(NULL, toicon($3, 1)); | | 737 | $$ = bitfield(NULL, toicon($3, 1)); |
737 | } | | 738 | } |
738 | ; | | 739 | ; |
739 | | | 740 | |
740 | type_member_decl: | | 741 | type_member_decl: |
741 | type_decl { | | 742 | type_decl { |
742 | $$ = $1; | | 743 | $$ = $1; |
743 | } | | 744 | } |
744 | | type_decl T_COLON constant { | | 745 | | type_decl T_COLON constant { |
745 | $$ = bitfield($1, toicon($3, 1)); | | 746 | $$ = bitfield($1, toicon($3, 1)); |
746 | } | | 747 | } |
747 | | { | | 748 | | { |
748 | symtyp = FVFT; | | 749 | symtyp = FVFT; |
749 | } T_COLON constant { | | 750 | } T_COLON constant { |
750 | $$ = bitfield(NULL, toicon($3, 1)); | | 751 | $$ = bitfield(NULL, toicon($3, 1)); |
751 | } | | 752 | } |
752 | ; | | 753 | ; |
753 | | | 754 | |
754 | enum_spec: | | 755 | enum_spec: |
755 | enum enum_tag { | | 756 | enum enum_tag { |
756 | $$ = mktag($2, ENUM, 0, 0); | | 757 | $$ = mktag($2, ENUM, 0, 0); |
757 | } | | 758 | } |
758 | | enum enum_tag { | | 759 | | enum enum_tag { |
759 | dcs->d_tagtyp = mktag($2, ENUM, 1, 0); | | 760 | dcs->d_tagtyp = mktag($2, ENUM, 1, 0); |
760 | } enum_declaration { | | 761 | } enum_declaration { |
761 | $$ = compltag(dcs->d_tagtyp, $4); | | 762 | $$ = compltag(dcs->d_tagtyp, $4); |
762 | } | | 763 | } |
763 | | enum { | | 764 | | enum { |
764 | dcs->d_tagtyp = mktag(NULL, ENUM, 1, 0); | | 765 | dcs->d_tagtyp = mktag(NULL, ENUM, 1, 0); |
765 | } enum_declaration { | | 766 | } enum_declaration { |
766 | $$ = compltag(dcs->d_tagtyp, $3); | | 767 | $$ = compltag(dcs->d_tagtyp, $3); |
767 | } | | 768 | } |
768 | | enum error { | | 769 | | enum error { |
769 | symtyp = FVFT; | | 770 | symtyp = FVFT; |
770 | $$ = gettyp(INT); | | 771 | $$ = gettyp(INT); |
771 | } | | 772 | } |
772 | ; | | 773 | ; |
773 | | | 774 | |
774 | enum: | | 775 | enum: |
775 | T_ENUM { | | 776 | T_ENUM { |
776 | symtyp = FTAG; | | 777 | symtyp = FTAG; |
777 | pushdecl(ENUMCON); | | 778 | pushdecl(ENUMCON); |
778 | } | | 779 | } |
779 | ; | | 780 | ; |
780 | | | 781 | |
781 | enum_tag: | | 782 | enum_tag: |
782 | identifier { | | 783 | identifier { |
783 | $$ = getsym($1); | | 784 | $$ = getsym($1); |
784 | } | | 785 | } |
785 | ; | | 786 | ; |
786 | | | 787 | |
787 | enum_declaration: | | 788 | enum_declaration: |
788 | enum_decl_lbrace enums_with_opt_comma T_RBRACE { | | 789 | enum_decl_lbrace enums_with_opt_comma T_RBRACE { |
789 | $$ = $2; | | 790 | $$ = $2; |
790 | } | | 791 | } |
791 | ; | | 792 | ; |
792 | | | 793 | |
793 | enum_decl_lbrace: | | 794 | enum_decl_lbrace: |
794 | T_LBRACE { | | 795 | T_LBRACE { |
795 | symtyp = FVFT; | | 796 | symtyp = FVFT; |
796 | enumval = 0; | | 797 | enumval = 0; |
797 | } | | 798 | } |
798 | ; | | 799 | ; |
799 | | | 800 | |
800 | enums_with_opt_comma: | | 801 | enums_with_opt_comma: |
801 | enums { | | 802 | enums { |
802 | $$ = $1; | | 803 | $$ = $1; |
803 | } | | 804 | } |
804 | | enums T_COMMA { | | 805 | | enums T_COMMA { |
805 | if (sflag) { | | 806 | if (sflag) { |
806 | /* trailing "," prohibited in enum declaration */ | | 807 | /* trailing "," prohibited in enum declaration */ |
807 | error(54); | | 808 | error(54); |
808 | } else { | | 809 | } else { |
809 | /* trailing "," prohibited in enum declaration */ | | 810 | /* trailing "," prohibited in enum declaration */ |
810 | (void)gnuism(54); | | 811 | (void)gnuism(54); |
811 | } | | 812 | } |
812 | $$ = $1; | | 813 | $$ = $1; |
813 | } | | 814 | } |
814 | ; | | 815 | ; |
815 | | | 816 | |
816 | enums: | | 817 | enums: |
817 | enumerator { | | 818 | enumerator { |
818 | $$ = $1; | | 819 | $$ = $1; |
819 | } | | 820 | } |
820 | | enums T_COMMA enumerator { | | 821 | | enums T_COMMA enumerator { |
821 | $$ = lnklst($1, $3); | | 822 | $$ = lnklst($1, $3); |
822 | } | | 823 | } |
823 | | error { | | 824 | | error { |
824 | $$ = NULL; | | 825 | $$ = NULL; |
825 | } | | 826 | } |
826 | ; | | 827 | ; |
827 | | | 828 | |
828 | enumerator: | | 829 | enumerator: |
829 | ename { | | 830 | ename { |
830 | $$ = ename($1, enumval, 1); | | 831 | $$ = ename($1, enumval, 1); |
831 | } | | 832 | } |
832 | | ename T_ASSIGN constant { | | 833 | | ename T_ASSIGN constant { |
833 | $$ = ename($1, toicon($3, 1), 0); | | 834 | $$ = ename($1, toicon($3, 1), 0); |
834 | } | | 835 | } |
835 | ; | | 836 | ; |
836 | | | 837 | |
837 | ename: | | 838 | ename: |
838 | identifier { | | 839 | identifier { |
839 | $$ = getsym($1); | | 840 | $$ = getsym($1); |
840 | } | | 841 | } |
841 | ; | | 842 | ; |
842 | | | 843 | |
843 | | | 844 | |
844 | notype_init_decls: | | 845 | notype_init_decls: |
845 | notype_init_decl | | 846 | notype_init_decl |
846 | | notype_init_decls T_COMMA type_init_decl | | 847 | | notype_init_decls T_COMMA type_init_decl |
847 | ; | | 848 | ; |
848 | | | 849 | |
849 | type_init_decls: | | 850 | type_init_decls: |
850 | type_init_decl | | 851 | type_init_decl |
851 | | type_init_decls T_COMMA type_init_decl | | 852 | | type_init_decls T_COMMA type_init_decl |
852 | ; | | 853 | ; |
853 | | | 854 | |
854 | notype_init_decl: | | 855 | notype_init_decl: |
855 | notype_decl opt_asm_or_symbolrename { | | 856 | notype_decl opt_asm_or_symbolrename { |
856 | idecl($1, 0, $2); | | 857 | idecl($1, 0, $2); |
857 | chksz($1); | | 858 | chksz($1); |
858 | } | | 859 | } |
859 | | notype_decl opt_asm_or_symbolrename { | | 860 | | notype_decl opt_asm_or_symbolrename { |
860 | idecl($1, 1, $2); | | 861 | idecl($1, 1, $2); |
861 | } T_ASSIGN initializer { | | 862 | } T_ASSIGN initializer { |
862 | chksz($1); | | 863 | chksz($1); |
863 | } | | 864 | } |
864 | ; | | 865 | ; |
865 | | | 866 | |
866 | type_init_decl: | | 867 | type_init_decl: |
867 | type_decl opt_asm_or_symbolrename { | | 868 | type_decl opt_asm_or_symbolrename { |
868 | idecl($1, 0, $2); | | 869 | idecl($1, 0, $2); |
869 | chksz($1); | | 870 | chksz($1); |
870 | } | | 871 | } |
871 | | type_decl opt_asm_or_symbolrename { | | 872 | | type_decl opt_asm_or_symbolrename { |
872 | idecl($1, 1, $2); | | 873 | idecl($1, 1, $2); |
873 | } T_ASSIGN initializer { | | 874 | } T_ASSIGN initializer { |
874 | chksz($1); | | 875 | chksz($1); |
875 | } | | 876 | } |
876 | ; | | 877 | ; |
877 | | | 878 | |
878 | notype_decl: | | 879 | notype_decl: |
879 | notype_direct_decl { | | 880 | notype_direct_decl { |
880 | $$ = $1; | | 881 | $$ = $1; |
881 | } | | 882 | } |
882 | | pointer notype_direct_decl { | | 883 | | pointer notype_direct_decl { |
883 | $$ = addptr($2, $1); | | 884 | $$ = addptr($2, $1); |
884 | } | | 885 | } |
885 | ; | | 886 | ; |
886 | | | 887 | |
887 | notype_direct_decl: | | 888 | notype_direct_decl: |
888 | T_NAME { | | 889 | T_NAME { |
889 | $$ = dname(getsym($1)); | | 890 | $$ = dname(getsym($1)); |
890 | } | | 891 | } |
891 | | T_LPARN type_decl T_RPARN { | | 892 | | T_LPARN type_decl T_RPARN { |
892 | $$ = $2; | | 893 | $$ = $2; |
893 | } | | 894 | } |
894 | | notype_direct_decl T_LBRACK T_RBRACK { | | 895 | | notype_direct_decl T_LBRACK T_RBRACK { |
895 | $$ = addarray($1, 0, 0); | | 896 | $$ = addarray($1, 0, 0); |
896 | } | | 897 | } |
897 | | notype_direct_decl T_LBRACK constant T_RBRACK { | | 898 | | notype_direct_decl T_LBRACK constant T_RBRACK { |
898 | $$ = addarray($1, 1, toicon($3, 0)); | | 899 | $$ = addarray($1, 1, toicon($3, 0)); |
899 | } | | 900 | } |
900 | | notype_direct_decl param_list { | | 901 | | notype_direct_decl param_list { |
901 | $$ = addfunc($1, $2); | | 902 | $$ = addfunc($1, $2); |
902 | popdecl(); | | 903 | popdecl(); |
903 | blklev--; | | 904 | blklev--; |
904 | } | | 905 | } |
905 | ; | | 906 | ; |
906 | | | 907 | |
907 | type_decl: | | 908 | type_decl: |
908 | type_direct_decl { | | 909 | type_direct_decl { |
909 | $$ = $1; | | 910 | $$ = $1; |
910 | } | | 911 | } |
911 | | pointer type_direct_decl { | | 912 | | pointer type_direct_decl { |
912 | $$ = addptr($2, $1); | | 913 | $$ = addptr($2, $1); |
913 | } | | 914 | } |
914 | ; | | 915 | ; |
915 | | | 916 | |
916 | type_direct_decl: | | 917 | type_direct_decl: |
917 | identifier { | | 918 | identifier { |
918 | $$ = dname(getsym($1)); | | 919 | $$ = dname(getsym($1)); |
919 | } | | 920 | } |
920 | | T_LPARN type_decl T_RPARN { | | 921 | | T_LPARN type_decl T_RPARN { |
921 | $$ = $2; | | 922 | $$ = $2; |
922 | } | | 923 | } |
923 | | type_direct_decl T_LBRACK T_RBRACK { | | 924 | | type_direct_decl T_LBRACK T_RBRACK { |
924 | $$ = addarray($1, 0, 0); | | 925 | $$ = addarray($1, 0, 0); |
925 | } | | 926 | } |
926 | | type_direct_decl T_LBRACK constant T_RBRACK { | | 927 | | type_direct_decl T_LBRACK constant T_RBRACK { |
927 | $$ = addarray($1, 1, toicon($3, 0)); | | 928 | $$ = addarray($1, 1, toicon($3, 0)); |
928 | } | | 929 | } |
929 | | type_direct_decl param_list { | | 930 | | type_direct_decl param_list { |
930 | $$ = addfunc($1, $2); | | 931 | $$ = addfunc($1, $2); |
931 | popdecl(); | | 932 | popdecl(); |
932 | blklev--; | | 933 | blklev--; |
933 | } | | 934 | } |
934 | ; | | 935 | ; |
935 | | | 936 | |
936 | /* | | 937 | /* |
937 | * param_decl and notype_param_decl exist to avoid a conflict in | | 938 | * param_decl and notype_param_decl exist to avoid a conflict in |
938 | * argument lists. A typename enclosed in parens should always be | | 939 | * argument lists. A typename enclosed in parens should always be |
939 | * treated as a typename, not an argument. | | 940 | * treated as a typename, not an argument. |
940 | * "typedef int a; f(int (a));" is "typedef int a; f(int foo(a));" | | 941 | * "typedef int a; f(int (a));" is "typedef int a; f(int foo(a));" |
941 | * not "typedef int a; f(int a);" | | 942 | * not "typedef int a; f(int a);" |
942 | */ | | 943 | */ |
943 | param_decl: | | 944 | param_decl: |
944 | direct_param_decl { | | 945 | direct_param_decl { |
945 | $$ = $1; | | 946 | $$ = $1; |
946 | } | | 947 | } |
947 | | pointer direct_param_decl { | | 948 | | pointer direct_param_decl { |
948 | $$ = addptr($2, $1); | | 949 | $$ = addptr($2, $1); |
949 | } | | 950 | } |
950 | ; | | 951 | ; |
951 | | | 952 | |
952 | direct_param_decl: | | 953 | direct_param_decl: |
953 | identifier { | | 954 | identifier { |
954 | $$ = dname(getsym($1)); | | 955 | $$ = dname(getsym($1)); |
955 | } | | 956 | } |
956 | | T_LPARN notype_param_decl T_RPARN { | | 957 | | T_LPARN notype_param_decl T_RPARN { |
957 | $$ = $2; | | 958 | $$ = $2; |
958 | } | | 959 | } |
959 | | direct_param_decl T_LBRACK T_RBRACK { | | 960 | | direct_param_decl T_LBRACK T_RBRACK { |
960 | $$ = addarray($1, 0, 0); | | 961 | $$ = addarray($1, 0, 0); |
961 | } | | 962 | } |
962 | | direct_param_decl T_LBRACK constant T_RBRACK { | | 963 | | direct_param_decl T_LBRACK constant T_RBRACK { |
963 | $$ = addarray($1, 1, toicon($3, 0)); | | 964 | $$ = addarray($1, 1, toicon($3, 0)); |
964 | } | | 965 | } |
965 | | direct_param_decl param_list { | | 966 | | direct_param_decl param_list { |
966 | $$ = addfunc($1, $2); | | 967 | $$ = addfunc($1, $2); |
967 | popdecl(); | | 968 | popdecl(); |
968 | blklev--; | | 969 | blklev--; |
969 | } | | 970 | } |
970 | ; | | 971 | ; |
971 | | | 972 | |
972 | notype_param_decl: | | 973 | notype_param_decl: |
973 | direct_notype_param_decl { | | 974 | direct_notype_param_decl { |
974 | $$ = $1; | | 975 | $$ = $1; |
975 | } | | 976 | } |
976 | | pointer direct_notype_param_decl { | | 977 | | pointer direct_notype_param_decl { |
977 | $$ = addptr($2, $1); | | 978 | $$ = addptr($2, $1); |
978 | } | | 979 | } |
979 | ; | | 980 | ; |
980 | | | 981 | |
981 | direct_notype_param_decl: | | 982 | direct_notype_param_decl: |
982 | T_NAME { | | 983 | T_NAME { |
983 | $$ = dname(getsym($1)); | | 984 | $$ = dname(getsym($1)); |
984 | } | | 985 | } |
985 | | T_LPARN notype_param_decl T_RPARN { | | 986 | | T_LPARN notype_param_decl T_RPARN { |
986 | $$ = $2; | | 987 | $$ = $2; |
987 | } | | 988 | } |
988 | | direct_notype_param_decl T_LBRACK T_RBRACK { | | 989 | | direct_notype_param_decl T_LBRACK T_RBRACK { |
989 | $$ = addarray($1, 0, 0); | | 990 | $$ = addarray($1, 0, 0); |
990 | } | | 991 | } |
991 | | direct_notype_param_decl T_LBRACK constant T_RBRACK { | | 992 | | direct_notype_param_decl T_LBRACK constant T_RBRACK { |
992 | $$ = addarray($1, 1, toicon($3, 0)); | | 993 | $$ = addarray($1, 1, toicon($3, 0)); |
993 | } | | 994 | } |
994 | | direct_notype_param_decl param_list { | | 995 | | direct_notype_param_decl param_list { |
995 | $$ = addfunc($1, $2); | | 996 | $$ = addfunc($1, $2); |
996 | popdecl(); | | 997 | popdecl(); |
997 | blklev--; | | 998 | blklev--; |
998 | } | | 999 | } |
999 | ; | | 1000 | ; |
1000 | | | 1001 | |
1001 | pointer: | | 1002 | pointer: |
1002 | asterisk { | | 1003 | asterisk { |
1003 | $$ = $1; | | 1004 | $$ = $1; |
1004 | } | | 1005 | } |
1005 | | asterisk type_qualifier_list { | | 1006 | | asterisk type_qualifier_list { |
1006 | $$ = mergepq($1, $2); | | 1007 | $$ = mergepq($1, $2); |
1007 | } | | 1008 | } |
1008 | | asterisk pointer { | | 1009 | | asterisk pointer { |
1009 | $$ = mergepq($1, $2); | | 1010 | $$ = mergepq($1, $2); |
1010 | } | | 1011 | } |
1011 | | asterisk type_qualifier_list pointer { | | 1012 | | asterisk type_qualifier_list pointer { |
1012 | $$ = mergepq(mergepq($1, $2), $3); | | 1013 | $$ = mergepq(mergepq($1, $2), $3); |
1013 | } | | 1014 | } |
1014 | ; | | 1015 | ; |
1015 | | | 1016 | |
1016 | asterisk: | | 1017 | asterisk: |
1017 | T_MULT { | | 1018 | T_MULT { |
1018 | $$ = xcalloc(1, sizeof (pqinf_t)); | | 1019 | $$ = xcalloc(1, sizeof (pqinf_t)); |
1019 | $$->p_pcnt = 1; | | 1020 | $$->p_pcnt = 1; |
1020 | } | | 1021 | } |
1021 | ; | | 1022 | ; |
1022 | | | 1023 | |
1023 | type_qualifier_list: | | 1024 | type_qualifier_list: |
1024 | type_qualifier { | | 1025 | type_qualifier { |
1025 | $$ = $1; | | 1026 | $$ = $1; |
1026 | } | | 1027 | } |
1027 | | type_qualifier_list type_qualifier { | | 1028 | | type_qualifier_list type_qualifier { |
1028 | $$ = mergepq($1, $2); | | 1029 | $$ = mergepq($1, $2); |
1029 | } | | 1030 | } |
1030 | ; | | 1031 | ; |
1031 | | | 1032 | |
1032 | type_qualifier: | | 1033 | type_qualifier: |
1033 | T_QUAL { | | 1034 | T_QUAL { |
1034 | $$ = xcalloc(1, sizeof (pqinf_t)); | | 1035 | $$ = xcalloc(1, sizeof (pqinf_t)); |
1035 | if ($1 == CONST) { | | 1036 | if ($1 == CONST) { |
1036 | $$->p_const = 1; | | 1037 | $$->p_const = 1; |
1037 | } else { | | 1038 | } else { |
1038 | $$->p_volatile = 1; | | 1039 | $$->p_volatile = 1; |
1039 | } | | 1040 | } |
1040 | } | | 1041 | } |
1041 | ; | | 1042 | ; |
1042 | | | 1043 | |
1043 | param_list: | | 1044 | param_list: |
1044 | id_list_lparn identifier_list T_RPARN { | | 1045 | id_list_lparn identifier_list T_RPARN { |
1045 | $$ = $2; | | 1046 | $$ = $2; |
1046 | } | | 1047 | } |
1047 | | abs_decl_param_list { | | 1048 | | abs_decl_param_list { |
1048 | $$ = $1; | | 1049 | $$ = $1; |
1049 | } | | 1050 | } |
1050 | ; | | 1051 | ; |
1051 | | | 1052 | |
1052 | id_list_lparn: | | 1053 | id_list_lparn: |
1053 | T_LPARN { | | 1054 | T_LPARN { |
1054 | blklev++; | | 1055 | blklev++; |
1055 | pushdecl(PARG); | | 1056 | pushdecl(PARG); |
1056 | } | | 1057 | } |
1057 | ; | | 1058 | ; |
1058 | | | 1059 | |
1059 | identifier_list: | | 1060 | identifier_list: |
1060 | T_NAME { | | 1061 | T_NAME { |
1061 | $$ = iname(getsym($1)); | | 1062 | $$ = iname(getsym($1)); |
1062 | } | | 1063 | } |
1063 | | identifier_list T_COMMA T_NAME { | | 1064 | | identifier_list T_COMMA T_NAME { |
1064 | $$ = lnklst($1, iname(getsym($3))); | | 1065 | $$ = lnklst($1, iname(getsym($3))); |
1065 | } | | 1066 | } |
1066 | | identifier_list error { | | 1067 | | identifier_list error { |
1067 | $$ = $1; | | 1068 | $$ = $1; |
1068 | } | | 1069 | } |
1069 | ; | | 1070 | ; |
1070 | | | 1071 | |
1071 | abs_decl_param_list: | | 1072 | abs_decl_param_list: |
1072 | abs_decl_lparn T_RPARN { | | 1073 | abs_decl_lparn T_RPARN { |
1073 | $$ = NULL; | | 1074 | $$ = NULL; |
1074 | } | | 1075 | } |
1075 | | abs_decl_lparn vararg_parameter_type_list T_RPARN { | | 1076 | | abs_decl_lparn vararg_parameter_type_list T_RPARN { |
1076 | dcs->d_proto = 1; | | 1077 | dcs->d_proto = 1; |
1077 | $$ = $2; | | 1078 | $$ = $2; |
1078 | } | | 1079 | } |
1079 | | abs_decl_lparn error T_RPARN { | | 1080 | | abs_decl_lparn error T_RPARN { |
1080 | $$ = NULL; | | 1081 | $$ = NULL; |
1081 | } | | 1082 | } |
1082 | ; | | 1083 | ; |
1083 | | | 1084 | |
1084 | abs_decl_lparn: | | 1085 | abs_decl_lparn: |
1085 | T_LPARN { | | 1086 | T_LPARN { |
1086 | blklev++; | | 1087 | blklev++; |
1087 | pushdecl(PARG); | | 1088 | pushdecl(PARG); |
1088 | } | | 1089 | } |
1089 | ; | | 1090 | ; |
1090 | | | 1091 | |
1091 | vararg_parameter_type_list: | | 1092 | vararg_parameter_type_list: |
1092 | parameter_type_list { | | 1093 | parameter_type_list { |
1093 | $$ = $1; | | 1094 | $$ = $1; |
1094 | } | | 1095 | } |
1095 | | parameter_type_list T_COMMA T_ELLIPSE { | | 1096 | | parameter_type_list T_COMMA T_ELLIPSE { |
1096 | dcs->d_vararg = 1; | | 1097 | dcs->d_vararg = 1; |
1097 | $$ = $1; | | 1098 | $$ = $1; |
1098 | } | | 1099 | } |
1099 | | T_ELLIPSE { | | 1100 | | T_ELLIPSE { |
1100 | if (sflag) { | | 1101 | if (sflag) { |
1101 | /* ANSI C requires formal parameter before "..." */ | | 1102 | /* ANSI C requires formal parameter before "..." */ |
1102 | error(84); | | 1103 | error(84); |
1103 | } else if (!tflag) { | | 1104 | } else if (!tflag) { |
1104 | /* ANSI C requires formal parameter before "..." */ | | 1105 | /* ANSI C requires formal parameter before "..." */ |
1105 | warning(84); | | 1106 | warning(84); |
1106 | } | | 1107 | } |
1107 | dcs->d_vararg = 1; | | 1108 | dcs->d_vararg = 1; |
1108 | $$ = NULL; | | 1109 | $$ = NULL; |
1109 | } | | 1110 | } |
1110 | ; | | 1111 | ; |
1111 | | | 1112 | |
1112 | parameter_type_list: | | 1113 | parameter_type_list: |
1113 | parameter_declaration { | | 1114 | parameter_declaration { |
1114 | $$ = $1; | | 1115 | $$ = $1; |
1115 | } | | 1116 | } |
1116 | | parameter_type_list T_COMMA parameter_declaration { | | 1117 | | parameter_type_list T_COMMA parameter_declaration { |
1117 | $$ = lnklst($1, $3); | | 1118 | $$ = lnklst($1, $3); |
1118 | } | | 1119 | } |
1119 | ; | | 1120 | ; |
1120 | | | 1121 | |
1121 | parameter_declaration: | | 1122 | parameter_declaration: |
1122 | declmods deftyp { | | 1123 | declmods deftyp { |
1123 | $$ = decl1arg(aname(), 0); | | 1124 | $$ = decl1arg(aname(), 0); |
1124 | } | | 1125 | } |
1125 | | declspecs deftyp { | | 1126 | | declspecs deftyp { |
1126 | $$ = decl1arg(aname(), 0); | | 1127 | $$ = decl1arg(aname(), 0); |
1127 | } | | 1128 | } |
1128 | | declmods deftyp notype_param_decl { | | 1129 | | declmods deftyp notype_param_decl { |
1129 | $$ = decl1arg($3, 0); | | 1130 | $$ = decl1arg($3, 0); |
1130 | } | | 1131 | } |
1131 | /* | | 1132 | /* |
1132 | * param_decl is needed because of following conflict: | | 1133 | * param_decl is needed because of following conflict: |
1133 | * "typedef int a; f(int (a));" could be parsed as | | 1134 | * "typedef int a; f(int (a));" could be parsed as |
1134 | * "function with argument a of type int", or | | 1135 | * "function with argument a of type int", or |
1135 | * "function with an abstract argument of type function". | | 1136 | * "function with an abstract argument of type function". |
1136 | * This grammar realizes the second case. | | 1137 | * This grammar realizes the second case. |
1137 | */ | | 1138 | */ |
1138 | | declspecs deftyp param_decl { | | 1139 | | declspecs deftyp param_decl { |
1139 | $$ = decl1arg($3, 0); | | 1140 | $$ = decl1arg($3, 0); |
1140 | } | | 1141 | } |
1141 | | declmods deftyp abs_decl { | | 1142 | | declmods deftyp abs_decl { |
1142 | $$ = decl1arg($3, 0); | | 1143 | $$ = decl1arg($3, 0); |
1143 | } | | 1144 | } |
1144 | | declspecs deftyp abs_decl { | | 1145 | | declspecs deftyp abs_decl { |
1145 | $$ = decl1arg($3, 0); | | 1146 | $$ = decl1arg($3, 0); |
1146 | } | | 1147 | } |
1147 | ; | | 1148 | ; |
1148 | | | 1149 | |
1149 | opt_asm_or_symbolrename: /* expect only one */ | | 1150 | opt_asm_or_symbolrename: /* expect only one */ |
1150 | /* empty */ { | | 1151 | /* empty */ { |
1151 | $$ = NULL; | | 1152 | $$ = NULL; |
1152 | } | | 1153 | } |
1153 | | T_ASM T_LPARN T_STRING T_RPARN { | | 1154 | | T_ASM T_LPARN T_STRING T_RPARN { |
1154 | freeyyv(&$3, T_STRING); | | 1155 | freeyyv(&$3, T_STRING); |
1155 | $$ = NULL; | | 1156 | $$ = NULL; |
1156 | } | | 1157 | } |
1157 | | T_SYMBOLRENAME T_LPARN T_NAME T_RPARN { | | 1158 | | T_SYMBOLRENAME T_LPARN T_NAME T_RPARN { |
1158 | $$ = $3; | | 1159 | $$ = $3; |
1159 | } | | 1160 | } |
1160 | ; | | 1161 | ; |
1161 | | | 1162 | |
1162 | initializer: | | 1163 | initializer: |
1163 | init_expr | | 1164 | init_expr |
1164 | ; | | 1165 | ; |
1165 | | | 1166 | |
1166 | init_expr: | | 1167 | init_expr: |
1167 | expr %prec T_COMMA { | | 1168 | expr %prec T_COMMA { |
1168 | mkinit($1); | | 1169 | mkinit($1); |
1169 | } | | 1170 | } |
1170 | | init_by_name init_expr %prec T_COMMA | | 1171 | | init_by_name init_expr %prec T_COMMA |
1171 | | init_lbrace init_expr_list init_rbrace | | 1172 | | init_lbrace init_expr_list init_rbrace |
1172 | | init_lbrace init_expr_list T_COMMA init_rbrace | | 1173 | | init_lbrace init_expr_list T_COMMA init_rbrace |
1173 | | error | | 1174 | | error |
1174 | ; | | 1175 | ; |
1175 | | | 1176 | |
1176 | init_expr_list: | | 1177 | init_expr_list: |
1177 | init_expr %prec T_COMMA | | 1178 | init_expr %prec T_COMMA |
1178 | | init_expr_list T_COMMA init_expr | | 1179 | | init_expr_list T_COMMA init_expr |
1179 | ; | | 1180 | ; |
1180 | | | 1181 | |
1181 | lorange: | | 1182 | lorange: |
1182 | constant T_ELLIPSE { | | 1183 | constant T_ELLIPSE { |
1183 | $$.lo = toicon($1, 1); | | 1184 | $$.lo = toicon($1, 1); |
1184 | } | | 1185 | } |
1185 | ; | | 1186 | ; |
1186 | range: | | 1187 | range: |
1187 | constant { | | 1188 | constant { |
1188 | $$.lo = toicon($1, 1); | | 1189 | $$.lo = toicon($1, 1); |
1189 | $$.hi = $$.lo + 1; | | 1190 | $$.hi = $$.lo + 1; |
1190 | } | | 1191 | } |
1191 | | lorange constant { | | 1192 | | lorange constant { |
1192 | $$.lo = $1.lo; | | 1193 | $$.lo = $1.lo; |
1193 | $$.hi = toicon($2, 1); | | 1194 | $$.hi = toicon($2, 1); |
1194 | } | | 1195 | } |
1195 | ; | | 1196 | ; |
1196 | | | 1197 | |
1197 | init_by_name: | | 1198 | init_by_name: |
1198 | T_LBRACK range T_RBRACK T_ASSIGN { | | 1199 | T_LBRACK range T_RBRACK T_ASSIGN { |
1199 | if (!Sflag) | | 1200 | if (!Sflag) |
1200 | warning(321); | | 1201 | warning(321); |
1201 | } | | 1202 | } |
1202 | | point identifier T_ASSIGN { | | 1203 | | point identifier T_ASSIGN { |
1203 | if (!Sflag) | | 1204 | if (!Sflag) |
1204 | warning(313); | | 1205 | warning(313); |
1205 | memberpush($2); | | 1206 | memberpush($2); |
1206 | } | | 1207 | } |
1207 | | identifier T_COLON { | | 1208 | | identifier T_COLON { |
1208 | gnuism(315); | | 1209 | gnuism(315); |
1209 | memberpush($1); | | 1210 | memberpush($1); |
1210 | } | | 1211 | } |
1211 | ; | | 1212 | ; |
1212 | | | 1213 | |
1213 | init_lbrace: | | 1214 | init_lbrace: |
1214 | T_LBRACE { | | 1215 | T_LBRACE { |
1215 | initlbr(); | | 1216 | initlbr(); |
1216 | } | | 1217 | } |
1217 | ; | | 1218 | ; |
1218 | | | 1219 | |
1219 | init_rbrace: | | 1220 | init_rbrace: |
1220 | T_RBRACE { | | 1221 | T_RBRACE { |
1221 | initrbr(); | | 1222 | initrbr(); |
1222 | } | | 1223 | } |
1223 | ; | | 1224 | ; |
1224 | | | 1225 | |
1225 | type_name: | | 1226 | type_name: |
1226 | { | | 1227 | { |
1227 | pushdecl(ABSTRACT); | | 1228 | pushdecl(ABSTRACT); |
1228 | } abstract_declaration { | | 1229 | } abstract_declaration { |
1229 | popdecl(); | | 1230 | popdecl(); |
1230 | $$ = $2->s_type; | | 1231 | $$ = $2->s_type; |
1231 | } | | 1232 | } |
1232 | ; | | 1233 | ; |
1233 | | | 1234 | |
1234 | abstract_declaration: | | 1235 | abstract_declaration: |
1235 | noclass_declmods deftyp { | | 1236 | noclass_declmods deftyp { |
1236 | $$ = decl1abs(aname()); | | 1237 | $$ = decl1abs(aname()); |
1237 | } | | 1238 | } |
1238 | | noclass_declspecs deftyp { | | 1239 | | noclass_declspecs deftyp { |
1239 | $$ = decl1abs(aname()); | | 1240 | $$ = decl1abs(aname()); |
1240 | } | | 1241 | } |
1241 | | noclass_declmods deftyp abs_decl { | | 1242 | | noclass_declmods deftyp abs_decl { |
1242 | $$ = decl1abs($3); | | 1243 | $$ = decl1abs($3); |
1243 | } | | 1244 | } |
1244 | | noclass_declspecs deftyp abs_decl { | | 1245 | | noclass_declspecs deftyp abs_decl { |
1245 | $$ = decl1abs($3); | | 1246 | $$ = decl1abs($3); |
1246 | } | | 1247 | } |
1247 | ; | | 1248 | ; |
1248 | | | 1249 | |
1249 | abs_decl: | | 1250 | abs_decl: |
1250 | pointer { | | 1251 | pointer { |
1251 | $$ = addptr(aname(), $1); | | 1252 | $$ = addptr(aname(), $1); |
1252 | } | | 1253 | } |
1253 | | direct_abs_decl { | | 1254 | | direct_abs_decl { |
1254 | $$ = $1; | | 1255 | $$ = $1; |
1255 | } | | 1256 | } |
1256 | | pointer direct_abs_decl { | | 1257 | | pointer direct_abs_decl { |
1257 | $$ = addptr($2, $1); | | 1258 | $$ = addptr($2, $1); |
1258 | } | | 1259 | } |
1259 | ; | | 1260 | ; |
1260 | | | 1261 | |
1261 | direct_abs_decl: | | 1262 | direct_abs_decl: |
1262 | T_LPARN abs_decl T_RPARN { | | 1263 | T_LPARN abs_decl T_RPARN { |
1263 | $$ = $2; | | 1264 | $$ = $2; |
1264 | } | | 1265 | } |
1265 | | T_LBRACK T_RBRACK { | | 1266 | | T_LBRACK T_RBRACK { |
1266 | $$ = addarray(aname(), 0, 0); | | 1267 | $$ = addarray(aname(), 0, 0); |
1267 | } | | 1268 | } |
1268 | | T_LBRACK constant T_RBRACK { | | 1269 | | T_LBRACK constant T_RBRACK { |
1269 | $$ = addarray(aname(), 1, toicon($2, 0)); | | 1270 | $$ = addarray(aname(), 1, toicon($2, 0)); |
1270 | } | | 1271 | } |
1271 | | direct_abs_decl T_LBRACK T_RBRACK { | | 1272 | | direct_abs_decl T_LBRACK T_RBRACK { |
1272 | $$ = addarray($1, 0, 0); | | 1273 | $$ = addarray($1, 0, 0); |
1273 | } | | 1274 | } |
1274 | | direct_abs_decl T_LBRACK constant T_RBRACK { | | 1275 | | direct_abs_decl T_LBRACK constant T_RBRACK { |
1275 | $$ = addarray($1, 1, toicon($3, 0)); | | 1276 | $$ = addarray($1, 1, toicon($3, 0)); |
1276 | } | | 1277 | } |
1277 | | abs_decl_param_list { | | 1278 | | abs_decl_param_list { |
1278 | $$ = addfunc(aname(), $1); | | 1279 | $$ = addfunc(aname(), $1); |
1279 | popdecl(); | | 1280 | popdecl(); |
1280 | blklev--; | | 1281 | blklev--; |
1281 | } | | 1282 | } |
1282 | | direct_abs_decl abs_decl_param_list { | | 1283 | | direct_abs_decl abs_decl_param_list { |
1283 | $$ = addfunc($1, $2); | | 1284 | $$ = addfunc($1, $2); |
1284 | popdecl(); | | 1285 | popdecl(); |
1285 | blklev--; | | 1286 | blklev--; |
1286 | } | | 1287 | } |
1287 | ; | | 1288 | ; |
1288 | | | 1289 | |
1289 | non_expr_stmnt: | | 1290 | non_expr_stmnt: |
1290 | labeled_stmnt | | 1291 | labeled_stmnt |
1291 | | comp_stmnt | | 1292 | | comp_stmnt |
1292 | | selection_stmnt | | 1293 | | selection_stmnt |
1293 | | iteration_stmnt | | 1294 | | iteration_stmnt |
1294 | | jump_stmnt { | | 1295 | | jump_stmnt { |
1295 | ftflg = 0; | | 1296 | ftflg = 0; |
1296 | } | | 1297 | } |
1297 | | asm_stmnt | | 1298 | | asm_stmnt |
1298 | | | 1299 | |
1299 | stmnt: | | 1300 | stmnt: |
1300 | expr_stmnt | | 1301 | expr_stmnt |
1301 | | non_expr_stmnt | | 1302 | | non_expr_stmnt |
1302 | ; | | 1303 | ; |
1303 | | | 1304 | |
1304 | labeled_stmnt: | | 1305 | labeled_stmnt: |
1305 | label stmnt | | 1306 | label stmnt |
1306 | ; | | 1307 | ; |
1307 | | | 1308 | |
1308 | label: | | 1309 | label: |
1309 | identifier T_COLON { | | 1310 | identifier T_COLON { |
1310 | symtyp = FLAB; | | 1311 | symtyp = FLAB; |
1311 | label(T_NAME, getsym($1), NULL); | | 1312 | label(T_NAME, getsym($1), NULL); |
1312 | } | | 1313 | } |
1313 | | T_CASE constant T_COLON { | | 1314 | | T_CASE constant T_COLON { |
1314 | label(T_CASE, NULL, $2); | | 1315 | label(T_CASE, NULL, $2); |
1315 | ftflg = 1; | | 1316 | ftflg = 1; |
1316 | } | | 1317 | } |
1317 | | T_CASE constant T_ELLIPSE constant T_COLON { | | 1318 | | T_CASE constant T_ELLIPSE constant T_COLON { |
1318 | /* XXX: We don't fill all cases */ | | 1319 | /* XXX: We don't fill all cases */ |
1319 | label(T_CASE, NULL, $2); | | 1320 | label(T_CASE, NULL, $2); |
1320 | ftflg = 1; | | 1321 | ftflg = 1; |
1321 | } | | 1322 | } |
1322 | | T_DEFAULT T_COLON { | | 1323 | | T_DEFAULT T_COLON { |
1323 | label(T_DEFAULT, NULL, NULL); | | 1324 | label(T_DEFAULT, NULL, NULL); |
1324 | ftflg = 1; | | 1325 | ftflg = 1; |
1325 | } | | 1326 | } |
1326 | ; | | 1327 | ; |
1327 | | | 1328 | |
1328 | comp_stmnt: | | 1329 | comp_stmnt: |
1329 | comp_stmnt_lbrace declaration_list opt_stmnt_list comp_stmnt_rbrace | | 1330 | comp_stmnt_lbrace declaration_list opt_stmnt_list comp_stmnt_rbrace |
1330 | | comp_stmnt_lbrace opt_stmnt_list comp_stmnt_rbrace | | 1331 | | comp_stmnt_lbrace opt_stmnt_list comp_stmnt_rbrace |
1331 | ; | | 1332 | ; |
1332 | | | 1333 | |
1333 | comp_stmnt_lbrace: | | 1334 | comp_stmnt_lbrace: |
1334 | T_LBRACE { | | 1335 | T_LBRACE { |
1335 | blklev++; | | 1336 | blklev++; |
1336 | mblklev++; | | 1337 | mblklev++; |
1337 | pushdecl(AUTO); | | 1338 | pushdecl(AUTO); |
1338 | } | | 1339 | } |
1339 | ; | | 1340 | ; |
1340 | | | 1341 | |
1341 | comp_stmnt_rbrace: | | 1342 | comp_stmnt_rbrace: |
1342 | T_RBRACE { | | 1343 | T_RBRACE { |
1343 | popdecl(); | | 1344 | popdecl(); |
1344 | freeblk(); | | 1345 | freeblk(); |
1345 | mblklev--; | | 1346 | mblklev--; |
1346 | blklev--; | | 1347 | blklev--; |
1347 | ftflg = 0; | | 1348 | ftflg = 0; |
1348 | } | | 1349 | } |
1349 | ; | | 1350 | ; |
1350 | | | 1351 | |
1351 | opt_stmnt_list: | | 1352 | opt_stmnt_list: |
1352 | /* empty */ | | 1353 | /* empty */ |
1353 | | stmnt_list | | 1354 | | stmnt_list |
1354 | ; | | 1355 | ; |
1355 | | | 1356 | |
1356 | stmnt_list: | | 1357 | stmnt_list: |
1357 | stmnt | | 1358 | stmnt |
1358 | | stmnt_list stmnt { | | 1359 | | stmnt_list stmnt { |
1359 | RESTORE(__FILE__, __LINE__); | | 1360 | RESTORE(__FILE__, __LINE__); |
1360 | } | | 1361 | } |
1361 | | stmnt_list error T_SEMI | | 1362 | | stmnt_list error T_SEMI |
1362 | ; | | 1363 | ; |
1363 | | | 1364 | |
1364 | expr_stmnt: | | 1365 | expr_stmnt: |
1365 | expr T_SEMI { | | 1366 | expr T_SEMI { |
1366 | expr($1, 0, 0, 1); | | 1367 | expr($1, 0, 0, 1); |
1367 | ftflg = 0; | | 1368 | ftflg = 0; |
1368 | } | | 1369 | } |
1369 | | T_SEMI { | | 1370 | | T_SEMI { |
1370 | ftflg = 0; | | 1371 | ftflg = 0; |
1371 | } | | 1372 | } |
1372 | ; | | 1373 | ; |
1373 | | | 1374 | |
1374 | /* | | 1375 | /* |
1375 | * The following two productions are used to implement | | 1376 | * The following two productions are used to implement |
1376 | * ({ [[decl-list] stmt-list] }). | | 1377 | * ({ [[decl-list] stmt-list] }). |
1377 | * XXX: This is not well tested. | | 1378 | * XXX: This is not well tested. |
1378 | */ | | 1379 | */ |
1379 | expr_stmnt_val: | | 1380 | expr_stmnt_val: |
1380 | expr T_SEMI { | | 1381 | expr T_SEMI { |
1381 | /* XXX: We should really do that only on the last name */ | | 1382 | /* XXX: We should really do that only on the last name */ |
1382 | if ($1->tn_op == NAME) | | 1383 | if ($1->tn_op == NAME) |
1383 | $1->tn_sym->s_used = 1; | | 1384 | $1->tn_sym->s_used = 1; |
1384 | $$ = $1; | | 1385 | $$ = $1; |
1385 | expr($1, 0, 0, 0); | | 1386 | expr($1, 0, 0, 0); |
1386 | ftflg = 0; | | 1387 | ftflg = 0; |
1387 | } | | 1388 | } |
1388 | | non_expr_stmnt { | | 1389 | | non_expr_stmnt { |
1389 | $$ = getnode(); | | 1390 | $$ = getnode(); |
1390 | $$->tn_type = gettyp(VOID); | | 1391 | $$->tn_type = gettyp(VOID); |
1391 | } | | 1392 | } |
1392 | ; | | 1393 | ; |
1393 | | | 1394 | |
1394 | expr_stmnt_list: | | 1395 | expr_stmnt_list: |
1395 | expr_stmnt_val | | 1396 | expr_stmnt_val |
1396 | | expr_stmnt_list expr_stmnt_val { | | 1397 | | expr_stmnt_list expr_stmnt_val { |
1397 | $$ = $2; | | 1398 | $$ = $2; |
1398 | } | | 1399 | } |
1399 | ; | | 1400 | ; |
1400 | | | 1401 | |
1401 | selection_stmnt: | | 1402 | selection_stmnt: |
1402 | if_without_else { | | 1403 | if_without_else { |
1403 | SAVE(__FILE__, __LINE__); | | 1404 | SAVE(__FILE__, __LINE__); |
1404 | if2(); | | 1405 | if2(); |
1405 | if3(0); | | 1406 | if3(0); |
1406 | } | | 1407 | } |
1407 | | if_without_else T_ELSE { | | 1408 | | if_without_else T_ELSE { |
1408 | SAVE(__FILE__, __LINE__); | | 1409 | SAVE(__FILE__, __LINE__); |
1409 | if2(); | | 1410 | if2(); |
1410 | } stmnt { | | 1411 | } stmnt { |
1411 | CLRWFLGS(__FILE__, __LINE__); | | 1412 | CLRWFLGS(__FILE__, __LINE__); |
1412 | if3(1); | | 1413 | if3(1); |
1413 | } | | 1414 | } |
1414 | | if_without_else T_ELSE error { | | 1415 | | if_without_else T_ELSE error { |
1415 | CLRWFLGS(__FILE__, __LINE__); | | 1416 | CLRWFLGS(__FILE__, __LINE__); |
1416 | if3(0); | | 1417 | if3(0); |
1417 | } | | 1418 | } |
1418 | | switch_expr stmnt { | | 1419 | | switch_expr stmnt { |
1419 | CLRWFLGS(__FILE__, __LINE__); | | 1420 | CLRWFLGS(__FILE__, __LINE__); |
1420 | switch2(); | | 1421 | switch2(); |
1421 | } | | 1422 | } |
1422 | | switch_expr error { | | 1423 | | switch_expr error { |
1423 | CLRWFLGS(__FILE__, __LINE__); | | 1424 | CLRWFLGS(__FILE__, __LINE__); |
1424 | switch2(); | | 1425 | switch2(); |
1425 | } | | 1426 | } |
1426 | ; | | 1427 | ; |
1427 | | | 1428 | |
1428 | if_without_else: | | 1429 | if_without_else: |
1429 | if_expr stmnt | | 1430 | if_expr stmnt |
1430 | | if_expr error | | 1431 | | if_expr error |
1431 | ; | | 1432 | ; |
1432 | | | 1433 | |
1433 | if_expr: | | 1434 | if_expr: |
1434 | T_IF T_LPARN expr T_RPARN { | | 1435 | T_IF T_LPARN expr T_RPARN { |
1435 | if1($3); | | 1436 | if1($3); |
1436 | CLRWFLGS(__FILE__, __LINE__); | | 1437 | CLRWFLGS(__FILE__, __LINE__); |
1437 | } | | 1438 | } |
1438 | ; | | 1439 | ; |
1439 | | | 1440 | |
1440 | switch_expr: | | 1441 | switch_expr: |
1441 | T_SWITCH T_LPARN expr T_RPARN { | | 1442 | T_SWITCH T_LPARN expr T_RPARN { |
1442 | switch1($3); | | 1443 | switch1($3); |
1443 | CLRWFLGS(__FILE__, __LINE__); | | 1444 | CLRWFLGS(__FILE__, __LINE__); |
1444 | } | | 1445 | } |
1445 | ; | | 1446 | ; |
1446 | | | 1447 | |
1447 | do_stmnt: | | 1448 | do_stmnt: |
1448 | do stmnt { | | 1449 | do stmnt { |
1449 | CLRWFLGS(__FILE__, __LINE__); | | 1450 | CLRWFLGS(__FILE__, __LINE__); |
1450 | } | | 1451 | } |
1451 | ; | | 1452 | ; |
1452 | | | 1453 | |
1453 | iteration_stmnt: | | 1454 | iteration_stmnt: |
1454 | while_expr stmnt { | | 1455 | while_expr stmnt { |
1455 | CLRWFLGS(__FILE__, __LINE__); | | 1456 | CLRWFLGS(__FILE__, __LINE__); |
1456 | while2(); | | 1457 | while2(); |
1457 | } | | 1458 | } |
1458 | | while_expr error { | | 1459 | | while_expr error { |
1459 | CLRWFLGS(__FILE__, __LINE__); | | 1460 | CLRWFLGS(__FILE__, __LINE__); |
1460 | while2(); | | 1461 | while2(); |
1461 | } | | 1462 | } |
1462 | | do_stmnt do_while_expr { | | 1463 | | do_stmnt do_while_expr { |
1463 | do2($2); | | 1464 | do2($2); |
1464 | ftflg = 0; | | 1465 | ftflg = 0; |
1465 | } | | 1466 | } |
1466 | | do error { | | 1467 | | do error { |
1467 | CLRWFLGS(__FILE__, __LINE__); | | 1468 | CLRWFLGS(__FILE__, __LINE__); |
1468 | do2(NULL); | | 1469 | do2(NULL); |
1469 | } | | 1470 | } |
1470 | | for_exprs stmnt { | | 1471 | | for_exprs stmnt { |
1471 | CLRWFLGS(__FILE__, __LINE__); | | 1472 | CLRWFLGS(__FILE__, __LINE__); |
1472 | for2(); | | 1473 | for2(); |
1473 | } | | 1474 | } |
1474 | | for_exprs error { | | 1475 | | for_exprs error { |
1475 | CLRWFLGS(__FILE__, __LINE__); | | 1476 | CLRWFLGS(__FILE__, __LINE__); |
1476 | for2(); | | 1477 | for2(); |
1477 | } | | 1478 | } |
1478 | ; | | 1479 | ; |
1479 | | | 1480 | |
1480 | while_expr: | | 1481 | while_expr: |
1481 | T_WHILE T_LPARN expr T_RPARN { | | 1482 | T_WHILE T_LPARN expr T_RPARN { |
1482 | while1($3); | | 1483 | while1($3); |
1483 | CLRWFLGS(__FILE__, __LINE__); | | 1484 | CLRWFLGS(__FILE__, __LINE__); |
1484 | } | | 1485 | } |
1485 | ; | | 1486 | ; |
1486 | | | 1487 | |
1487 | do: | | 1488 | do: |
1488 | T_DO { | | 1489 | T_DO { |
1489 | do1(); | | 1490 | do1(); |
1490 | } | | 1491 | } |
1491 | ; | | 1492 | ; |
1492 | | | 1493 | |
1493 | do_while_expr: | | 1494 | do_while_expr: |
1494 | T_WHILE T_LPARN expr T_RPARN T_SEMI { | | 1495 | T_WHILE T_LPARN expr T_RPARN T_SEMI { |
1495 | $$ = $3; | | 1496 | $$ = $3; |
1496 | } | | 1497 | } |
1497 | ; | | 1498 | ; |
1498 | | | 1499 | |
1499 | for_exprs: | | 1500 | for_exprs: |
1500 | T_FOR T_LPARN declspecs deftyp notype_init_decls T_SEMI opt_expr | | 1501 | T_FOR T_LPARN declspecs deftyp notype_init_decls T_SEMI opt_expr |
1501 | T_SEMI opt_expr T_RPARN { | | 1502 | T_SEMI opt_expr T_RPARN { |
1502 | c99ism(325); | | 1503 | c99ism(325); |
1503 | for1(NULL, $7, $9); | | 1504 | for1(NULL, $7, $9); |
1504 | CLRWFLGS(__FILE__, __LINE__); | | 1505 | CLRWFLGS(__FILE__, __LINE__); |
1505 | } | | 1506 | } |
1506 | | T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN { | | 1507 | | T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN { |
1507 | for1($3, $5, $7); | | 1508 | for1($3, $5, $7); |
1508 | CLRWFLGS(__FILE__, __LINE__); | | 1509 | CLRWFLGS(__FILE__, __LINE__); |
1509 | } | | 1510 | } |
1510 | ; | | 1511 | ; |
1511 | | | 1512 | |
1512 | opt_expr: | | 1513 | opt_expr: |
1513 | /* empty */ { | | 1514 | /* empty */ { |
1514 | $$ = NULL; | | 1515 | $$ = NULL; |
1515 | } | | 1516 | } |
1516 | | expr { | | 1517 | | expr { |
1517 | $$ = $1; | | 1518 | $$ = $1; |
1518 | } | | 1519 | } |
1519 | ; | | 1520 | ; |
1520 | | | 1521 | |
1521 | jump_stmnt: | | 1522 | jump_stmnt: |
1522 | goto identifier T_SEMI { | | 1523 | goto identifier T_SEMI { |
1523 | dogoto(getsym($2)); | | 1524 | dogoto(getsym($2)); |
1524 | } | | 1525 | } |
1525 | | goto error T_SEMI { | | 1526 | | goto error T_SEMI { |
1526 | symtyp = FVFT; | | 1527 | symtyp = FVFT; |
1527 | } | | 1528 | } |
1528 | | T_CONTINUE T_SEMI { | | 1529 | | T_CONTINUE T_SEMI { |
1529 | docont(); | | 1530 | docont(); |
1530 | } | | 1531 | } |
1531 | | T_BREAK T_SEMI { | | 1532 | | T_BREAK T_SEMI { |
1532 | dobreak(); | | 1533 | dobreak(); |
1533 | } | | 1534 | } |
1534 | | T_RETURN T_SEMI { | | 1535 | | T_RETURN T_SEMI { |
1535 | doreturn(NULL); | | 1536 | doreturn(NULL); |
1536 | } | | 1537 | } |
1537 | | T_RETURN expr T_SEMI { | | 1538 | | T_RETURN expr T_SEMI { |
1538 | doreturn($2); | | 1539 | doreturn($2); |
1539 | } | | 1540 | } |
1540 | ; | | 1541 | ; |
1541 | | | 1542 | |
1542 | goto: | | 1543 | goto: |
1543 | T_GOTO { | | 1544 | T_GOTO { |
1544 | symtyp = FLAB; | | 1545 | symtyp = FLAB; |
1545 | } | | 1546 | } |
1546 | ; | | 1547 | ; |
1547 | | | 1548 | |
1548 | asm_stmnt: | | 1549 | asm_stmnt: |
1549 | T_ASM T_LPARN read_until_rparn T_SEMI { | | 1550 | T_ASM T_LPARN read_until_rparn T_SEMI { |
1550 | setasm(); | | 1551 | setasm(); |
1551 | } | | 1552 | } |
1552 | | T_ASM T_QUAL T_LPARN read_until_rparn T_SEMI { | | 1553 | | T_ASM T_QUAL T_LPARN read_until_rparn T_SEMI { |
1553 | setasm(); | | 1554 | setasm(); |
1554 | } | | 1555 | } |
1555 | | T_ASM error | | 1556 | | T_ASM error |
1556 | ; | | 1557 | ; |
1557 | | | 1558 | |
1558 | read_until_rparn: | | 1559 | read_until_rparn: |
1559 | /* empty */ { | | 1560 | /* empty */ { |
1560 | ignuptorp(); | | 1561 | ignuptorp(); |
1561 | } | | 1562 | } |
1562 | ; | | 1563 | ; |
1563 | | | 1564 | |
1564 | declaration_list: | | 1565 | declaration_list: |
1565 | declaration { | | 1566 | declaration { |
1566 | CLRWFLGS(__FILE__, __LINE__); | | 1567 | CLRWFLGS(__FILE__, __LINE__); |
1567 | } | | 1568 | } |
1568 | | declaration_list declaration { | | 1569 | | declaration_list declaration { |
1569 | CLRWFLGS(__FILE__, __LINE__); | | 1570 | CLRWFLGS(__FILE__, __LINE__); |
1570 | } | | 1571 | } |
1571 | ; | | 1572 | ; |
1572 | | | 1573 | |
1573 | constant: | | 1574 | constant: |
1574 | expr %prec T_COMMA { | | 1575 | expr %prec T_COMMA { |
1575 | $$ = $1; | | 1576 | $$ = $1; |
1576 | } | | 1577 | } |
1577 | ; | | 1578 | ; |
1578 | | | 1579 | |
1579 | expr: | | 1580 | expr: |
1580 | expr T_MULT expr { | | 1581 | expr T_MULT expr { |
1581 | $$ = build(MULT, $1, $3); | | 1582 | $$ = build(MULT, $1, $3); |
1582 | } | | 1583 | } |
1583 | | expr T_DIVOP expr { | | 1584 | | expr T_DIVOP expr { |
1584 | $$ = build($2, $1, $3); | | 1585 | $$ = build($2, $1, $3); |
1585 | } | | 1586 | } |
1586 | | expr T_ADDOP expr { | | 1587 | | expr T_ADDOP expr { |
1587 | $$ = build($2, $1, $3); | | 1588 | $$ = build($2, $1, $3); |
1588 | } | | 1589 | } |
1589 | | expr T_SHFTOP expr { | | 1590 | | expr T_SHFTOP expr { |
1590 | $$ = build($2, $1, $3); | | 1591 | $$ = build($2, $1, $3); |
1591 | } | | 1592 | } |
1592 | | expr T_RELOP expr { | | 1593 | | expr T_RELOP expr { |
1593 | $$ = build($2, $1, $3); | | 1594 | $$ = build($2, $1, $3); |
1594 | } | | 1595 | } |
1595 | | expr T_EQOP expr { | | 1596 | | expr T_EQOP expr { |
1596 | $$ = build($2, $1, $3); | | 1597 | $$ = build($2, $1, $3); |
1597 | } | | 1598 | } |
1598 | | expr T_AND expr { | | 1599 | | expr T_AND expr { |
1599 | $$ = build(AND, $1, $3); | | 1600 | $$ = build(AND, $1, $3); |
1600 | } | | 1601 | } |
1601 | | expr T_XOR expr { | | 1602 | | expr T_XOR expr { |
1602 | $$ = build(XOR, $1, $3); | | 1603 | $$ = build(XOR, $1, $3); |
1603 | } | | 1604 | } |
1604 | | expr T_OR expr { | | 1605 | | expr T_OR expr { |
1605 | $$ = build(OR, $1, $3); | | 1606 | $$ = build(OR, $1, $3); |
1606 | } | | 1607 | } |
1607 | | expr T_LOGAND expr { | | 1608 | | expr T_LOGAND expr { |
1608 | $$ = build(LOGAND, $1, $3); | | 1609 | $$ = build(LOGAND, $1, $3); |
1609 | } | | 1610 | } |
1610 | | expr T_LOGOR expr { | | 1611 | | expr T_LOGOR expr { |
1611 | $$ = build(LOGOR, $1, $3); | | 1612 | $$ = build(LOGOR, $1, $3); |
1612 | } | | 1613 | } |
1613 | | expr T_QUEST expr T_COLON expr { | | 1614 | | expr T_QUEST expr T_COLON expr { |
1614 | $$ = build(QUEST, $1, build(COLON, $3, $5)); | | 1615 | $$ = build(QUEST, $1, build(COLON, $3, $5)); |
1615 | } | | 1616 | } |
1616 | | expr T_ASSIGN expr { | | 1617 | | expr T_ASSIGN expr { |
1617 | $$ = build(ASSIGN, $1, $3); | | 1618 | $$ = build(ASSIGN, $1, $3); |
1618 | } | | 1619 | } |
1619 | | expr T_OPASS expr { | | 1620 | | expr T_OPASS expr { |
1620 | $$ = build($2, $1, $3); | | 1621 | $$ = build($2, $1, $3); |
1621 | } | | 1622 | } |
1622 | | expr T_COMMA expr { | | 1623 | | expr T_COMMA expr { |
1623 | $$ = build(COMMA, $1, $3); | | 1624 | $$ = build(COMMA, $1, $3); |
1624 | } | | 1625 | } |
1625 | | term { | | 1626 | | term { |
1626 | $$ = $1; | | 1627 | $$ = $1; |
1627 | } | | 1628 | } |
1628 | ; | | 1629 | ; |
1629 | | | 1630 | |
1630 | term: | | 1631 | term: |
1631 | T_NAME { | | 1632 | T_NAME { |
1632 | /* XXX really necessary? */ | | 1633 | /* XXX really necessary? */ |
1633 | if (yychar < 0) | | 1634 | if (yychar < 0) |
1634 | yychar = yylex(); | | 1635 | yychar = yylex(); |
1635 | $$ = getnnode(getsym($1), yychar); | | 1636 | $$ = getnnode(getsym($1), yychar); |
1636 | } | | 1637 | } |
1637 | | string { | | 1638 | | string { |
1638 | $$ = getsnode($1); | | 1639 | $$ = getsnode($1); |
1639 | } | | 1640 | } |
1640 | | T_CON { | | 1641 | | T_CON { |
1641 | $$ = getcnode(gettyp($1->v_tspec), $1); | | 1642 | $$ = getcnode(gettyp($1->v_tspec), $1); |
1642 | } | | 1643 | } |
1643 | | T_LPARN expr T_RPARN { | | 1644 | | T_LPARN expr T_RPARN { |
1644 | if ($2 != NULL) | | 1645 | if ($2 != NULL) |
1645 | $2->tn_parn = 1; | | 1646 | $2->tn_parn = 1; |
1646 | $$ = $2; | | 1647 | $$ = $2; |
1647 | } | | 1648 | } |
1648 | | T_LPARN comp_stmnt_lbrace declaration_list expr_stmnt_list { | | 1649 | | T_LPARN comp_stmnt_lbrace declaration_list expr_stmnt_list { |
1649 | blklev--; | | 1650 | blklev--; |
1650 | mblklev--; | | 1651 | mblklev--; |
1651 | initsym = mktempsym(duptyp($4->tn_type)); | | 1652 | initsym = mktempsym(duptyp($4->tn_type)); |
1652 | mblklev++; | | 1653 | mblklev++; |
1653 | blklev++; | | 1654 | blklev++; |
1654 | gnuism(320); | | 1655 | gnuism(320); |
1655 | } comp_stmnt_rbrace T_RPARN { | | 1656 | } comp_stmnt_rbrace T_RPARN { |
1656 | $$ = getnnode(initsym, 0); | | 1657 | $$ = getnnode(initsym, 0); |
1657 | } | | 1658 | } |
1658 | | T_LPARN comp_stmnt_lbrace expr_stmnt_list { | | 1659 | | T_LPARN comp_stmnt_lbrace expr_stmnt_list { |
1659 | blklev--; | | 1660 | blklev--; |
1660 | mblklev--; | | 1661 | mblklev--; |
1661 | initsym = mktempsym($3->tn_type); | | 1662 | initsym = mktempsym($3->tn_type); |
1662 | mblklev++; | | 1663 | mblklev++; |
1663 | blklev++; | | 1664 | blklev++; |
1664 | gnuism(320); | | 1665 | gnuism(320); |
1665 | } comp_stmnt_rbrace T_RPARN { | | 1666 | } comp_stmnt_rbrace T_RPARN { |
1666 | $$ = getnnode(initsym, 0); | | 1667 | $$ = getnnode(initsym, 0); |
1667 | } | | 1668 | } |
1668 | | term T_INCDEC { | | 1669 | | term T_INCDEC { |
1669 | $$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL); | | 1670 | $$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL); |
1670 | } | | 1671 | } |
1671 | | T_INCDEC term { | | 1672 | | T_INCDEC term { |
1672 | $$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL); | | 1673 | $$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL); |
1673 | } | | 1674 | } |
1674 | | T_MULT term { | | 1675 | | T_MULT term { |
1675 | $$ = build(STAR, $2, NULL); | | 1676 | $$ = build(STAR, $2, NULL); |
1676 | } | | 1677 | } |
1677 | | T_AND term { | | 1678 | | T_AND term { |
1678 | $$ = build(AMPER, $2, NULL); | | 1679 | $$ = build(AMPER, $2, NULL); |
1679 | } | | 1680 | } |
1680 | | T_UNOP term { | | 1681 | | T_UNOP term { |
1681 | $$ = build($1, $2, NULL); | | 1682 | $$ = build($1, $2, NULL); |
1682 | } | | 1683 | } |
1683 | | T_ADDOP term { | | 1684 | | T_ADDOP term { |
1684 | if (tflag && $1 == PLUS) { | | 1685 | if (tflag && $1 == PLUS) { |
1685 | /* unary + is illegal in traditional C */ | | 1686 | /* unary + is illegal in traditional C */ |