source: code/trunk/vendor/modernc.org/cc/v3/parser.yy@ 822

Last change on this file since 822 was 822, checked in by yakumo.izuru, 22 months ago

Prefer immortal.run over runit and rc.d, use vendored modules
for convenience.

Signed-off-by: Izuru Yakumo <yakumo.izuru@…>

File size: 35.0 KB
Line 
1%{
2// Copyright 2019 The CC Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file.
5
6// Based on [0], 6.5-6.10.
7
8package cc // import "modernc.org/cc/v3"
9
10%}
11
12%union {
13 Token Token
14 node Node
15}
16
17%token
18 /*yy:token "%c" */ IDENTIFIER
19 /*yy:token "%c_e" */ ENUMCONST
20 /*yy:token "%c_t" */ TYPEDEFNAME
21 /*yy:token "%d" */ INTCONST
22 /*yy:token "'%c'" */ CHARCONST
23 /*yy:token "1.%d" */ FLOATCONST
24 /*yy:token "L'%c'" */ LONGCHARCONST
25 /*yy:token "L\"%c\"" */ LONGSTRINGLITERAL
26 /*yy:token "\"%c\"" */ STRINGLITERAL
27
28 ACCUM "_Accum"
29 ADDASSIGN "+="
30 ALIGNAS "_Alignas"
31 ALIGNOF "_Alignof"
32 ANDAND "&&"
33 ANDASSIGN "&="
34 ARROW "->"
35 ASM "__asm__"
36 ATOMIC "_Atomic"
37 ATTRIBUTE "__attribute__"
38 AUTO "auto"
39 BOOL "_Bool"
40 BREAK "break"
41 BUILTINCHOOSEXPR "__builtin_choose_expr"
42 BUILTINTYPESCOMPATIBLE "__builtin_types_compatible_p"
43 CASE "case"
44 CHAR "char"
45 COMPLEX "_Complex"
46 CONST "const"
47 CONTINUE "continue"
48 DDD "..."
49 DEC "--"
50 DECIMAL128 "_Decimal128"
51 DECIMAL32 "_Decimal32"
52 DECIMAL64 "_Decimal64"
53 DEFAULT "default"
54 DIVASSIGN "/="
55 DO "do"
56 DOUBLE "double"
57 ELSE "else"
58 ENUM "enum"
59 EQ "=="
60 EXTERN "extern"
61 FLOAT "float"
62 FLOAT128 "_Float128"
63 FLOAT16 "__fp16"
64 FLOAT32 "_Float32"
65 FLOAT32X "_Float32x"
66 FLOAT64 "_Float64"
67 FLOAT64x "_Float64x"
68 FLOAT80 "__float80"
69 FOR "for"
70 FRACT "_Fract"
71 GEQ ">="
72 GOTO "goto"
73 IF "if"
74 IMAG "__imag__"
75 INC "++"
76 INLINE "inline"
77 INT "int"
78 INT8 "__int8"
79 INT16 "__int16"
80 INT32 "__int32"
81 INT64 "__int64"
82 INT128 "__int128"
83 LABEL "__label__"
84 LEQ "<="
85 LONG "long"
86 LSH "<<"
87 LSHASSIGN "<<="
88 MODASSIGN "%="
89 MULASSIGN "*="
90 NEQ "!="
91 NORETURN "_Noreturn"
92 ORASSIGN "|="
93 OROR "||"
94 PPNUMBER "preprocessing number"
95 PPPASTE "##"
96 PRAGMASTDC "__pragma_stdc"
97 REAL "__real__"
98 REGISTER "register"
99 RESTRICT "restrict"
100 RETURN "return"
101 RSH ">>"
102 RSHASSIGN ">>="
103 SAT "_Sat"
104 SHORT "short"
105 SIGNED "signed"
106 SIZEOF "sizeof"
107 STATIC "static"
108 STRUCT "struct"
109 SUBASSIGN "-="
110 SWITCH "switch"
111 THREADLOCAL "_Thread_local"
112 TYPEDEF "typedef"
113 TYPEOF "typeof"
114 UNION "union"
115 UNSIGNED "unsigned"
116 VOID "void"
117 VOLATILE "volatile"
118 WHILE "while"
119 XORASSIGN "^="
120
121%precedence BELOW_ELSE
122%precedence ELSE
123
124%precedence BELOW_ATTRIBUTE
125%precedence ATTRIBUTE
126
127%start TranslationUnit
128
129%%
130
131 /* [0], 6.5.1 Primary expressions */
132 /*yy:field Operand Operand */
133 /*yy:field lexicalScope Scope */
134 /*yy:field resolvedIn Scope */
135 /*yy:field resolvedTo Node */
136 /*yy:field IsSideEffectsFree bool */
137 /*yy:example int i = x; */
138/*yy:case Ident */
139 PrimaryExpression:
140 IDENTIFIER
141 /*yy:example int i = 42; */
142/*yy:case Int */ | INTCONST
143 /*yy:example int i = 3.14; */
144/*yy:case Float */ | FLOATCONST
145 /*yy:example enum e {a}; int i = a; */
146/*yy:case Enum */ | ENUMCONST
147 /*yy:example int i = 'x'; */
148/*yy:case Char */ | CHARCONST
149 /*yy:example int i = L'x'; */
150/*yy:case LChar */ | LONGCHARCONST
151 /*yy:example char *c = "x"; */
152/*yy:case String */ | STRINGLITERAL
153 /*yy:example char *c = L"x"; */
154/*yy:case LString */ | LONGSTRINGLITERAL
155 /*yy:example int i = (x+y); */
156/*yy:case Expr */ | '(' Expression ')'
157 /*yy:example int i = ({x();}); */
158/*yy:case Stmt */ | '(' CompoundStatement ')'
159
160 /* [0], 6.5.2 Postfix operators */
161 /*yy:field Operand Operand */
162 /*yy:field Field Field // Case Select, PSelect */
163 /*yy:field IsSideEffectsFree bool */
164 /*yy:example int i = x; */
165/*yy:case Primary */ PostfixExpression:
166 PrimaryExpression
167 /*yy:example int i = x[y]; */
168/*yy:case Index */ | PostfixExpression '[' Expression ']'
169 /*yy:example int i = x(y); */
170/*yy:case Call */ | PostfixExpression '(' ArgumentExpressionList ')'
171 /*yy:example int i = x.y; */
172/*yy:case Select */ | PostfixExpression '.' IDENTIFIER
173 /*yy:example int i = x->y; */
174/*yy:case PSelect */ | PostfixExpression "->" IDENTIFIER
175 /*yy:example int i = x++; */
176/*yy:case Inc */ | PostfixExpression "++"
177 /*yy:example int i = x--; */
178/*yy:case Dec */ | PostfixExpression "--"
179 /*yy:example int i = (int[]){y}; */
180/*yy:case Complit */ | '(' TypeName ')' '{' InitializerList ',' '}'
181 /*yy:example int i = __builtin_types_compatible_p(int, double); */
182/*yy:case TypeCmp */ | "__builtin_types_compatible_p" '(' TypeName ',' TypeName ')'
183 /*yy:example int i = __builtin_choose_expr(1, 2, "foo"); */
184/*yy:case ChooseExpr*/ | "__builtin_choose_expr" '(' AssignmentExpression ',' AssignmentExpression ',' AssignmentExpression ')'
185
186 /*yy:example int i = f(x); */
187 ArgumentExpressionList:
188 AssignmentExpression
189 /*yy:example int i = f(x, y); */
190 | ArgumentExpressionList ',' AssignmentExpression
191
192 /* [0], 6.5.3 Unary operators */
193 /*yy:field Operand Operand */
194 /*yy:field lexicalScope Scope */
195 /*yy:field IsSideEffectsFree bool */
196 /*yy:example int i = x; */
197/*yy:case Postfix */ UnaryExpression:
198 PostfixExpression
199 /*yy:example int i = ++x; */
200/*yy:case Inc */ | "++" UnaryExpression
201 /*yy:example int i = --x; */
202/*yy:case Dec */ | "--" UnaryExpression
203 /*yy:example int *i = &x; */
204/*yy:case Addrof */ | '&' CastExpression
205 /*yy:example int i = *x; */
206/*yy:case Deref */ | '*' CastExpression
207 /*yy:example int i = +x; */
208/*yy:case Plus */ | '+' CastExpression
209 /*yy:example int i = -x; */
210/*yy:case Minus */ | '-' CastExpression
211 /*yy:example int i = ~x; */
212/*yy:case Cpl */ | '~' CastExpression
213 /*yy:example int i = !x; */
214/*yy:case Not */ | '!' CastExpression
215 /*yy:example int i = sizeof x; */
216/*yy:case SizeofExpr */ | "sizeof" UnaryExpression
217 /*yy:example int i = sizeof(int); */
218/*yy:case SizeofType */ | "sizeof" '(' TypeName ')'
219 /*yy:example int f() { L: &&L; }*/
220/*yy:case LabelAddr */ | "&&" IDENTIFIER
221 /*yy:example int i = _Alignof(x); */
222/*yy:case AlignofExpr*/ | "_Alignof" UnaryExpression
223 /*yy:example int i = _Alignof(int); */
224/*yy:case AlignofType*/ | "_Alignof" '(' TypeName ')'
225 /*yy:example double i = __imag__ x; */
226/*yy:case Imag */ | "__imag__" UnaryExpression
227 /*yy:example double i = __real__ x; */
228/*yy:case Real */ | "__real__" UnaryExpression
229
230 /* [0], 6.5.4 Cast operators */
231 /*yy:field Operand Operand */
232 /*yy:field IsSideEffectsFree bool */
233 /*yy:example int i = 42; */
234/*yy:case Unary */ CastExpression:
235 UnaryExpression
236 /*yy:example int i = (int)3.14; */
237/*yy:case Cast */ | '(' TypeName ')' CastExpression
238
239 /* [0], 6.5.5 Multiplicative operators */
240 /*yy:field Operand Operand */
241 /*yy:field promote Type */
242 /*yy:field IsSideEffectsFree bool */
243 /*yy:example int i = x;*/
244/*yy:case Cast */ MultiplicativeExpression:
245 CastExpression
246 /*yy:example int i = x * y;*/
247/*yy:case Mul */ | MultiplicativeExpression '*' CastExpression
248 /*yy:example int i = x / y;*/
249/*yy:case Div */ | MultiplicativeExpression '/' CastExpression
250 /*yy:example int i = x % y;*/
251/*yy:case Mod */ | MultiplicativeExpression '%' CastExpression
252
253 /* [0], 6.5.6 Additive operators */
254 /*yy:field lexicalScope Scope */
255 /*yy:field Operand Operand */
256 /*yy:field promote Type */
257 /*yy:field IsSideEffectsFree bool */
258 /*yy:example int i = x; */
259/*yy:case Mul */ AdditiveExpression:
260 MultiplicativeExpression
261 /*yy:example int i = x+y; */
262/*yy:case Add */ | AdditiveExpression '+' MultiplicativeExpression
263 /*yy:example int i = x-y; */
264/*yy:case Sub */ | AdditiveExpression '-' MultiplicativeExpression
265
266 /* [0], 6.5.7 Bitwise shift operators */
267 /*yy:field Operand Operand */
268 /*yy:field promote Type // shift count promoted type */
269 /*yy:field IsSideEffectsFree bool */
270 /*yy:example int i = x; */
271/*yy:case Add */ ShiftExpression:
272 AdditiveExpression
273 /*yy:example int i = x << y; */
274/*yy:case Lsh */ | ShiftExpression "<<" AdditiveExpression
275 /*yy:example int i = x >> y; */
276/*yy:case Rsh */ | ShiftExpression ">>" AdditiveExpression
277
278 /* [0], 6.5.8 Relational operators */
279 /*yy:field Operand Operand */
280 /*yy:field promote Type */
281 /*yy:field IsSideEffectsFree bool */
282 /*yy:example int i = x; */
283/*yy:case Shift */ RelationalExpression:
284 ShiftExpression
285 /*yy:example int i = x < y; */
286/*yy:case Lt */ | RelationalExpression '<' ShiftExpression
287 /*yy:example int i = x > y; */
288/*yy:case Gt */ | RelationalExpression '>' ShiftExpression
289 /*yy:example int i = x <= y; */
290/*yy:case Leq */ | RelationalExpression "<=" ShiftExpression
291 /*yy:example int i = x >= y; */
292/*yy:case Geq */ | RelationalExpression ">=" ShiftExpression
293
294 /* [0], 6.5.9 Equality operators */
295 /*yy:field Operand Operand */
296 /*yy:field promote Type */
297 /*yy:field IsSideEffectsFree bool */
298 /*yy:example int i = x; */
299/*yy:case Rel */ EqualityExpression:
300 RelationalExpression
301 /*yy:example int i = x == y; */
302/*yy:case Eq */ | EqualityExpression "==" RelationalExpression
303 /*yy:example int i = x != y; */
304/*yy:case Neq */ | EqualityExpression "!=" RelationalExpression
305
306 /* [0], 6.5.10 Bitwise AND operator */
307 /*yy:field Operand Operand */
308 /*yy:field promote Type */
309 /*yy:field IsSideEffectsFree bool */
310 /*yy:example int i = x; */
311/*yy:case Eq */ AndExpression:
312 EqualityExpression
313 /*yy:example int i = x & y; */
314/*yy:case And */ | AndExpression '&' EqualityExpression
315
316 /* [0], 6.5.11 Bitwise exclusive OR operator */
317 /*yy:field Operand Operand */
318 /*yy:field promote Type */
319 /*yy:field IsSideEffectsFree bool */
320 /*yy:example int i = x; */
321/*yy:case And */ ExclusiveOrExpression:
322 AndExpression
323 /*yy:example int i = x^y; */
324/*yy:case Xor */ | ExclusiveOrExpression '^' AndExpression
325
326 /* [0], 6.5.12 Bitwise inclusive OR operator */
327 /*yy:field Operand Operand */
328 /*yy:field promote Type */
329 /*yy:field IsSideEffectsFree bool */
330 /*yy:example int i = x; */
331/*yy:case Xor */ InclusiveOrExpression:
332 ExclusiveOrExpression
333 /*yy:example int i = x|y; */
334/*yy:case Or */ | InclusiveOrExpression '|' ExclusiveOrExpression
335
336 /* [0], 6.5.13 Logical AND operator */
337 /*yy:field Operand Operand */
338 /*yy:field IsSideEffectsFree bool */
339 /*yy:example int i = x;*/
340/*yy:case Or */ LogicalAndExpression:
341 InclusiveOrExpression
342 /*yy:example int i = x && y;*/
343/*yy:case LAnd */ | LogicalAndExpression "&&" InclusiveOrExpression
344
345 /* [0], 6.5.14 Logical OR operator */
346 /*yy:field Operand Operand */
347 /*yy:field IsSideEffectsFree bool */
348 /*yy:example int i = x;*/
349/*yy:case LAnd */ LogicalOrExpression:
350 LogicalAndExpression
351 /*yy:example int i = x || y;*/
352/*yy:case LOr */ | LogicalOrExpression "||" LogicalAndExpression
353
354 /* [0], 6.5.15 Conditional operator */
355 /*yy:field Operand Operand */
356 /*yy:field IsSideEffectsFree bool */
357 /*yy:example int i = x; */
358/*yy:case LOr */ ConditionalExpression:
359 LogicalOrExpression
360 /*yy:example int i = x ? y : z; */
361/*yy:case Cond */ | LogicalOrExpression '?' Expression ':' ConditionalExpression
362
363 /* [0], 6.5.16 Assignment operators */
364 /*yy:field Operand Operand */
365 /*yy:field InitializerOperand Operand // When the expression is used in an initializer */
366 /*yy:field lexicalScope Scope */
367 /*yy:field promote Type */
368 /*yy:field IsSideEffectsFree bool */
369 /*yy:example int i = x; } */
370/*yy:case Cond */ AssignmentExpression:
371 ConditionalExpression
372 /*yy:example int f() { x = y; } */
373/*yy:case Assign */ | UnaryExpression '=' AssignmentExpression
374 /*yy:example int f() { x *= y; } */
375/*yy:case Mul */ | UnaryExpression "*=" AssignmentExpression
376 /*yy:example int f() { x /= y; } */
377/*yy:case Div */ | UnaryExpression "/=" AssignmentExpression
378 /*yy:example int f() { x %= y; } */
379/*yy:case Mod */ | UnaryExpression "%=" AssignmentExpression
380 /*yy:example int f() { x += y; } */
381/*yy:case Add */ | UnaryExpression "+=" AssignmentExpression
382 /*yy:example int f() { x -= y; } */
383/*yy:case Sub */ | UnaryExpression "-=" AssignmentExpression
384 /*yy:example int f() { x <<= y; } */
385/*yy:case Lsh */ | UnaryExpression "<<=" AssignmentExpression
386 /*yy:example int f() { x >>= y; } */
387/*yy:case Rsh */ | UnaryExpression ">>=" AssignmentExpression
388 /*yy:example int f() { x &= y; } */
389/*yy:case And */ | UnaryExpression "&=" AssignmentExpression
390 /*yy:example int f() { x ^= y; } */
391/*yy:case Xor */ | UnaryExpression "^=" AssignmentExpression
392 /*yy:example int f() { x |= y; } */
393/*yy:case Or */ | UnaryExpression "|=" AssignmentExpression
394
395 /* [0], 6.5.17 Comma operator */
396 /*yy:field Operand Operand */
397 /*yy:field IsSideEffectsFree bool */
398 /*yy:example int f() { i = x; }; */
399/*yy:case Assign */ Expression:
400 AssignmentExpression
401 /*yy:example int f() { x, y; }; */
402/*yy:case Comma */ | Expression ',' AssignmentExpression
403
404 /* [0], 6.6 Constant expressions */
405 /*yy:field Operand Operand */
406 /*yy:example struct { int i:3; }; */
407 ConstantExpression:
408 ConditionalExpression
409
410 /* [0], 6.7 Declarations */
411 /*yy:example int i, j; */
412 Declaration:
413 DeclarationSpecifiers InitDeclaratorList ';'
414
415 /*yy:field class storageClass */
416 /*yy:example static int i; */
417/*yy:case Storage */ DeclarationSpecifiers:
418 StorageClassSpecifier DeclarationSpecifiers
419 /*yy:example int i; */
420/*yy:case TypeSpec */ | TypeSpecifier DeclarationSpecifiers
421 /*yy:example volatile int i; */
422/*yy:case TypeQual */ | TypeQualifier DeclarationSpecifiers
423 /*yy:example inline int f() {} */
424/*yy:case Func */ | FunctionSpecifier DeclarationSpecifiers
425 /*yy:example _Alignas(double) int i; */
426/*yy:case AlignSpec */ | AlignmentSpecifier DeclarationSpecifiers
427 /*yy:example int __attribute__((a)) i; */
428/*yy:case Attribute */ | AttributeSpecifier DeclarationSpecifiers
429
430 /*yy:example int i; */
431 InitDeclaratorList:
432 InitDeclarator
433 /*yy:example int i, j; */
434 | InitDeclaratorList ',' AttributeSpecifierList InitDeclarator
435
436 /*yy:field initializer *InitializerValue */
437 /*yy:example int i; */
438/*yy:case Decl */ InitDeclarator:
439 Declarator AttributeSpecifierList
440 /*yy:example int i = x; */
441/*yy:case Init */ | Declarator AttributeSpecifierList '=' Initializer
442
443 /* [0], 6.7.1 Storage-class specifiers */
444 /*yy:example typedef int int_t;*/
445/*yy:case Typedef */ StorageClassSpecifier:
446 "typedef"
447 /*yy:example extern int i;*/
448/*yy:case Extern */ | "extern"
449 /*yy:example static int i;*/
450/*yy:case Static */ | "static"
451 /*yy:example auto int i;*/
452/*yy:case Auto */ | "auto"
453 /*yy:example register int i;*/
454/*yy:case Register */ | "register"
455 /*yy:example _Thread_local int i;*/
456/*yy:case ThreadLocal*/ | "_Thread_local"
457
458 /* [0], 6.7.2 Type specifiers */
459 /*yy:field resolvedIn Scope // Case TypedefName */
460 /*yy:field typ Type */
461 /*yy:example void i(); */
462/*yy:case Void */ TypeSpecifier:
463 "void"
464 /*yy:example char i; */
465/*yy:case Char */ | "char"
466 /*yy:example short i; */
467/*yy:case Short */ | "short"
468 /*yy:example int i; */
469/*yy:case Int */ | "int"
470 /*yy:example __int8 i; */
471/*yy:case Int8 */ | "__int8"
472 /*yy:example __int16 i; */
473/*yy:case Int16 */ | "__int16"
474 /*yy:example __int32 i; */
475/*yy:case Int32 */ | "__int32"
476 /*yy:example __int64 i; */
477/*yy:case Int64 */ | "__int64"
478 /*yy:example __int128 i; */
479/*yy:case Int128 */ | "__int128"
480 /*yy:example long i; */
481/*yy:case Long */ | "long"
482 /*yy:example float i; */
483/*yy:case Float */ | "float"
484 /*yy:example __fp16 i; */
485/*yy:case Float16 */ | "__fp16"
486 /*yy:example _Decimal32 i; */
487/*yy:case Decimal32 */ | "_Decimal32"
488 /*yy:example _Decimal64 i; */
489/*yy:case Decimal64 */ | "_Decimal64"
490 /*yy:example _Decimal128 i; */
491/*yy:case Decimal128 */ | "_Decimal128"
492 /*yy:example _Float128 i; */
493/*yy:case Float128 */ | "_Float128"
494 /*yy:example __float80 i; */
495/*yy:case Float80 */ | "__float80"
496 /*yy:example double i; */
497/*yy:case Double */ | "double"
498 /*yy:example signed i; */
499/*yy:case Signed */ | "signed"
500 /*yy:example unsigned i; */
501/*yy:case Unsigned */ | "unsigned"
502 /*yy:example _Bool i; */
503/*yy:case Bool */ | "_Bool"
504 /*yy:example _Complex i; */
505/*yy:case Complex */ | "_Complex"
506 /*yy:example struct s i; */
507/*yy:case StructOrUnion */
508 | StructOrUnionSpecifier
509 /*yy:example enum e i; */
510/*yy:case Enum */ | EnumSpecifier
511 /*yy:example typedef const T; T i; */
512/*yy:case TypedefName*/ | TYPEDEFNAME
513 /*yy:example typeof(42) i; */
514/*yy:case TypeofExpr */ | "typeof" '(' Expression ')'
515 /*yy:example typedef const T; typeof(T) i; */
516/*yy:case TypeofType */ | "typeof" '(' TypeName ')'
517 /*yy:example _Atomic(int) i; */
518/*yy:case Atomic */ | AtomicTypeSpecifier
519 /*yy:example _Fract i; */
520/*yy:case Fract */ | "_Fract"
521 /*yy:example _Sat i; */
522/*yy:case Sat */ | "_Sat"
523 /*yy:example _Accum i; */
524/*yy:case Accum */ | "_Accum"
525 /*yy:example _Float32 i; */
526/*yy:case Float32 */ | "_Float32"
527 /*yy:example _Float64 i; */
528/*yy:case Float64 */ | "_Float64"
529 /*yy:example _Float32x i; */
530/*yy:case Float32x */ | "_Float32x"
531 /*yy:example _Float64x i; */
532/*yy:case Float64x */ | "_Float64x"
533
534 /* [0], 6.7.2.1 Structure and union specifiers */
535 /*yy:field lexicalScope Scope */
536 /*yy:field maxAlign int */
537 /*yy:field typ Type */
538 /*yy:example struct s { int i; }; */
539/*yy:case Def */ StructOrUnionSpecifier:
540 StructOrUnion AttributeSpecifierList IDENTIFIER '{' StructDeclarationList '}'
541 /*yy:example struct s v; */
542/*yy:case Tag */ | StructOrUnion AttributeSpecifierList IDENTIFIER
543
544 /*yy:example struct { int i; } s; */
545/*yy:case Struct */ StructOrUnion:
546 "struct"
547 /*yy:example union { int i; double d; } u; */
548/*yy:case Union */ | "union"
549
550 /*yy:example struct{ int i; } */
551 StructDeclarationList:
552 StructDeclaration
553 /*yy:example struct{ int i; double d; } */
554 | StructDeclarationList StructDeclaration
555
556 /*yy:example struct{ int i; } */
557 /*yy:field Empty bool // TCC extension */
558 StructDeclaration:
559 SpecifierQualifierList StructDeclaratorList ';'
560
561 /*yy:field noStorageClass */
562 /*yy:example struct {int i;};*/
563/*yy:case TypeSpec */ SpecifierQualifierList:
564 TypeSpecifier SpecifierQualifierList
565 /*yy:example struct {const int i;};*/
566/*yy:case TypeQual */ | TypeQualifier SpecifierQualifierList
567 /*yy:example struct {_Alignas(double) int i;};*/
568/*yy:case AlignSpec */ | AlignmentSpecifier SpecifierQualifierList
569 /*yy:example struct {__attribute__((a)) int i;};*/
570/*yy:case Attribute */ | AttributeSpecifier SpecifierQualifierList
571
572 /*yy:example struct{ int i; } */
573 StructDeclaratorList:
574 StructDeclarator
575 /*yy:example struct{ int i, j; } */
576 | StructDeclaratorList ',' StructDeclarator
577
578 /*yy:field decl *StructDeclaration */
579 /*yy:example struct{ int i; } */
580/*yy:case Decl */ StructDeclarator:
581 Declarator
582 /*yy:example struct{ int i:3; } */
583/*yy:case BitField */ | Declarator ':' ConstantExpression AttributeSpecifierList
584
585 /* [0], 6.7.2.2 Enumeration specifiers */
586 /*yy:field lexicalScope Scope */
587 /*yy:field typ Type */
588 /*yy:field min Value */
589 /*yy:field max Value */
590 /*yy:example enum e {a}; */
591/*yy:case Def */ EnumSpecifier:
592 "enum" AttributeSpecifierList IDENTIFIER '{' EnumeratorList ',' '}'
593 /*yy:example enum e i; */
594/*yy:case Tag */ | "enum" AttributeSpecifierList IDENTIFIER
595
596 /*yy:example enum e {a}; */
597 EnumeratorList:
598 Enumerator
599 /*yy:example enum e {a, b}; */
600 | EnumeratorList ',' Enumerator
601
602 /*yy:field lexicalScope Scope */
603 /*yy:field Operand Operand */
604 /*yy:example enum e {a}; */
605/*yy:case Ident */ Enumerator:
606 IDENTIFIER AttributeSpecifierList
607 /*yy:example enum e {a = 42}; */
608/*yy:case Expr */ | IDENTIFIER AttributeSpecifierList '=' ConstantExpression
609
610 /* [2], 6.7.2.4 Atomic type specifiers */
611 /*yy:field list []*TypeSpecifier */
612 /*yy:example _Atomic(int) i; */
613 AtomicTypeSpecifier:
614 "_Atomic" '(' TypeName ')'
615
616 /* [0], 6.7.3 Type qualifiers */
617 /*yy:example const int i; */
618/*yy:case Const */ TypeQualifier:
619 "const"
620 /*yy:example restrict int i; */
621/*yy:case Restrict */ | "restrict"
622 /*yy:example volatile int i; */
623/*yy:case Volatile */ | "volatile"
624 /*yy:example _Atomic int i; */
625/*yy:case Atomic */ | "_Atomic"
626
627 /* [0], 6.7.4 Function specifiers */
628 /*yy:example inline int f() {}*/
629/*yy:case Inline */ FunctionSpecifier:
630 "inline"
631 /*yy:example _Noreturn int f() {}*/
632/*yy:case Noreturn */ | "_Noreturn"
633
634 /* [0], 6.7.5 Declarators */
635 /*yy:field Linkage Linkage */
636 /*yy:field Read int */
637 /*yy:field StorageClass StorageClass */
638 /*yy:field Write int */
639 /*yy:field funcDefinition *FunctionDefinition */
640 /*yy:field lhs map[*Declarator]struct{} */
641 /*yy:field td typeDescriptor */
642 /*yy:field typ Type */
643 /*yy:field AddressTaken bool */
644 /*yy:field IsParameter bool */
645 /*yy:field IsTypedefName bool */
646 /*yy:field SubjectOfAsgnOp bool */
647 /*yy:field SubjectOfIncDec bool */
648 /*yy:field called bool */
649 /*yy:field fnDef bool */
650 /*yy:field hasInitializer bool */
651 /*yy:field implicit bool */
652 /*yy:example int *p __attribute__ ((foo)); */
653 Declarator:
654 Pointer DirectDeclarator AttributeSpecifierList %prec BELOW_ATTRIBUTE
655
656 /* [2], 6.7.5 Alignment specifier */
657 /*yy:example _Alignas(double) char c; */
658/*yy:case AlignasType*/ AlignmentSpecifier:
659 "_Alignas" '(' TypeName ')'
660 /*yy:example _Alignas(0ll) char c; */
661/*yy:case AlignasExpr*/ | "_Alignas" '(' ConstantExpression ')'
662
663 /*yy:field lexicalScope Scope */
664 /*yy:field paramScope Scope */
665 /*yy:field typeQualifiers *typeBase */
666 /*yy:field idListNoDeclList bool */
667 /*yy:example int i; */
668/*yy:case Ident */ DirectDeclarator:
669 IDENTIFIER Asm
670 /*yy:example int (f); */
671/*yy:case Decl */ | '(' AttributeSpecifierList Declarator ')'
672 /*yy:example int i[const 42]; */
673/*yy:case Arr */ | DirectDeclarator '[' TypeQualifiers AssignmentExpression ']'
674 /*yy:example int i[static const 42]; */
675/*yy:case StaticArr */ | DirectDeclarator '[' "static" TypeQualifiers AssignmentExpression ']'
676 /*yy:example int i[const static 42]; */
677/*yy:case ArrStatic */ | DirectDeclarator '[' TypeQualifiers "static" AssignmentExpression ']'
678 /*yy:example int i[const *]; */
679/*yy:case Star */ | DirectDeclarator '[' TypeQualifiers '*' ']'
680 /*yy:example int f(int i); */
681/*yy:case FuncParam */ | DirectDeclarator '(' ParameterTypeList ')'
682 /*yy:example int f(a); */
683/*yy:case FuncIdent */ | DirectDeclarator '(' IdentifierList ')'
684
685 /*yy:field typeQualifiers *typeBase*/
686 /*yy:example int *p; */
687/*yy:case TypeQual */ Pointer:
688 '*' TypeQualifiers
689 /*yy:example int **p; */
690/*yy:case Ptr */ | '*' TypeQualifiers Pointer
691 /*yy:example int atexit_b(void (^ _Nonnull)(void)); */
692/*yy:case Block */ | '^' TypeQualifiers
693
694 /*yy:field noStorageClass */
695 /*yy:example int * const i; */
696/*yy:case TypeQual */ TypeQualifiers:
697 TypeQualifier
698 /*yy:example int * __attribute__((a)) i; */
699/*yy:case Attribute */ | AttributeSpecifier
700 /*yy:example int * const volatile i; */
701 | TypeQualifiers TypeQualifier
702 /*yy:example int * __attribute__((a)) __attribute__((b)) i; */
703 | TypeQualifiers AttributeSpecifier
704
705 /*yy:example int f(int i) {} */
706/*yy:case List */ ParameterTypeList:
707 ParameterList
708 /*yy:example int f(int i, ...) {} */
709/*yy:case Var */ | ParameterList ',' "..."
710
711 /*yy:example int f(int i) {} */
712 ParameterList:
713 ParameterDeclaration
714 /*yy:example int f(int i, int j) {} */
715 | ParameterList ',' ParameterDeclaration
716
717 /*yy:field typ Type */
718 /*yy:example int f(int i) {} */
719/*yy:case Decl */ ParameterDeclaration:
720 DeclarationSpecifiers Declarator AttributeSpecifierList
721 /*yy:example int f(int*) {} */
722/*yy:case Abstract */ | DeclarationSpecifiers AbstractDeclarator
723
724 /*yy:field lexicalScope Scope */
725 /*yy:example int f(i) int i; {}*/
726 IdentifierList:
727 IDENTIFIER
728 /*yy:example int f(i, j) int i, j; {}*/
729 | IdentifierList ',' IDENTIFIER
730
731 /* [0], 6.7.6 Type names */
732 /*yy:field typ Type */
733 /*yy:example int i = (int)x; */
734 TypeName:
735 SpecifierQualifierList AbstractDeclarator
736
737 /*yy:field typ Type */
738 /*yy:example void f(int*); */
739/*yy:case Ptr */ AbstractDeclarator:
740 Pointer
741 /*yy:example void f(int()); */
742/*yy:case Decl */ | Pointer DirectAbstractDeclarator
743
744 /*yy:field paramScope Scope */
745 /*yy:field typeQualifiers *typeBase */
746 /*yy:example void f(int()); */
747/*yy:case Decl */ DirectAbstractDeclarator:
748 '(' AbstractDeclarator ')'
749 /*yy:example void f(int[const 42]); */
750/*yy:case Arr */ | DirectAbstractDeclarator '[' TypeQualifiers AssignmentExpression ']'
751 /*yy:example void f(int[static const 42]); */
752/*yy:case StaticArr */ | DirectAbstractDeclarator '[' "static" TypeQualifiers AssignmentExpression ']'
753 /*yy:example void f(int[const static 42]); */
754/*yy:case ArrStatic */ | DirectAbstractDeclarator '[' TypeQualifiers "static" AssignmentExpression ']'
755 /*yy:example void f(int[*]); */
756/*yy:case ArrStar */ | DirectAbstractDeclarator '[' '*' ']'
757 /*yy:example void f(int(char)); */
758/*yy:case Func */ | DirectAbstractDeclarator '(' ParameterTypeList ')'
759
760 /* [0], 6.7.8 Initialization */
761 /*yy:field Field Field // Where aplicable */
762 /*yy:field Offset uintptr // Case Expr */
763 /*yy:field field0 Field */
764 /*yy:field list []*Initializer */
765 /*yy:field parent *Initializer */
766 /*yy:field trailingComma *Token */
767 /*yy:field typ Type */
768 /*yy:field isConst bool */
769 /*yy:field isZero bool */
770 /*yy:example int i = x; */
771/*yy:case Expr */ Initializer:
772 AssignmentExpression
773 /*yy:example int i[] = { x }; */
774/*yy:case InitList */ | '{' InitializerList ',' '}'
775
776 /*yy:field list []*Initializer */
777 /*yy:field isConst bool */
778 /*yy:field isZero bool */
779 /*yy:example int i[] = { [10] = x }; */
780 InitializerList:
781 Designation Initializer
782 /*yy:example int i[] = { [10] = x, [20] = y }; */
783 | InitializerList ',' Designation Initializer
784
785 /*yy:example int a[] = { [42] = 314 }; */
786 Designation:
787 DesignatorList '='
788
789 /*yy:example int a[] = { [42] = 314 }; */
790 DesignatorList:
791 Designator
792 /*yy:example int a[100][] = { [42][12] = 314 }; */
793 | DesignatorList Designator
794
795 /*yy:field lexicalScope Scope */
796 /*yy:example int a[] = { [42] = 314 }; */
797/*yy:case Index */ Designator:
798 '[' ConstantExpression ']'
799 /*yy:example struct t s = { .fld = 314 }; */
800/*yy:case Field */ | '.' IDENTIFIER
801 /*yy:example struct t s = { fld: 314 }; */
802/*yy:case Field2 */ | IDENTIFIER ':'
803
804 /* [0], 6.8 Statements and blocks */
805 /*yy:field Operand Operand // Case CompoundStatement, ExpressionStatement*/
806 /*yy:example int f() { L: x(); }*/
807/*yy:case Labeled */ Statement:
808 LabeledStatement
809 /*yy:example int f() { { y(); } }*/
810/*yy:case Compound */ | CompoundStatement
811 /*yy:example int f() { x(); }*/
812/*yy:case Expr */ | ExpressionStatement
813 /*yy:example int f() { if(x) y(); }*/
814/*yy:case Selection */ | SelectionStatement
815 /*yy:example int f() { for(;;) x(); }*/
816/*yy:case Iteration */ | IterationStatement
817 /*yy:example int f() { return x; }*/
818/*yy:case Jump */ | JumpStatement
819 /*yy:example int f() { __asm__("nop"); }*/
820/*yy:case Asm */ | AsmStatement
821
822 /* [0], 6.8.1 Labeled statements */
823 /*yy:field block *CompoundStatement */
824 /*yy:field lexicalScope Scope */
825 /*yy:example int f() { L: goto L; } */
826/*yy:case Label */ LabeledStatement:
827 IDENTIFIER ':' AttributeSpecifierList Statement
828 /*yy:example int f() { switch(i) case 42: x(); } */
829/*yy:case CaseLabel */ | "case" ConstantExpression ':' Statement
830 /*yy:example int f() { switch(i) case 42 ... 56: x(); } */
831/*yy:case Range */ | "case" ConstantExpression "..." ConstantExpression ':' Statement
832 /*yy:example int f() { switch(i) default: x(); } */
833/*yy:case Default */ | "default" ':' Statement
834
835 /* [0], 6.8.2 Compound statement */
836 /*yy:field Operand Operand */
837 /*yy:field children []*CompoundStatement */
838 /*yy:field declarations []*Declaration */
839 /*yy:field isJumpTarget bool */
840 /*yy:field labeledStmts []*LabeledStatement */
841 /*yy:field parent *CompoundStatement */
842 /*yy:field scope Scope */
843 /*yy:example int f() { int i; } */
844 CompoundStatement:
845 '{' BlockItemList '}'
846
847 /*yy:example int f() { int i; }*/
848 BlockItemList:
849 BlockItem
850 /*yy:example int f() { int i; double j; }*/
851 | BlockItemList BlockItem
852
853 /*yy:field fn *FunctionDefinition // Case FuncDef */
854 /*yy:field closure map[StringID]struct{} // Case FuncDef */
855 /*yy:field Last bool */
856 /*yy:example int f() { int i; }*/
857/*yy:case Decl */ BlockItem:
858 Declaration
859 /*yy:example int f() { g(); }*/
860/*yy:case Stmt */ | Statement
861 /*yy:example int f() { __label__ L; }*/
862/*yy:case Label */ | LabelDeclaration
863 /*yy:example int f() { int g() {} }*/
864/*yy:case FuncDef */ | DeclarationSpecifiers Declarator CompoundStatement
865 /*yy:example int f() {\n#pragma STDC FENV_ACCESS OFF\n}*/
866/*yy:case Pragma */ | PragmaSTDC
867
868 /* [0], 6.8.3 Expression and null statements */
869 /*yy:example int f() { g(); }*/
870 ExpressionStatement:
871 Expression AttributeSpecifierList ';'
872
873 /* [0], 6.8.4 Selection statements */
874 /*yy:field promote Type // switch expression promoted type */
875 /*yy:field cases []*LabeledStatement */
876 /*yy:example int f() { if(x) y(); } */
877/*yy:case If */ SelectionStatement:
878 "if" '(' Expression ')' Statement %prec BELOW_ELSE
879 /*yy:example int f() { if(x) y(); else z(); } */
880/*yy:case IfElse */ | "if" '(' Expression ')' Statement "else" Statement
881 /*yy:example int f() { switch(i) case 42: x(); } */
882/*yy:case Switch */ | "switch" '(' Expression ')' Statement
883
884 /* [0], 6.8.5 Iteration statements */
885 /*yy:example int f() { while(x) y(); } */
886/*yy:case While */ IterationStatement:
887 "while" '(' Expression ')' Statement
888 /*yy:example int f() { do x(); while(y); } */
889/*yy:case Do */ | "do" Statement "while" '(' Expression ')' ';'
890 /*yy:example int f() { for( i = 0; i < 10; i++) x(); } */
891/*yy:case For */ | "for" '(' Expression ';' Expression ';' Expression ')' Statement
892 /*yy:example int f() { for( int i = 0; i < 10; i++) x(); } */
893/*yy:case ForDecl */ | "for" '(' Declaration Expression ';' Expression ')' Statement
894
895 /* [0], 6.8.6 Jump statements */
896 /*yy:field context Node */
897 /*yy:field lexicalScope Scope */
898 /*yy:example int f() { L: goto L; } */
899/*yy:case Goto */ JumpStatement:
900 "goto" IDENTIFIER ';'
901 /*yy:example int f() { L: x(); void *p = &&L; goto *p; } */
902/*yy:case GotoExpr */ | "goto" '*' Expression ';'
903 /*yy:example int f() { for(;;) if (i) continue; } */
904/*yy:case Continue */ | "continue" ';'
905 /*yy:example int f() { for(;;) if (i) break; } */
906/*yy:case Break */ | "break" ';'
907 /*yy:example int f() { if (i) return x; } */
908/*yy:case Return */ | "return" Expression ';'
909
910 /* [0], 6.9 External definitions */
911 /*yy:list*/
912 /*yy:example int i; */
913 TranslationUnit:
914 ExternalDeclaration
915 /*yy:example int i; int j; */
916 | TranslationUnit ExternalDeclaration
917
918 /*yy:example int f() {} */
919/*yy:case FuncDef */ ExternalDeclaration:
920 FunctionDefinition
921 /*yy:example int i; */
922/*yy:case Decl */ | Declaration
923 /*yy:example int f() __asm__("nop"); */
924/*yy:case Asm */ | AsmFunctionDefinition
925 /*yy:example __asm__("nop"); */
926/*yy:case AsmStmt */ | AsmStatement
927 /*yy:example ; */
928/*yy:case Empty */ | ';'
929 /*yy:example #pragma STDC CX_LIMITED_RANGE DEFAULT */
930/*yy:case Pragma */ | PragmaSTDC
931
932 /* [0], 6.9.1 Function definitions */
933 /*yy:field CallSiteComplexExpr []*AssignmentExpression */
934 /*yy:field CompositeLiterals []*PostfixExpression */
935 /*yy:field ComputedGotos map[StringID]*UnaryExpression */
936 /*yy:field Gotos map[StringID]*JumpStatement */
937 /*yy:field InitDeclarators []*InitDeclarator */
938 /*yy:field Labels map[StringID]*LabeledStatement */
939 /*yy:field ReturnComplexExpr []*Expression */
940 /*yy:field VLAs []*Declarator */
941 /*yy:field compoundStatements []*CompoundStatement */
942 /*yy:field checked bool */
943 /*yy:example int f() {} */
944 FunctionDefinition:
945 DeclarationSpecifiers Declarator DeclarationList CompoundStatement
946
947 /*yy:example int f(i) int i; {} */
948 DeclarationList:
949 Declaration
950 /*yy:example int f(i, j) int i; int j; {} */
951 | DeclarationList Declaration
952
953 /* -------------------------------------- Extensions */
954
955 /*yy:example __asm__("nop": [a] b); */
956 AsmIndex:
957 '[' Expression ']'
958
959 /*yy:example __asm__("nop": a); */
960 AsmExpressionList:
961 AsmIndex AssignmentExpression
962 /*yy:example __asm__("nop": a, b); */
963 | AsmExpressionList ',' AsmIndex AssignmentExpression
964
965 /*yy:example __asm__("nop": a); */
966 AsmArgList:
967 ':' AsmExpressionList
968 /*yy:example __asm__("nop": a : b); */
969 | AsmArgList ':' AsmExpressionList
970
971 /*yy:example __asm__("nop"); */
972 Asm:
973 "__asm__" AsmQualifierList '(' STRINGLITERAL AsmArgList ')'
974
975 /*yy:example void f() { __asm__("nop"); } */
976 AsmStatement:
977 Asm AttributeSpecifierList ';'
978
979 /*yy:example int f() __asm__("nop"); */
980 AsmFunctionDefinition:
981 DeclarationSpecifiers Declarator AsmStatement
982
983 /*yy:example __asm__ volatile ("nop"); */
984/*yy:case Volatile */ AsmQualifier:
985 "volatile"
986 /*yy:example __asm__ inline ("nop"); */
987/*yy:case Inline */ | "inline"
988 /*yy:example __asm__ goto ("nop"); */
989/*yy:case Goto */ | "goto"
990
991 /*yy:example __asm__ inline ("nop"); */
992 AsmQualifierList:
993 AsmQualifier
994 /*yy:example __asm__ inline volatile ("nop"); */
995 | AsmQualifierList AsmQualifier
996
997 /*yy:example int f() { __label__ L; L: x(); } */
998 LabelDeclaration:
999 "__label__" IdentifierList ';'
1000
1001 /* [4], 6.37 Attribute Syntax */
1002 /*yy:example int i __attribute__((a(b))); */
1003 ExpressionList:
1004 AssignmentExpression
1005 /*yy:example int i __attribute__((a(b, c))); */
1006 | ExpressionList ',' AssignmentExpression
1007
1008 /*yy:field lexicalScope Scope */
1009 /*yy:example int i __attribute__((a)); */
1010/*yy:case Ident */ AttributeValue:
1011 IDENTIFIER
1012 /*yy:example int i __attribute__((a(b))); */
1013/*yy:case Expr */ | IDENTIFIER '(' ExpressionList ')'
1014
1015 /*yy:example int i __attribute__((a)); */
1016 AttributeValueList:
1017 AttributeValue
1018 /*yy:example int i __attribute__((a, b)); */
1019 | AttributeValueList ',' AttributeValue
1020
1021 /*yy:example int i __attribute__((a)); */
1022 AttributeSpecifier:
1023 "__attribute__" '(' '(' AttributeValueList ')' ')'
1024
1025 /*yy:example int i __attribute__((a)); */
1026 AttributeSpecifierList:
1027 AttributeSpecifier %prec BELOW_ATTRIBUTE
1028 /*yy:example int i __attribute__((a)) __attribute((b)); */
1029 | AttributeSpecifierList AttributeSpecifier
1030
1031 /*yy:example _Pragma("STDC FP_CONTRACT ON") */
1032 PragmaSTDC:
1033 "__pragma_stdc" IDENTIFIER IDENTIFIER IDENTIFIER
Note: See TracBrowser for help on using the repository browser.