compiler: Fixes to improve compatibility with MinGW/GCC 5 headers
[sdk] / compiler / libec / src / type.y
1 %{
2
3 import "ecdefs"
4
5 #define YYSIZE_T size_t
6 #define YYLTYPE Location
7 #include "grammar.h"
8
9 #ifndef YYLLOC_DEFAULT
10 # define YYLLOC_DEFAULT(Current, Rhs, N)         \
11   (Current).start = (Rhs)[1].start;      \
12   (Current).end = (Rhs)[N].end;
13 #endif
14
15 TypeName parsedType;
16
17 #define PRECOMPILER
18
19 #define yyparse type_yyparse
20 #define yylval  type_yylval
21 #define yychar  type_yychar
22 #define yydebug type_yydebug
23 #define yynerrs type_yynerrs
24 #define yylloc  type_yylloc
25
26 extern bool parseTypeError;
27
28 extern File fileInput;
29 extern char * yytext;
30 int yylex();
31 int yyerror();
32
33 #define uint _uint
34 default:
35
36 %}
37
38 %debug
39 %union
40 {
41    int i;
42    SpecifierType specifierType;
43    Identifier id;
44    Expression exp;
45    Specifier specifier;
46    OldList * list;
47    Enumerator enumerator;
48    Declarator declarator;
49    Pointer pointer;
50    Initializer initializer;
51    InitDeclarator initDeclarator;
52    TypeName typeName;
53    Declaration declaration;
54    Statement stmt;
55    FunctionDefinition function;
56    External external;
57    Context context;
58    Attrib attrib;
59    ExtDecl extDecl;
60    Attribute attribute;
61
62    Instantiation instance;
63    MembersInit membersInit;
64    MemberInit memberInit;
65    ClassFunction classFunction;
66    ClassDefinition _class;
67    ClassDef classDef;
68    PropertyDef prop;
69    char * string;
70    Symbol symbol;
71    TemplateParameter templateParameter;
72    TemplateArgument templateArgument;
73    TemplateDatatype templateDatatype;
74 }
75
76 // *** Types ***
77
78 %type <specifierType> struct_or_union
79 %type <i>   unary_operator assignment_operator
80 %type <id>  identifier
81 %type <exp> primary_expression postfix_expression unary_expression cast_expression
82             multiplicative_expression additive_expression shift_expression
83             relational_expression relational_expression_smaller_than equality_expression and_expression
84             exclusive_or_expression inclusive_or_expression logical_and_expression
85             logical_or_expression conditional_expression assignment_expression
86             constant_expression
87             common_unary_expression simple_primary_expression
88             anon_instantiation_expression
89
90 //simple_postfix_expression simple_unary_expression
91
92 %type <list> argument_expression_list expression enumerator_list
93              struct_declarator_list struct_declaration_list
94              declaration_specifiers identifier_list initializer_list init_declarator_list
95              parameter_list parameter_type_list declaration_list statement_list
96              members_initialization_list members_initialization_list_coloned data_member_initialization_list data_member_initialization_list_coloned
97              guess_declaration_specifiers real_guess_declaration_specifiers
98              specifier_qualifier_list guess_specifier_qualifier_list
99              type_qualifier_list property_specifiers
100              renew_specifiers
101              default_property_list
102              template_arguments_list attribs_list
103
104
105 %type <specifier> storage_class_specifier enum_specifier_compound enum_specifier_nocompound type_qualifier type_specifier strict_type_specifier
106                   struct_or_union_specifier_compound struct_or_union_specifier_nocompound guess_type type strict_type
107                   real_guess_type ext_storage base_strict_type
108 %type <enumerator> enumerator
109 %type <declarator> declarator direct_declarator direct_abstract_declarator abstract_declarator
110                    struct_declarator direct_declarator_function direct_declarator_function_start declarator_function direct_declarator_nofunction
111                    direct_abstract_declarator_noarray abstract_declarator_noarray declarator_nofunction
112
113 %type <pointer> pointer
114 %type <initializer> initializer initializer_condition
115 %type <initDeclarator> init_declarator
116 %type <typeName> type_name guess_type_name parameter_declaration
117 %type <stmt> statement labeled_statement compound_statement expression_statement
118              selection_statement iteration_statement jump_statement compound_inside
119
120 %type <declaration> declaration
121 %type <classDef> struct_declaration
122 %type <string> string_literal attribute_word
123 %type <extDecl> ext_decl
124 %type <attrib> attrib
125 %type <attribute> attribute
126
127 %type <instance> instantiation_named instantiation_unnamed guess_instantiation_named instantiation_anon
128 /* %type <membersInit>  members_initialization */
129 %type <memberInit> data_member_initialization default_property
130 %type <classFunction> class_function_definition class_function_definition_start
131                      virtual_class_function_definition_start
132                      constructor_function_definition_start destructor_function_definition_start
133 %type <classFunction> instance_class_function_definition instance_class_function_definition_start
134 %type <prop> property
135
136 %type <templateArgument> template_argument template_type_argument template_expression_argument
137 %type <templateDatatype> template_datatype
138
139 %type <context> compound_start
140
141 %token IDENTIFIER CONSTANT STRING_LITERAL SIZEOF
142 %token PTR_OP INC_OP DEC_OP LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP
143 %token AND_OP OR_OP MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN
144 %token SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN
145 %token XOR_ASSIGN OR_ASSIGN TYPE_NAME
146
147 %token TYPEDEF EXTERN STATIC AUTO REGISTER
148 %token CHAR SHORT INT UINT INT64 INT128 LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID VALIST
149 %token STRUCT UNION ENUM ELLIPSIS
150
151 %token CASE DEFAULT IF SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN
152
153 %nonassoc IFX
154 %nonassoc ELSE
155 %token CLASS THISCLASS CLASS_NAME
156 %token PROPERTY SETPROP GETPROP NEWOP RENEW DELETE EXT_DECL EXT_STORAGE IMPORT DEFINE VIRTUAL ATTRIB
157 %token PUBLIC PRIVATE
158 %token TYPED_OBJECT ANY_OBJECT _INCREF EXTENSION ASM TYPEOF
159 %token WATCH STOPWATCHING FIREWATCHERS WATCHABLE CLASS_DESIGNER CLASS_NO_EXPANSION CLASS_FIXED ISPROPSET
160 %token CLASS_DEFAULT_PROPERTY PROPERTY_CATEGORY CLASS_DATA CLASS_PROPERTY SUBCLASS NAMESPACE
161 %token NEW0OP RENEW0 VAARG
162 %token DBTABLE DBFIELD DBINDEX DATABASE_OPEN
163 %token ALIGNOF ATTRIB_DEP __ATTRIB
164 %token BOOL _BOOL _COMPLEX _IMAGINARY RESTRICT THREAD
165 %token WIDE_STRING_LITERAL
166 %token BUILTIN_OFFSETOF
167
168 %destructor { FreeIdentifier($$); } identifier
169 %destructor { FreePointer($$); } pointer
170 %destructor { FreeExpression($$); } primary_expression postfix_expression unary_expression cast_expression
171                                     multiplicative_expression additive_expression shift_expression
172                                     relational_expression equality_expression and_expression
173                                     exclusive_or_expression inclusive_or_expression logical_and_expression
174                                     logical_or_expression conditional_expression assignment_expression
175                                     constant_expression
176 %destructor { FreeSpecifier($$); }  storage_class_specifier enum_specifier_compound enum_specifier_nocompound type_qualifier type_specifier
177                                     struct_or_union_specifier_compound struct_or_union_specifier_nocompound ext_storage type strict_type guess_type strict_type_specifier
178                                     base_strict_type
179 %destructor { FreeEnumerator($$); } enumerator
180 %destructor { FreeDeclarator($$); } declarator direct_declarator direct_abstract_declarator abstract_declarator
181                                     direct_abstract_declarator_noarray abstract_declarator_noarray
182                                     struct_declarator direct_declarator_function direct_declarator_function_start declarator_function direct_declarator_nofunction
183                                     declarator_nofunction
184
185 %destructor { FreeInitializer($$); } initializer initializer_condition
186 %destructor { FreeInitDeclarator($$); } init_declarator
187 %destructor { FreeTypeName($$); } type_name guess_type_name parameter_declaration
188 %destructor { FreeStatement($$); }  statement labeled_statement compound_statement expression_statement
189                                     selection_statement iteration_statement jump_statement compound_inside
190
191 %destructor { FreeDeclaration($$); } declaration
192
193 %destructor { FreeInstance($$); } instantiation_named instantiation_unnamed
194
195 %destructor { FreeMemberInit($$); } data_member_initialization default_property
196
197 %destructor { FreeClassFunction($$); } class_function_definition class_function_definition_start
198                                        virtual_class_function_definition_start
199                                        constructor_function_definition_start destructor_function_definition_start
200                                        instance_class_function_definition instance_class_function_definition_start
201 %destructor { FreeClassDef($$); } struct_declaration
202 %destructor { delete $$; } string_literal attribute_word
203 %destructor { FreeProperty($$); } property
204
205 %destructor { FreeList($$, FreeExpression); }  argument_expression_list expression
206 %destructor { FreeList($$, FreeEnumerator); }  enumerator_list
207 %destructor { FreeList($$, FreeSpecifier); }   type_qualifier_list specifier_qualifier_list declaration_specifiers
208                                                guess_declaration_specifiers guess_specifier_qualifier_list
209 %destructor { FreeList($$, FreeDeclarator); }  struct_declarator_list
210 %destructor { FreeList($$, FreeDeclaration); } declaration_list
211 %destructor { FreeList($$, FreeInitializer); } initializer_list
212 %destructor { FreeList($$, FreeInitDeclarator); } init_declarator_list
213 %destructor { FreeList($$, FreeTypeName); } parameter_list parameter_type_list identifier_list
214 %destructor { FreeList($$, FreeStatement); } statement_list
215 %destructor { FreeList($$, FreeClassDef); } struct_declaration_list
216 %destructor { FreeList($$, FreeMemberInit); } default_property_list data_member_initialization_list data_member_initialization_list_coloned
217 %destructor { FreeList($$, FreeMembersInit); } members_initialization_list members_initialization_list_coloned
218 %destructor { PopContext($$); FreeContext($$); delete $$; } compound_start
219 %destructor { FreeTemplateArgument($$); } template_argument template_type_argument template_expression_argument
220 %destructor { FreeTemplateDataType($$); } template_datatype
221 %destructor { FreeAttrib($$); } attrib
222 %destructor { FreeExtDecl($$); } ext_decl
223 %destructor { FreeAttribute($$); } attribute
224 %destructor { FreeList($$, FreeAttribute); }  attribs_list
225
226 %start type_unit
227
228 %%
229
230 guess_type:
231    identifier '*'
232    {
233       $$ = null;
234       DeclClass($1._class, $1.string);
235       fileInput.Seek(@1.start.pos, start);
236       resetScannerPos(&@1.start);
237       yyclearin;
238
239       FreeIdentifier($1);
240
241       YYPOPSTACK(1);
242       yystate = *yyssp;
243       YY_STACK_PRINT (yyss, yyssp);
244       YYPOPSTACK(1);
245       yystate = *yyssp;
246       YY_STACK_PRINT (yyss, yyssp);
247       goto yysetstate;
248    }
249    | identifier '<'
250    {
251       $$ = null;
252    #ifdef PRECOMPILER
253       _DeclClass($1._class, $1.string);
254
255       FreeIdentifier($1);
256
257       fileInput.Seek(@1.start.pos, start);
258       resetScannerPos(&@1.start);
259       yyclearin;
260
261       YYPOPSTACK(1);
262       yystate = *yyssp;
263       YY_STACK_PRINT (yyss, yyssp);
264       YYPOPSTACK(1);
265       yystate = *yyssp;
266       YY_STACK_PRINT (yyss, yyssp);
267       goto yysetstate;
268    #endif
269    }
270    ;
271
272 real_guess_type:
273    identifier error
274    {
275       DeclClass($1._class, $1.string);
276       fileInput.Seek(@1.start.pos, start);
277       parseTypeError = 0;
278       resetScannerPos(&@1.start);
279       yyclearin;
280       FreeIdentifier($1);
281
282       YYPOPSTACK(1);
283       yystate = *yyssp;
284       YY_STACK_PRINT (yyss, yyssp);
285       YYPOPSTACK(1);
286       yystate = *yyssp;
287       YY_STACK_PRINT (yyss, yyssp);
288       goto yysetstate;
289    }
290 /*   | identifier '<'
291    {
292    #ifdef PRECOMPILER
293       _DeclClass($1._class, $1.string);
294
295       FreeIdentifier($1);
296
297       fileInput.Seek(@1.start.pos, start);
298       resetScannerPos(&@1.start);
299       yyclearin;
300
301       YYPOPSTACK(1);
302       yystate = *yyssp;
303       YY_STACK_PRINT (yyss, yyssp);
304       YYPOPSTACK(1);
305       yystate = *yyssp;
306       YY_STACK_PRINT (yyss, yyssp);
307       goto yysetstate;
308    #endif
309    }
310    ;
311 */
312 type:
313    strict_type       { $$ = $1; }
314    | identifier identifier
315    {
316    #ifdef PRECOMPILER
317       DeclClass($1._class, $1.string);
318       fileInput.Seek(@1.start.pos, start);
319       resetScannerPos(&@1.start);
320       yyclearin;
321
322       FreeIdentifier($1);
323       FreeIdentifier($2);
324
325       YYPOPSTACK(1);
326       yystate = *yyssp;
327       YY_STACK_PRINT (yyss, yyssp);
328       YYPOPSTACK(1);
329       yystate = *yyssp;
330       YY_STACK_PRINT (yyss, yyssp);
331       goto yysetstate;
332    #else
333       Location tmpLoc = yylloc; $$ = $2; yylloc = @1;
334       Compiler_Error($"Not a type: %s\n", $1.string);
335       yylloc = tmpLoc; $2.badID = $1; // FreeIdentifier($1);
336    #endif
337    }
338    ;
339
340 base_strict_type:
341      TYPE_NAME    { $$ = MkSpecifierName(yytext); }
342    ;
343
344 strict_type:
345      base_strict_type
346     | base_strict_type '<' template_arguments_list '>' { $$ = $1; SetClassTemplateArgs($$, $3); $$.loc = @$; }
347     | base_strict_type '<' template_arguments_list RIGHT_OP
348     {
349       $$ = $1;
350       SetClassTemplateArgs($$, $3);
351       $$.loc = @$;
352
353       @4.end.pos--;
354       fileInput.Seek(@4.end.pos, start);
355       resetScannerPos(&@4.end);
356       yyclearin;
357     }
358
359 /*  | identifier '<' template_arguments_list '>'
360       { $$ = MkSpecifierNameArgs($1.string, $3); $$.loc = @$; FreeIdentifier($1); } */
361    ;
362
363 class_function_definition_start:
364      guess_declaration_specifiers declarator_function
365       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; }
366    | declarator_function
367       { $$ = MkClassFunction(null, null, $1, null); $$.loc = @$; }
368    ;
369
370 constructor_function_definition_start:
371    guess_declaration_specifiers '(' ')'
372       { $$ = MkClassFunction(null, null, null, null); $$.isConstructor = true; $$.loc = @$; FreeList /*FreeSpecifier*/($1, FreeSpecifier); }
373    ;
374
375 destructor_function_definition_start:
376    '~' guess_declaration_specifiers '(' ')'
377       { $$ = MkClassFunction(null, null, null, null); $$.isDestructor = true; $$.loc = @$; FreeList /*FreeSpecifier*/($2, FreeSpecifier); }
378    ;
379
380 virtual_class_function_definition_start:
381      VIRTUAL guess_declaration_specifiers declarator_function
382       { $$ = MkClassFunction($2, null, $3, null); $$.isVirtual = true; $$.loc = @$; }
383    | VIRTUAL declarator_function
384       { $$ = MkClassFunction(null, null, $2, null); $$.isVirtual = true; $$.loc = @$; }
385       ;
386
387 identifier:
388    IDENTIFIER
389       { $$ = MkIdentifier(yytext); $$.loc = @1; }
390    ;
391
392 primary_expression:
393      simple_primary_expression
394         | '(' expression ')'
395       { $$ = MkExpBrackets($2); $$.loc = @$; }
396    ;
397
398 simple_primary_expression:
399           identifier
400       { $$ = MkExpIdentifier($1); $$.loc = @$; }
401    | instantiation_unnamed
402       { $$ = MkExpInstance($1); $$.loc = @$; }
403         | CONSTANT
404       { $$ = MkExpConstant(yytext); $$.loc = @$; }
405    | WIDE_STRING_LITERAL { $$ = MkExpWideString(yytext); $$.loc = @$; }
406         | string_literal
407       { $$ = MkExpString($1); delete $1; $$.loc = @$; }
408    | '$' string_literal     { $$ = MkExpIntlString($2, null); delete $2; $$.loc = @$; }
409    | '$' string_literal '.' string_literal     { $$ = MkExpIntlString($4, $2); delete $2; delete $4; $$.loc = @$; }
410    | '(' ')'
411       { Expression exp = MkExpDummy(); exp.loc.start = @1.end; exp.loc.end = @2.start; $$ = MkExpBrackets(MkListOne(exp)); $$.loc = @$; yyerror(); }
412
413    | NEWOP guess_declaration_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpNew(MkTypeName($2,$3), $5); $$.loc = @$; }
414    | NEWOP guess_declaration_specifiers '[' constant_expression ']' { $$ = MkExpNew(MkTypeName($2,null), $4); $$.loc = @$; }
415    | NEW0OP guess_declaration_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpNew0(MkTypeName($2,$3), $5); $$.loc = @$; }
416    | NEW0OP guess_declaration_specifiers '[' constant_expression ']' { $$ = MkExpNew0(MkTypeName($2,null), $4); $$.loc = @$; }
417    | RENEW constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpRenew($2, MkTypeName($3,$4), $6); $$.loc = @$; }
418    | RENEW constant_expression renew_specifiers '[' constant_expression ']' { $$ = MkExpRenew($2, MkTypeName($3,null), $5); $$.loc = @$; }
419    | RENEW0 constant_expression renew_specifiers abstract_declarator_noarray '[' constant_expression ']' { $$ = MkExpRenew0($2, MkTypeName($3,$4), $6); $$.loc = @$; }
420    | RENEW0 constant_expression renew_specifiers '[' constant_expression ']' { $$ = MkExpRenew0($2, MkTypeName($3,null), $5); $$.loc = @$; }
421    | error { $$ = MkExpDummy(); }
422    ;
423
424 postfix_expression:
425           primary_expression
426    | postfix_expression '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
427         | postfix_expression '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
428         | postfix_expression '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.loc = @$; }
429         | postfix_expression '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
430    | postfix_expression identifier
431    {
432       char * constant = $1.type == constantExp ? $1.constant : null;
433       int len = constant ? strlen(constant) : 0;
434       if(constant && constant[len-1] == '.')
435       {
436          constant[len-1] = 0;
437          $$ = MkExpMember($1, $2);
438          $$.loc = @$;
439       }
440       else
441          yyerror();
442    }
443         | postfix_expression PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
444         | postfix_expression INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
445         | postfix_expression DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
446         ;
447
448 anon_instantiation_expression:
449    instantiation_anon            { $$ = MkExpInstance($1); $$.loc = @$; }
450    ;
451
452 /*
453 simple_postfix_expression:
454           simple_primary_expression
455    | simple_postfix_expression '[' expression ']'               { $$ = MkExpIndex($1, $3); $$.loc = @$; }
456         | simple_postfix_expression '(' ')'                          { $$ = MkExpCall($1, MkList()); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @3.end; $$.loc = @$; }
457         | simple_postfix_expression '(' argument_expression_list ')' { $$ = MkExpCall($1, $3); $$.call.argLoc.start = @2.start; $$.call.argLoc.end = @4.end; $$.loc = @$; }
458         | simple_postfix_expression '.' identifier                   { $$ = MkExpMember($1, $3); $$.loc = @$; }
459    | simple_postfix_expression identifier
460    {
461       char * constant = $1.type == constantExp ? $1.constant : null;
462       int len = constant ? strlen(constant) : 0;
463       if(constant && constant[len-1] == '.')
464       {
465          constant[len-1] = 0;
466          $$ = MkExpMember($1, $2);
467          $$.loc = @$;
468       }
469       else
470          yyerror();
471    }
472         | simple_postfix_expression PTR_OP identifier                { $$ = MkExpPointer($1, $3); $$.loc = @$; }
473         | simple_postfix_expression INC_OP                           { $$ = MkExpOp($1, INC_OP, null); $$.loc = @$; }
474         | simple_postfix_expression DEC_OP                           { $$ = MkExpOp($1, DEC_OP, null); $$.loc = @$; }
475         ;
476 */
477 argument_expression_list:
478           assignment_expression          { $$ = MkList(); ListAdd($$, $1); }
479    | anon_instantiation_expression  { $$ = MkList(); ListAdd($$, $1); }
480         | argument_expression_list ',' assignment_expression   { $$ = $1; ListAdd($1, $3);  }
481    | argument_expression_list ',' anon_instantiation_expression   { $$ = $1; ListAdd($1, $3);  }
482         ;
483
484 common_unary_expression:
485           INC_OP unary_expression           { $$ = MkExpOp(null, INC_OP, $2); $$.loc = @$; }
486         | DEC_OP unary_expression           { $$ = MkExpOp(null, DEC_OP, $2); $$.loc = @$; }
487         | unary_operator cast_expression    { $$ = MkExpOp(null, $1, $2); $$.loc = @$; }
488         //| SIZEOF '(' unary_expression ')'         { $$ = MkExpOp(null, SIZEOF, $3); $$.loc = @$; }
489    | SIZEOF unary_expression          { $$ = MkExpOp(null, SIZEOF, $2); $$.loc = @$; }
490    | SIZEOF '(' guess_type_name ')'          { $$ = MkExpTypeSize($3); $$.loc = @$; }
491         //| ALIGNOF '(' unary_expression ')'         { $$ = MkExpOp(null, ALIGNOF, $3); $$.loc = @$; }
492    | ALIGNOF unary_expression          { $$ = MkExpOp(null, ALIGNOF, $2); $$.loc = @$; }
493    | ALIGNOF '(' guess_type_name ')'          { $$ = MkExpTypeAlign($3); $$.loc = @$; }
494    ;
495
496 unary_expression:
497        common_unary_expression
498           | postfix_expression
499         ;
500 /*
501 simple_unary_expression:
502      common_unary_expression
503         | simple_postfix_expression
504         ;
505 */
506 unary_operator:
507           '&'     { $$ = '&'; }
508         | '*'     { $$ = '*'; }
509         | '+'     { $$ = '+'; }
510         | '-'     { $$ = '-'; }
511         | '~'     { $$ = '~'; }
512         | '!'     { $$ = '!'; }
513    | DELETE  { $$ = DELETE; }
514         ;
515
516 cast_expression:
517      unary_expression
518         | '(' type_name ')' cast_expression    { $$ = MkExpCast($2, $4); $$.loc = @$; }
519         ;
520
521 multiplicative_expression:
522           cast_expression
523         | multiplicative_expression '*' cast_expression { $$ = MkExpOp($1, '*', $3); $$.loc = @$; }
524         | multiplicative_expression '/' cast_expression { $$ = MkExpOp($1, '/', $3); $$.loc = @$; }
525         | multiplicative_expression '%' cast_expression { $$ = MkExpOp($1, '%', $3); $$.loc = @$; }
526         ;
527
528 additive_expression:
529           multiplicative_expression
530         | additive_expression '+' multiplicative_expression  { $$ = MkExpOp($1, '+', $3); $$.loc = @$; }
531         | additive_expression '-' multiplicative_expression  { $$ = MkExpOp($1, '-', $3); $$.loc = @$; }
532         ;
533
534 shift_expression:
535           additive_expression
536         | shift_expression LEFT_OP additive_expression  { $$ = MkExpOp($1, LEFT_OP, $3); $$.loc = @$; }
537         | shift_expression RIGHT_OP additive_expression { $$ = MkExpOp($1, RIGHT_OP, $3); $$.loc = @$; }
538         ;
539
540 relational_expression_smaller_than:
541    relational_expression '<'
542    {
543       $$ = $1;
544       skipErrors = true;
545    }
546    ;
547
548 relational_expression:
549           shift_expression
550         | relational_expression_smaller_than /*relational_expression '<' */ shift_expression    { skipErrors = false; $$ = MkExpOp($1, '<', $2/*$3*/); $$.loc = @$; }
551         | relational_expression '>' shift_expression    { $$ = MkExpOp($1, '>', $3); $$.loc = @$; }
552         | relational_expression LE_OP shift_expression  { $$ = MkExpOp($1, LE_OP, $3); $$.loc = @$; }
553         | relational_expression GE_OP shift_expression  { $$ = MkExpOp($1, GE_OP, $3); $$.loc = @$; }
554         ;
555
556 equality_expression:
557           relational_expression
558         | equality_expression EQ_OP relational_expression  { $$ = MkExpOp($1, EQ_OP, $3); $$.loc = @$; }
559         | equality_expression NE_OP relational_expression  { $$ = MkExpOp($1, NE_OP, $3); $$.loc = @$; }
560         ;
561
562 and_expression:
563           equality_expression
564         | and_expression '&' equality_expression  { $$ = MkExpOp($1, '&', $3); $$.loc = @$; }
565         ;
566
567 exclusive_or_expression:
568           and_expression
569         | exclusive_or_expression '^' and_expression { $$ = MkExpOp($1, '^', $3); $$.loc = @$; }
570         ;
571
572 inclusive_or_expression:
573           exclusive_or_expression
574         | inclusive_or_expression '|' exclusive_or_expression { $$ = MkExpOp($1, '|', $3); $$.loc = @$; }
575         ;
576
577 logical_and_expression:
578           inclusive_or_expression
579         | logical_and_expression AND_OP inclusive_or_expression  { $$ = MkExpOp($1, AND_OP, $3); $$.loc = @$; }
580         ;
581
582 logical_or_expression:
583           logical_and_expression
584         | logical_or_expression OR_OP logical_and_expression     { $$ = MkExpOp($1, OR_OP, $3); $$.loc = @$; }
585         ;
586
587 conditional_expression:
588           logical_or_expression
589         | logical_or_expression '?' expression ':' conditional_expression { $$ = MkExpCondition($1, $3, $5); $$.loc = @$; }
590         ;
591
592 assignment_expression:
593           conditional_expression
594         | unary_expression assignment_operator assignment_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
595         | unary_expression assignment_operator anon_instantiation_expression   { $$ = MkExpOp($1, $2, $3); $$.loc = @$; }
596    ;
597
598 assignment_operator:
599           '='                   { $$ = '='; }
600         | MUL_ASSIGN            { $$ = MUL_ASSIGN; }
601         | DIV_ASSIGN            { $$ = DIV_ASSIGN; }
602         | MOD_ASSIGN            { $$ = MOD_ASSIGN; }
603         | ADD_ASSIGN            { $$ = ADD_ASSIGN; }
604         | SUB_ASSIGN            { $$ = SUB_ASSIGN; }
605         | LEFT_ASSIGN           { $$ = LEFT_ASSIGN; }
606         | RIGHT_ASSIGN          { $$ = RIGHT_ASSIGN; }
607         | AND_ASSIGN            { $$ = AND_ASSIGN; }
608         | XOR_ASSIGN            { $$ = XOR_ASSIGN; }
609         | OR_ASSIGN             { $$ = OR_ASSIGN; }
610         ;
611
612 expression:
613      assignment_expression                 { $$ = MkList(); ListAdd($$, $1); }
614         | expression ',' assignment_expression  { $$ = $1; ListAdd($1, $3); }
615         ;
616
617 constant_expression:
618           conditional_expression
619         ;
620
621 declaration:
622           declaration_specifiers ';'                       { $$ = MkDeclaration($1, null); $$.loc = @$; }
623         | declaration_specifiers init_declarator_list ';'  { $$ = MkDeclaration($1, $2); $$.loc = @$; }
624    | instantiation_named ';'                          { $$ = MkDeclarationInst($1); $$.loc = @$; }
625    | DEFINE identifier '=' constant_expression ';'           { $$ = MkDeclarationDefine($2, $4); $$.loc = @$; }
626         ;
627
628 specifier_qualifier_list:
629      type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
630    | specifier_qualifier_list  type_qualifier            { $$ = $1; ListAdd($1, $2); }
631    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
632    | specifier_qualifier_list  type_specifier            { $$ = $1; ListAdd($1, $2); }
633    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
634         | specifier_qualifier_list enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
635    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
636         | specifier_qualifier_list struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
637    ;
638
639 guess_specifier_qualifier_list:
640      type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
641    | guess_specifier_qualifier_list  type_qualifier            { $$ = $1; ListAdd($1, $2); }
642    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
643    | guess_specifier_qualifier_list  type_specifier            { $$ = $1; ListAdd($1, $2); }
644    | guess_type                                       { $$ = MkList(); ListAdd($$, $1); }
645    | guess_specifier_qualifier_list  guess_type            { $$ = $1; ListAdd($1, $2); }
646    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
647         | guess_specifier_qualifier_list enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
648    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
649         | guess_specifier_qualifier_list struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
650    ;
651
652 declaration_specifiers:
653      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
654    | declaration_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
655    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
656    | declaration_specifiers  type_qualifier            { $$ = $1; ListAdd($1, $2); }
657    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
658    | declaration_specifiers  type_specifier            { $$ = $1; ListAdd($1, $2); }
659    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
660         | declaration_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
661    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
662         | declaration_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
663    ;
664
665 guess_declaration_specifiers:
666      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
667    | guess_declaration_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
668    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
669    | guess_declaration_specifiers  type_qualifier            { $$ = $1; ListAdd($1, $2); }
670    | type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
671    | guess_declaration_specifiers  type_specifier            { $$ = $1; ListAdd($1, $2); }
672    | guess_type                                       { $$ = MkList(); ListAdd($$, $1); }
673         | guess_declaration_specifiers guess_type          { $$ = $1; ListAdd($1, $2); }
674    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
675         | guess_declaration_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
676    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
677         | guess_declaration_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
678    ;
679
680 real_guess_declaration_specifiers:
681        guess_declaration_specifiers                          { $$ = $1; }
682      | real_guess_type                                       { $$ = MkList(); ListAdd($$, $1); }
683    ;
684
685 property_specifiers:
686      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
687    | property_specifiers storage_class_specifier     { $$ = $1; ListAdd($1, $2); }
688    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
689    | property_specifiers type_qualifier            { $$ = $1; ListAdd($1, $2); }
690    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
691    | property_specifiers strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
692    | identifier                        { $$ = MkList(); ListAdd($$, MkSpecifierName($1.string)); FreeIdentifier($1); }
693    | property_specifiers identifier          { ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2); }
694    | identifier '<' template_arguments_list '>'
695       {
696          _DeclClass($1._class, $1.string);
697
698          $$ = MkList();
699          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
700          FreeIdentifier($1);
701       }
702    | property_specifiers identifier '<' template_arguments_list '>'
703       {
704          _DeclClass($2._class, $2.string);
705          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
706          FreeIdentifier($2);
707       }
708    ;
709
710 renew_specifiers:
711      storage_class_specifier                          { $$ = MkList(); ListAdd($$, $1); }
712    | renew_specifiers storage_class_specifier    { $$ = $1; ListAdd($1, $2); }
713    | type_qualifier                                   { $$ = MkList(); ListAdd($$, $1); }
714    | renew_specifiers type_qualifier            { $$ = $1; ListAdd($1, $2); }
715    | strict_type_specifier                                   { $$ = MkList(); ListAdd($$, $1); }
716    | renew_specifiers strict_type_specifier            { $$ = $1; ListAdd($1, $2); }
717    | struct_or_union_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
718         | renew_specifiers struct_or_union_specifier_compound          { $$ = $1; ListAdd($1, $2); }
719    | enum_specifier_compound              { $$ = MkList(); ListAdd($$, $1); }
720         | renew_specifiers enum_specifier_compound          { $$ = $1; ListAdd($1, $2); }
721    | identifier                        { $$ = MkList(); ListAdd($$, MkSpecifierName($1.string)); FreeIdentifier($1); }
722    | renew_specifiers identifier          { $$ = $1; ListAdd($1, MkSpecifierName($2.string)); FreeIdentifier($2)}
723    | identifier '<' template_arguments_list '>'
724       {
725          _DeclClass($1._class, $1.string);
726
727          $$ = MkList();
728          ListAdd($$, MkSpecifierNameArgs($1.string, $3));
729          FreeIdentifier($1);
730       }
731    | renew_specifiers identifier '<' template_arguments_list '>'
732       {
733          _DeclClass($2._class, $2.string);
734          ListAdd($1, MkSpecifierNameArgs($2.string, $4));
735          FreeIdentifier($2);
736       }
737    ;
738
739 init_declarator_list:
740           init_declarator                            { $$ = MkList(); ListAdd($$, $1); }
741         | init_declarator_list ',' init_declarator   { $$ = $1; ListAdd($1, $3); }
742         ;
743
744 init_declarator:
745           declarator                        { $$ = MkInitDeclarator($1, null); $$.loc = @$; }
746         | declarator '=' initializer                 { $$ = MkInitDeclarator($1, $3); $$.loc = @$; $$.initializer.loc.start = @2.end; }
747         ;
748
749 storage_class_specifier:
750           TYPEDEF       { $$ = MkSpecifier(TYPEDEF); }
751         | EXTERN        { $$ = MkSpecifier(EXTERN); }
752         | STATIC        { $$ = MkSpecifier(STATIC); }
753         | AUTO          { $$ = MkSpecifier(AUTO); }
754         | REGISTER      { $$ = MkSpecifier(REGISTER); }
755    | THREAD        { $$ = MkSpecifier(THREAD); }
756         ;
757
758 ext_decl:
759      EXT_DECL { $$ = MkExtDeclString(CopyString(yytext)); }
760    | EXT_STORAGE { $$ = MkExtDeclString(CopyString(yytext)); }
761    | attrib { $$ = MkExtDeclAttrib($1); }
762    ;
763
764 _attrib:
765    ATTRIB      { $<i>$ = ATTRIB; }
766  | ATTRIB_DEP  { $<i>$ = ATTRIB_DEP; }
767  | __ATTRIB    { $<i>$ = __ATTRIB; }
768  ;
769
770
771 attribute_word:
772      IDENTIFIER   { $$  = CopyString(yytext); }
773    | TYPE_NAME    { $$  = CopyString(yytext); }
774    | EXT_STORAGE  { $$  = CopyString(yytext); }
775    | EXT_DECL     { $$  = CopyString(yytext); }
776    | CONST        { $$  = CopyString(yytext); }
777    ;
778
779 attribute:
780      attribute_word  { $$ = MkAttribute($1, null); $$.loc = @$; }
781    | attribute_word '(' expression ')'  { $$ = MkAttribute($1, MkExpBrackets($3)); $$.loc = @$; }
782    ;
783
784 attribs_list:
785      attribute { $$ = MkListOne($1); }
786    | attribs_list attribute { ListAdd($1, $2); $$ = $1; }
787    | attribs_list ',' attribute { ListAdd($1, $3); $$ = $1; }
788    ;
789
790 attrib:
791      _attrib '(' '(' attribs_list ')' ')' { $$ = MkAttrib($<i>1, $4); $$.loc = @$; }
792    | _attrib '(' '('              ')' ')'  { $$ = MkAttrib($<i>1, null); $$.loc = @$; }
793    ;
794
795 ext_storage:
796    ext_decl   { $$ = MkSpecifierExtended($1); }
797    ;
798
799 type_qualifier:
800           CONST        { $$ = MkSpecifier(CONST); }
801         | VOLATILE     { $$ = MkSpecifier(VOLATILE); }
802    | ext_storage  { $$ = $1; }
803         ;
804
805
806 type_specifier:
807           VOID            { $$ = MkSpecifier(VOID); }
808         | CHAR            { $$ = MkSpecifier(CHAR); }
809         | SHORT           { $$ = MkSpecifier(SHORT); }
810         | INT             { $$ = MkSpecifier(INT); }
811    | UINT            { $$ = MkSpecifier(UINT); }
812    | INT64           { $$ = MkSpecifier(INT64); }
813    | INT128          { $$ = MkSpecifier(INT128); }
814    | VALIST          { $$ = MkSpecifier(VALIST); }
815         | LONG            { $$ = MkSpecifier(LONG); }
816         | FLOAT           { $$ = MkSpecifier(FLOAT); }
817         | DOUBLE          { $$ = MkSpecifier(DOUBLE); }
818         | SIGNED          { $$ = MkSpecifier(SIGNED); }
819         | UNSIGNED        { $$ = MkSpecifier(UNSIGNED); }
820    | EXTENSION       { $$ = MkSpecifier(EXTENSION); }
821    | _BOOL           { $$ = MkSpecifier(_BOOL); }
822    | BOOL            { $$ = MkSpecifier(BOOL); }
823         | struct_or_union_specifier_nocompound
824         | enum_specifier_nocompound
825         | type
826    | TYPEOF '(' assignment_expression ')' { $$ = MkSpecifierTypeOf($3); }
827    | SUBCLASS '(' type ')'                { $$ = MkSpecifierSubClass($3); }
828    | SUBCLASS '(' identifier ')'          { _DeclClass($3._class, $3.string); $$ = MkSpecifierSubClass(MkSpecifierName($3.string)); FreeIdentifier($3); }
829    | THISCLASS       { $$ = MkSpecifier(THISCLASS); }
830    | TYPED_OBJECT    { $$ = MkSpecifier(TYPED_OBJECT); }
831    | ANY_OBJECT      { $$ = MkSpecifier(ANY_OBJECT); }
832         ;
833
834 strict_type_specifier:
835           VOID            { $$ = MkSpecifier(VOID); }
836         | CHAR            { $$ = MkSpecifier(CHAR); }
837         | SHORT           { $$ = MkSpecifier(SHORT); }
838         | INT             { $$ = MkSpecifier(INT); }
839    | UINT            { $$ = MkSpecifier(UINT); }
840    | INT64           { $$ = MkSpecifier(INT64); }
841    | INT128          { $$ = MkSpecifier(INT128); }
842    | VALIST          { $$ = MkSpecifier(VALIST); }
843         | LONG            { $$ = MkSpecifier(LONG); }
844         | FLOAT           { $$ = MkSpecifier(FLOAT); }
845         | DOUBLE          { $$ = MkSpecifier(DOUBLE); }
846         | SIGNED          { $$ = MkSpecifier(SIGNED); }
847         | UNSIGNED        { $$ = MkSpecifier(UNSIGNED); }
848    | EXTENSION       { $$ = MkSpecifier(EXTENSION); }
849    | _BOOL           { $$ = MkSpecifier(_BOOL); }
850    | BOOL            { $$ = MkSpecifier(BOOL); }
851         | struct_or_union_specifier_nocompound
852         | enum_specifier_nocompound
853         | strict_type
854    | TYPEOF '(' assignment_expression ')' { $$ = MkSpecifierTypeOf($3); }
855    | SUBCLASS '(' type ')'                { $$ = MkSpecifierSubClass($3); }
856    | SUBCLASS '(' identifier ')'          { _DeclClass($3._class, $3.string); $$ = MkSpecifierSubClass(MkSpecifierName($3.string)); FreeIdentifier($3); }
857    | THISCLASS       { $$ = MkSpecifier(THISCLASS); }
858         ;
859
860
861 struct_or_union_specifier_compound:
862           struct_or_union identifier '{' struct_declaration_list '}'   { $$ = MkStructOrUnion($1, $2, $4); if(declMode) DeclClass($2._class, $2.string); }
863         | struct_or_union '{' struct_declaration_list '}'              { $$ = MkStructOrUnion($1, null, $3); }
864    | struct_or_union identifier '{' '}'   { $$ = MkStructOrUnion($1, $2, null); if(declMode) DeclClass($2._class, $2.string); }
865    | struct_or_union '{' '}'              { $$ = MkStructOrUnion($1, null, null); }
866         | struct_or_union base_strict_type '{' struct_declaration_list '}'
867       { $$ = MkStructOrUnion($1, MkIdentifier($2.name), $4); if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
868
869         | struct_or_union ext_decl identifier '{' struct_declaration_list '}'   { $$ = MkStructOrUnion($1, $3, $5); $$.extDeclStruct = $2; if(declMode) DeclClass($3._class, $3.string); }
870         | struct_or_union ext_decl '{' struct_declaration_list '}'              { $$ = MkStructOrUnion($1, null, $4); $$.extDeclStruct = $2; }
871    | struct_or_union ext_decl identifier '{' '}'   { $$ = MkStructOrUnion($1, $3, null); $$.extDeclStruct = $2; if(declMode) DeclClass($3._class, $3.string); }
872    | struct_or_union ext_decl '{' '}'              { $$ = MkStructOrUnion($1, null, null); $$.extDeclStruct = $2; }
873         | struct_or_union ext_decl strict_type '{' struct_declaration_list '}'
874       { $$ = MkStructOrUnion($1, MkIdentifier($3.name), $5); $$.extDeclStruct = $2; if(declMode) DeclClass($3.nsSpec, $3.name); FreeSpecifier($3); }
875         ;
876
877 struct_or_union_specifier_nocompound:
878           struct_or_union identifier                                   { $$ = MkStructOrUnion($1, $2, null); if(declMode) DeclClass($2._class, $2.string); }
879         | struct_or_union strict_type
880       { $$ = MkStructOrUnion($1, MkIdentifier($2.name), null); if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
881
882         | struct_or_union ext_decl identifier
883       { $$ = MkStructOrUnion($1, $3, null); $$.extDeclStruct = $2;if(declMode) DeclClass($3._class, $3.string); }
884         | struct_or_union ext_decl strict_type
885       { $$ = MkStructOrUnion($1, MkIdentifier($3.name), null); $$.extDeclStruct = $2; if(declMode) DeclClass($3.nsSpec, $3.name); FreeSpecifier($3); }
886         ;
887
888 template_datatype:
889      guess_declaration_specifiers { $$ = MkTemplateDatatype($1, null); }
890    | guess_declaration_specifiers abstract_declarator { $$ = MkTemplateDatatype($1, $2); }
891    /*| identifier { $$ = MkTemplateDatatype(MkListOne(MkSpecifierName($1.string)), null); FreeIdentifier($1); }*/
892    ;
893
894 template_type_argument:
895      guess_declaration_specifiers { $$ = MkTemplateTypeArgument(MkTemplateDatatype($1, null)); }
896    | guess_declaration_specifiers abstract_declarator { $$ = MkTemplateTypeArgument(MkTemplateDatatype($1, $2)); }
897      //template_datatype { $$ = MkTemplateTypeArgument($1); }
898    ;
899
900 /*
901 template_identifier_argument:
902      identifier { $$ = MkTemplateIdentifierArgument($1); }
903    ;
904 */
905
906 template_expression_argument:
907      shift_expression /*constant_expression*/ { $$ = MkTemplateExpressionArgument($1); }
908    ;
909
910 template_argument:
911      template_expression_argument
912    /*| template_identifier_argument*/
913    | template_type_argument
914    | identifier '=' template_expression_argument   { $$ = $3; $$.name = $1; $$.loc = @$; }
915    /*| identifier '=' template_identifier_argument   { $$ = $3; $$.name = $1; $$.loc = @$; }*/
916    | identifier '=' template_type_argument         { $$ = $3; $$.name = $1; $$.loc = @$; }
917    | template_datatype '=' template_expression_argument
918    {
919       $$ = $3;
920       if($1.specifiers && $1.specifiers->first)
921       {
922          Specifier spec = $1.specifiers->first;
923          if(spec.type == nameSpecifier)
924             $$.name = MkIdentifier(spec.name);
925       }
926       FreeTemplateDataType($1);
927       $$.loc = @$;
928    }
929    /*| template_datatype '=' template_identifier_argument
930    {
931       $$ = $3;
932       if($1.specifiers && $1.specifiers->first)
933       {
934          Specifier spec = $1.specifiers->first;
935          if(spec.type == nameSpecifier)
936             $$.name = MkIdentifier(spec.name);
937       }
938       FreeTemplateDataType($1);
939       $$.loc = @$;
940    } */
941    | template_datatype '=' template_type_argument
942    {
943       $$ = $3;
944       if($1.specifiers && $1.specifiers->first)
945       {
946          Specifier spec = $1.specifiers->first;
947          if(spec.type == nameSpecifier)
948             $$.name = MkIdentifier(spec.name);
949       }
950       FreeTemplateDataType($1);
951       $$.loc = @$;
952    }
953    ;
954
955 template_arguments_list:
956      template_argument                                { $$ = MkList(); ListAdd($$, $1); }
957    | template_arguments_list ',' template_argument    { ListAdd($1, $3); }
958    ;
959
960 struct_or_union:
961           STRUCT    { $$ = structSpecifier; }
962         | UNION     { $$ = unionSpecifier; }
963         ;
964
965 struct_declaration_list:
966           struct_declaration                            { $$ = MkList(); ListAdd($$, $1); }
967         | struct_declaration_list struct_declaration    { $$ = $1; ListAdd($1, $2); }
968         ;
969
970 default_property:
971      postfix_expression '=' initializer_condition { $$ = MkMemberInitExp($1, $3); $$.loc = @$; $$.realLoc = @$; }
972    ;
973
974 default_property_list:
975      default_property        { $$ = MkList(); ListAdd($$, $1); ((MemberInit)$$->last).loc = @$; }
976    | default_property_list ',' default_property      { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
977    ;
978
979 property:
980    PROPERTY property_specifiers identifier '{' SETPROP compound_statement GETPROP compound_statement '}'
981       { $$ = MkProperty($2, null, $3, $6, $8); $$.loc = @$; }
982    | PROPERTY property_specifiers identifier '{' GETPROP compound_statement SETPROP compound_statement '}'
983       { $$ = MkProperty($2, null, $3, $8, $6); $$.loc = @$; }
984    | PROPERTY property_specifiers identifier '{' SETPROP compound_statement '}'
985       { $$ = MkProperty($2, null, $3, $6, null); $$.loc = @$; }
986    | PROPERTY property_specifiers identifier '{' GETPROP compound_statement '}'
987       { $$ = MkProperty($2, null, $3, null, $6); $$.loc = @$; }
988    | PROPERTY property_specifiers identifier '{' '}'
989       { $$ = MkProperty($2, null, $3, null, null); $$.loc = @$; }
990
991    | PROPERTY property_specifiers abstract_declarator identifier '{' SETPROP compound_statement GETPROP compound_statement '}'
992       { $$ = MkProperty($2, $3, $4, $7, $9); $$.loc = @$; }
993    | PROPERTY property_specifiers abstract_declarator identifier '{' GETPROP compound_statement SETPROP compound_statement '}'
994       { $$ = MkProperty($2, $3, $4, $9, $7); $$.loc = @$; }
995    | PROPERTY property_specifiers abstract_declarator identifier '{' SETPROP compound_statement '}'
996       { $$ = MkProperty($2, $3, $4, $7, null); $$.loc = @$; }
997    | PROPERTY property_specifiers abstract_declarator identifier '{' GETPROP compound_statement '}'
998       { $$ = MkProperty($2, $3, $4, null, $7); $$.loc = @$; }
999    | PROPERTY property_specifiers abstract_declarator identifier '{' '}'
1000       { $$ = MkProperty($2, $3, $4, null, null); $$.loc = @$; }
1001
1002    | PROPERTY property_specifiers '{' SETPROP compound_statement GETPROP compound_statement '}'
1003       { $$ = MkProperty($2, null, null, $5, $7); $$.loc = @$; }
1004    | PROPERTY property_specifiers '{' GETPROP compound_statement SETPROP compound_statement '}'
1005       { $$ = MkProperty($2, null, null, $7, $5); $$.loc = @$; }
1006    | PROPERTY property_specifiers '{' SETPROP compound_statement '}'
1007       { $$ = MkProperty($2, null, null, $5, null); $$.loc = @$; }
1008    | PROPERTY property_specifiers '{' GETPROP compound_statement '}'
1009       { $$ = MkProperty($2, null, null, null, $5); $$.loc = @$; }
1010    | PROPERTY property_specifiers '{' '}'
1011       { $$ = MkProperty($2, null, null, null, null); $$.loc = @$; }
1012
1013    | PROPERTY property_specifiers abstract_declarator '{' SETPROP compound_statement GETPROP compound_statement '}'
1014       { $$ = MkProperty($2, $3, null, $6, $8); $$.loc = @$; }
1015    | PROPERTY property_specifiers abstract_declarator '{' GETPROP compound_statement SETPROP compound_statement '}'
1016       { $$ = MkProperty($2, $3, null, $8, $6); $$.loc = @$; }
1017    | PROPERTY property_specifiers abstract_declarator '{' SETPROP compound_statement '}'
1018       { $$ = MkProperty($2, $3, null, $6, null); $$.loc = @$; }
1019    | PROPERTY property_specifiers abstract_declarator '{' GETPROP compound_statement '}'
1020       { $$ = MkProperty($2, $3, null, null, $6); $$.loc = @$; }
1021    | PROPERTY property_specifiers abstract_declarator '{' '}'
1022       { $$ = MkProperty($2, $3, null, null, null); $$.loc = @$; }
1023 ;
1024
1025 struct_declaration:
1026           guess_declaration_specifiers struct_declarator_list ';'         { $$ = MkClassDefDeclaration(MkStructDeclaration($1, $2, null)); $$.decl.loc = @$; $$.loc = @$; }
1027    | guess_declaration_specifiers ';'                                { $$ = MkClassDefDeclaration(MkStructDeclaration($1, null, null)); $$.decl.loc = @$; $$.loc = @$; }
1028    | instantiation_unnamed ';'                                       { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = @$; $$.decl.loc = @$; }
1029    | guess_instantiation_named ';'                                   { $$ = MkClassDefDeclaration(MkDeclarationClassInst($1)); $$.loc = @$; $$.decl.loc = @$; }
1030    | class_function_definition                                       { $$ = MkClassDefFunction($1); $$.loc = @$; }
1031    | default_property_list ';' { $$ = MkClassDefDefaultProperty($1); if($1->last) ((MemberInit)$1->last).loc.end = @2.start; $$.loc = @$; }
1032    | property { $$ = MkClassDefProperty($1); $$.loc = @$; }
1033    | ';' { $$ = null; }
1034         ;
1035
1036 struct_declarator_list:
1037           struct_declarator
1038       { $$ = MkList(); ListAdd($$, $1); }
1039         | struct_declarator_list ',' struct_declarator
1040       { $$ = $1; ListAdd($1, $3); }
1041         ;
1042
1043 struct_declarator:
1044           declarator_nofunction
1045       { $$ = MkStructDeclarator($1, null); $$.loc = @$; }
1046         | declarator_nofunction attrib
1047       { $$ = MkStructDeclarator($1, null); $$.structDecl.attrib = $2; $$.loc = @$; }
1048         | ':' constant_expression
1049       { $$ = MkStructDeclarator(null, $2);  $$.loc = @$; }
1050         | declarator_nofunction ':' constant_expression
1051       { $$ = MkStructDeclarator($1, $3);  $$.loc = @$; }
1052    | declarator_nofunction ':' constant_expression ':' constant_expression
1053       { $$ = MkStructDeclarator($1, $3); $$.structDecl.posExp = $5; $$.loc = @$; }
1054         ;
1055
1056 enum_specifier_nocompound:
1057      ENUM identifier                            { $$ = MkEnum($2, null); if(declMode) DeclClass($2._class, $2.string); }
1058    | ENUM strict_type                           { $$ = MkEnum(MkIdentifier($2.name), null); if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
1059    ;
1060
1061 enum_specifier_compound:
1062           ENUM '{' enumerator_list '}'
1063       { $$ = MkEnum(null, $3); }
1064         | ENUM identifier '{' enumerator_list '}'    { $$ = MkEnum($2, $4); if(declMode) DeclClass($2._class, $2.string); }
1065    | ENUM identifier '{' enumerator_list ';' struct_declaration_list '}'    { $$ = MkEnum($2, $4); $$.definitions = $6; if(declMode) DeclClass($2._class, $2.string); }
1066         | ENUM strict_type '{' enumerator_list ';' struct_declaration_list '}'          { $$ = MkEnum(MkIdentifier($2.name), $4); $$.definitions = $6; if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
1067    | ENUM strict_type '{' enumerator_list '}'          { $$ = MkEnum(MkIdentifier($2.name), $4); if(declMode) DeclClass($2.nsSpec, $2.name); FreeSpecifier($2); }
1068         ;
1069
1070 enumerator_list:
1071           enumerator
1072       { $$ = MkList(); ListAdd($$, $1); }
1073         | enumerator_list ',' enumerator
1074       { $$ = $1; ListAdd($1, $3); }
1075         ;
1076
1077 enumerator:
1078           identifier
1079       { $$ = MkEnumerator($1, null); }
1080         | identifier '=' constant_expression
1081       { $$ = MkEnumerator($1, $3); }
1082         ;
1083
1084
1085 direct_abstract_declarator:
1086           '(' abstract_declarator ')'
1087                                  { $$ = MkDeclaratorBrackets($2); }
1088         | '[' ']'
1089                                  { $$ = MkDeclaratorArray(null, null); }
1090    | '[' constant_expression ']'
1091                                  { $$ = MkDeclaratorArray(null, $2); }
1092    | '[' type ']'
1093                                  { $$ = MkDeclaratorEnumArray(null, $2); }
1094         | direct_abstract_declarator '[' ']'
1095                                  { $$ = MkDeclaratorArray($1, null); }
1096         | direct_abstract_declarator '[' constant_expression ']'
1097                                  { $$ = MkDeclaratorArray($1, $3); }
1098         | direct_abstract_declarator '[' type']'
1099                                  { $$ = MkDeclaratorEnumArray($1, $3); }
1100         | '(' ')'
1101                                  { $$ = MkDeclaratorFunction(null, null); }
1102         | '(' parameter_type_list ')'
1103                                  { $$ = MkDeclaratorFunction(null, $2); }
1104         | direct_abstract_declarator '(' ')'
1105                                  { $$ = MkDeclaratorFunction($1, null); }
1106         | direct_abstract_declarator '(' parameter_type_list ')'
1107                                  { $$ = MkDeclaratorFunction($1, $3); }
1108         ;
1109
1110 direct_abstract_declarator_noarray:
1111           '(' abstract_declarator_noarray ')'
1112                                  { $$ = MkDeclaratorBrackets($2); }
1113         | '(' ')'
1114                                  { $$ = MkDeclaratorFunction(null, null); }
1115         | '(' parameter_type_list ')'
1116                                  { $$ = MkDeclaratorFunction(null, $2); }
1117         | direct_abstract_declarator_noarray '(' ')'
1118                                  { $$ = MkDeclaratorFunction($1, null); }
1119         | direct_abstract_declarator_noarray '(' parameter_type_list ')'
1120                                  { $$ = MkDeclaratorFunction($1, $3); }
1121         ;
1122
1123 abstract_declarator:
1124           pointer                              { $$ = MkDeclaratorPointer($1, null); }
1125         | direct_abstract_declarator
1126         | pointer direct_abstract_declarator   { $$ = MkDeclaratorPointer($1, $2); }
1127    | ext_decl pointer                     { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, null)); }
1128    | ext_decl direct_abstract_declarator  { $$ = MkDeclaratorExtended($1, $2); }
1129         | ext_decl pointer direct_abstract_declarator { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
1130         ;
1131
1132 abstract_declarator_noarray:
1133           pointer                              { $$ = MkDeclaratorPointer($1, null); }
1134         | direct_abstract_declarator_noarray
1135         | pointer direct_abstract_declarator_noarray   { $$ = MkDeclaratorPointer($1, $2); }
1136    | ext_decl pointer { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, null)); }
1137    | ext_decl direct_abstract_declarator_noarray { $$ = MkDeclaratorExtended($1, $2); }
1138         | ext_decl pointer direct_abstract_declarator_noarray { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
1139         ;
1140
1141 /*
1142 abstract_declarator:
1143           pointer
1144       { $$ = MkDeclaratorPointer($1, null); }
1145         | direct_abstract_declarator
1146         | pointer direct_abstract_declarator
1147       { $$ = MkDeclaratorPointer($1, $2); }
1148
1149    | ext_decl pointer
1150       { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, null)); }
1151         | ext_decl direct_abstract_declarator
1152       { $$ = MkDeclaratorExtended($1, $2); }
1153         | ext_decl pointer direct_abstract_declarator
1154       { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
1155
1156         ;
1157
1158 direct_abstract_declarator:
1159           '(' abstract_declarator ')'
1160       { $$ = MkDeclaratorBrackets($2); }
1161         | '[' ']'
1162       { $$ = MkDeclaratorArray(null, null); }
1163         | '[' constant_expression ']'
1164       { $$ = MkDeclaratorArray(null, $2); }
1165    | '[' type ']'
1166       { $$ = MkDeclaratorEnumArray(null, $2); }
1167         | direct_abstract_declarator '[' ']'
1168       { $$ = MkDeclaratorArray($1, null); }
1169         | direct_abstract_declarator '[' constant_expression ']'
1170       { $$ = MkDeclaratorArray($1, $3); }
1171         | direct_abstract_declarator '[' type ']'
1172       { $$ = MkDeclaratorEnumArray($1, $3); }
1173         | '(' ')'
1174       { $$ = MkDeclaratorFunction(null, null); }
1175         | '(' parameter_type_list ')'
1176       { $$ = MkDeclaratorFunction(null, $2); }
1177         | direct_abstract_declarator '(' ')'
1178       { $$ = MkDeclaratorFunction($1, null); }
1179         | direct_abstract_declarator '(' parameter_type_list ')'
1180       { $$ = MkDeclaratorFunction($1, $3); }
1181         ;
1182 */
1183 declarator:
1184           direct_declarator
1185         | pointer direct_declarator
1186       { $$ = MkDeclaratorPointer($1, $2); }
1187    | ext_decl pointer direct_declarator
1188       { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
1189    | declarator ext_decl
1190       { $$ = MkDeclaratorExtendedEnd($2, $1); }
1191    ;
1192
1193 direct_declarator_nofunction:
1194           identifier
1195       { $$ = MkDeclaratorIdentifier($1); }
1196         | '(' declarator ')'
1197       { $$ = MkDeclaratorBrackets($2); }
1198         | direct_declarator_nofunction '[' constant_expression ']'
1199       { $$ = MkDeclaratorArray($1, $3); }
1200         | direct_declarator_nofunction '[' ']'
1201       { $$ = MkDeclaratorArray($1, null); }
1202    | direct_declarator_nofunction '[' type ']'
1203       { $$ = MkDeclaratorEnumArray($1, $3); }
1204         ;
1205
1206 declarator_function:
1207      direct_declarator_function
1208         | pointer direct_declarator_function
1209       { $$ = MkDeclaratorPointer($1, $2); }
1210
1211    | ext_decl direct_declarator_function
1212       { $$ = MkDeclaratorExtended($1, $2); }
1213         | ext_decl pointer direct_declarator_function
1214       { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
1215         | pointer ext_decl direct_declarator_function
1216       { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
1217
1218    ;
1219
1220 direct_declarator_function_start:
1221      direct_declarator_nofunction '('
1222    ;
1223
1224 direct_declarator_function:
1225           direct_declarator_function_start parameter_type_list ')'
1226       { $$ = MkDeclaratorFunction($1, $2); }
1227         | direct_declarator_function_start identifier_list ')'
1228       { $$ = MkDeclaratorFunction($1, $2); }
1229         | direct_declarator_function_start ')'
1230       { $$ = MkDeclaratorFunction($1, null); }
1231         ;
1232
1233 direct_declarator:
1234      direct_declarator_function
1235    | direct_declarator_nofunction
1236    | ext_decl direct_declarator_function
1237       { $$ = MkDeclaratorExtended($1, $2); }
1238    | ext_decl direct_declarator_nofunction
1239       { $$ = MkDeclaratorExtended($1, $2); }
1240         ;
1241
1242 declarator_nofunction:
1243           direct_declarator_nofunction
1244         | pointer direct_declarator_nofunction      { $$ = MkDeclaratorPointer($1, $2); }
1245    | ext_decl direct_declarator_nofunction { $$ = MkDeclaratorExtended($1, $2); }
1246         | ext_decl pointer direct_declarator_nofunction { $$ = MkDeclaratorExtended($1, MkDeclaratorPointer($2, $3)); }
1247         | pointer ext_decl direct_declarator_nofunction { $$ = MkDeclaratorPointer($1, MkDeclaratorExtended($2, $3)); }
1248 ;
1249
1250 type_qualifier_list:
1251           type_qualifier                          { $$ = MkList(); ListAdd($$, $1); }
1252         | type_qualifier_list type_qualifier      { $$ = $1; ListAdd($1, $2);  }
1253         ;
1254
1255 pointer:
1256           '*'                               { $$ = MkPointer(null, null); }
1257         | '*' type_qualifier_list           { $$ = MkPointer($2, null); }
1258         | '*' pointer                       { $$ = MkPointer(null, $2); }
1259         | '*' type_qualifier_list pointer   { $$ = MkPointer($2, $3); }
1260         ;
1261
1262 parameter_type_list:
1263           parameter_list
1264         | parameter_list ',' ELLIPSIS { $$ = $1; ListAdd($1, MkTypeName(null, null)); }
1265         ;
1266
1267 parameter_list:
1268           parameter_declaration                      { $$ = MkList(); ListAdd($$, $1); }
1269         | parameter_list ',' parameter_declaration   { $$ = $1; ListAdd($1, $3); }
1270         ;
1271
1272 parameter_declaration:
1273           guess_declaration_specifiers declarator          { $$ = MkTypeName($1, $2); }
1274         | guess_declaration_specifiers abstract_declarator { $$ = MkTypeName($1, $2); }
1275    | guess_declaration_specifiers '&'                 { $$ = MkTypeName($1, MkDeclaratorPointer(MkPointer(null,null), null)); }
1276    | guess_declaration_specifiers '&' declarator      { $$ = MkTypeName($1, MkDeclaratorPointer(MkPointer(null,null), $3)); }
1277    | real_guess_declaration_specifiers                { $$ = MkTypeName($1, null); }
1278 /*
1279    | CLASS
1280       { $$ = MkTypeName(MkList(), null); $$.typedObject = true; }                        // Confusion with ellipsis? MkList()?
1281    | CLASS '&'
1282       { $$ = MkTypeName(null, null); $$.typedObject = true; $$.byReference = true; }
1283    | CLASS declarator
1284       { $$ = MkTypeName(MkList(), $2); $$.typedObject = true; }                        // Confusion with ellipsis? MkList()?
1285    | CLASS '&' declarator
1286       { $$ = MkTypeName(null, $3); $$.typedObject = true; $$.byReference = true; }
1287 */
1288    | CLASS
1289       { $$ = MkTypeName(MkListOne(MkSpecifier(CLASS)), null); }
1290 /*
1291    | TYPED_OBJECT
1292       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), null); }
1293    | TYPED_OBJECT '&'
1294       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), MkDeclaratorPointer(MkPointer(null,null), null)); }
1295    | TYPED_OBJECT declarator
1296       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), $2);  }
1297    | TYPED_OBJECT '&' declarator
1298       { $$ = MkTypeName(MkListOne(MkSpecifier(TYPED_OBJECT)), MkDeclaratorPointer(MkPointer(null,null), $3)); }
1299    | ANY_OBJECT
1300       { $$ = MkTypeName(MkListOne(MkSpecifier(ANY_OBJECT)), null); }
1301    | ANY_OBJECT declarator
1302       { $$ = MkTypeName(MkListOne(MkSpecifier(ANY_OBJECT)), $2); }
1303
1304    | error
1305       { $$ = MkTypeName(MkListOne(MkSpecifier(INT)), null); }
1306    | error declarator             { $$ = MkTypeName(MkListOne(MkSpecifier(INT)), $2); }
1307    //| error struct_declarator             { $$ = MkTypeName(MkListOne(MkSpecifier(INT)), $2); }
1308    | error abstract_declarator          { $$ = MkTypeName(MkListOne(MkSpecifier(INT)), $2); }
1309 */
1310         ;
1311
1312 identifier_list:
1313           identifier                        { $$ = MkList(); ListAdd($$, MkTypeName(null, MkDeclaratorIdentifier($1))); }
1314         | identifier_list ',' identifier    { $$ = $1; ListAdd($1, MkTypeName(null, MkDeclaratorIdentifier($3))); }
1315         ;
1316
1317 type_name:
1318           specifier_qualifier_list                      { $$ = MkTypeName($1, null); }
1319         | specifier_qualifier_list abstract_declarator  { $$ = MkTypeName($1, $2); }
1320         ;
1321
1322 guess_type_name:
1323           guess_specifier_qualifier_list                         { $$ = MkTypeName($1, null); }
1324         | guess_specifier_qualifier_list abstract_declarator     { $$ = MkTypeName($1, $2); }
1325         ;
1326
1327 initializer:
1328           assignment_expression
1329       { $$ = MkInitializerAssignment($1); $$.loc = @$; }
1330         | '{' initializer_list '}'
1331       { $$ = MkInitializerList($2); $$.loc = @$; }
1332         | '{' initializer_list ',' '}'
1333       {
1334          $$ = MkInitializerList($2);
1335          $$.loc = @$;
1336
1337          {
1338             Expression exp = MkExpDummy();
1339             Initializer init = MkInitializerAssignment(exp);
1340             init.loc = @3;
1341             exp.loc = @3;
1342             ListAdd($2, init);
1343          }
1344       }
1345         ;
1346
1347 initializer_condition:
1348           conditional_expression
1349       { $$ = MkInitializerAssignment($1); $$.loc = @$; }
1350    | anon_instantiation_expression
1351       { $$ = MkInitializerAssignment($1); $$.loc = @$; }
1352 /*
1353         | '{' initializer_list '}'
1354       { $$ = MkInitializerList($2); $$.loc = @$; }
1355         | '{' initializer_list ',' '}'
1356       {
1357          $$ = MkInitializerList($2);
1358          $$.loc = @$;
1359
1360          {
1361             Expression exp = MkExpDummy();
1362             Initializer init = MkInitializerAssignment(exp);
1363             init.loc = @3;
1364             exp.loc = @3;
1365             ListAdd($2, init);
1366          }
1367       }
1368 */
1369         ;
1370
1371 initializer_list:
1372           initializer
1373       { $$ = MkList(); ListAdd($$, $1); }
1374         | initializer_list ',' initializer
1375       { $$ = $1; ListAdd($1, $3); }
1376         ;
1377
1378 statement:
1379           labeled_statement
1380         | compound_statement
1381         | expression_statement
1382         | selection_statement
1383         | iteration_statement
1384         | jump_statement
1385         ;
1386
1387 labeled_statement:
1388           identifier ':' statement
1389       { $$ = MkLabeledStmt($1, $3); $$.loc = @$; }
1390         | CASE constant_expression ':' statement
1391       { $$ = MkCaseStmt($2, $4); $$.loc = @$; $2.loc.start = @1.end; }
1392         | DEFAULT ':' statement
1393       { $$ = MkCaseStmt(null, $3); $$.loc = @$; }
1394         ;
1395
1396 declaration_list:
1397           declaration                       { $$ = MkList(); ListAdd($$, $1); }
1398         | declaration_list declaration      { $$ = $1; ListAdd($1, $2); }
1399         ;
1400
1401 statement_list:
1402           statement                         { $$ = MkList(); ListAdd($$, $1); }
1403         | statement_list statement          { $$ = $1; ListAdd($1, $2); }
1404
1405    // declaration not allowed after statements
1406    | statement_list declaration              { Statement stmt = MkBadDeclStmt($2); stmt.loc = @2; /*yyerror(); */ ListAdd($1, stmt); $$ = $1; }
1407         ;
1408
1409 compound_inside:
1410           statement_list                      { $$ = MkCompoundStmt(null, $1); }
1411         | declaration_list                  { $$ = MkCompoundStmt($1, null); }
1412         | declaration_list statement_list   { $$ = MkCompoundStmt($1, $2); }
1413    ;
1414
1415 compound_start:
1416     '{' { $<context>$ = PushContext(); }
1417     ;
1418
1419 compound_statement:
1420    '{' '}'
1421    {
1422       $$ = MkCompoundStmt(null, null);
1423       $$.compound.context = PushContext();
1424       PopContext($$.compound.context);
1425       $$.loc = @$;
1426    }
1427
1428         | compound_start compound_inside '}'
1429       { $$ = $2; $$.compound.context = $<context>1; PopContext($<context>1); $$.loc = @$; }
1430         ;
1431
1432 expression_statement:
1433           ';'                         { $$ = MkExpressionStmt(null); $$.loc = @$; }
1434         | expression ';'              { $$ = MkExpressionStmt($1); $$.loc = @$; }
1435         ;
1436
1437 selection_statement:
1438           IF '(' expression ')' statement %prec IFX        { $$ = MkIfStmt($3, $5, null); $$.loc = @$; }
1439         | IF '(' expression ')' statement ELSE statement   { $$ = MkIfStmt($3, $5, $7); $$.loc = @$; }
1440         | SWITCH '(' expression ')' statement              { $$ = MkSwitchStmt($3, $5); $$.loc = @$; }
1441         ;
1442
1443 iteration_statement:
1444           WHILE '(' expression ')' statement           { $$ = MkWhileStmt($3, $5); $$.loc = @$; }
1445         | DO statement WHILE '(' expression ')' ';'     { $$ = MkDoWhileStmt($2, $5); $$.loc = @$; }
1446         | FOR '(' expression_statement expression_statement ')' statement                   { $$ = MkForStmt($3, $4, null, $6); $$.loc = @$; }
1447         | FOR '(' expression_statement expression_statement expression ')' statement        { $$ = MkForStmt($3, $4, $5, $7); $$.loc = @$; }
1448
1449    | WHILE '(' ')' statement     { $$ = MkWhileStmt(null, $4); $$.loc = @$; }
1450    | FOR '(' expression_statement ')' statement                   { $$ = MkForStmt($3, null, null, $5); $$.loc = @$; }
1451    | FOR '(' ')' statement  { $$ = MkForStmt(null, null, null, $4); $$.loc = @$; }
1452         ;
1453
1454 jump_statement:
1455           GOTO identifier ';'   { $$ = MkGotoStmt($2); $$.loc = @$; }
1456         | CONTINUE ';'          { $$ = MkContinueStmt(); $$.loc = @$; }
1457         | BREAK ';'             { $$ = MkBreakStmt(); $$.loc = @$; }
1458         | RETURN ';'            { Expression exp = MkExpDummy(); $$ = MkReturnStmt(MkListOne(exp)); $$.loc = @$; exp.loc = @2; }
1459         | RETURN expression ';' { $$ = MkReturnStmt($2); $$.loc = @$; }
1460         ;
1461
1462 string_literal:
1463    STRING_LITERAL { $$ = CopyString(yytext); }
1464    ;
1465
1466 instantiation_named:
1467      declaration_specifiers identifier '{' members_initialization_list '}'
1468       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
1469    | declaration_specifiers identifier '{' '}'
1470       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), MkList());  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.start;}
1471    ;
1472
1473 guess_instantiation_named:
1474      guess_declaration_specifiers identifier '{' members_initialization_list '}'
1475       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;}
1476    |  guess_declaration_specifiers identifier '{' '}'
1477       { $$ = MkInstantiationNamed($1, MkExpIdentifier($2), MkList());  $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @4.start;}
1478
1479    /*| guess_declaration_specifiers identifier '{' members_initialization_list error
1480       {
1481          int l = 0;
1482          $$ = MkInstantiationNamed($1, MkExpIdentifier($2), $4); $$.loc = @$; $$.nameLoc = @2; $$.insideLoc.start = @3.end; $$.insideLoc.end = @5.start;
1483
1484          for(;;)
1485          {
1486             if(yychar == '}')
1487                l--;
1488             else if(yychar == '{')
1489                l++;
1490             if(l<0)
1491                break;
1492             yychar = yylex();
1493             yyerrok;
1494          }
1495          if(yychar == '}')
1496             yychar = yylex();
1497       }*/
1498    ;
1499
1500 instantiation_unnamed:
1501      type '{' members_initialization_list '}'
1502       { $$ = MkInstantiation($1, null, $3);  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; }
1503    | type '{' '}'
1504       { $$ = MkInstantiation($1, null, MkList());  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.start;}
1505    | identifier '{' members_initialization_list '}'
1506       { Location tmpLoc = yylloc; yylloc = @1; yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, $3);$$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @4.start; FreeIdentifier($1); }
1507    | identifier '{' '}'
1508       { Location tmpLoc = yylloc; yylloc = @1; yylloc = tmpLoc;  $$ = MkInstantiation(MkSpecifierName($1.string), null, MkList());  $$.loc = @$; $$.insideLoc.start = @2.end; $$.insideLoc.end = @3.start; FreeIdentifier($1); }
1509    ;
1510
1511 instantiation_anon:
1512      '{' members_initialization_list '}'
1513       { $$ = MkInstantiation(null, null, $2);  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @3.start; }
1514    | '{' '}'
1515       { $$ = MkInstantiation(null, null, MkList());  $$.loc = @$; $$.insideLoc.start = @1.end; $$.insideLoc.end = @2.start;}
1516    ;
1517 class_function_definition:
1518           class_function_definition_start compound_statement
1519       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
1520         | virtual_class_function_definition_start compound_statement
1521       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
1522    | virtual_class_function_definition_start ';'
1523       { ProcessClassFunctionBody($1, null); $$.loc = @$; }
1524         | constructor_function_definition_start compound_statement
1525       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
1526         | destructor_function_definition_start compound_statement
1527       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
1528         ;
1529
1530 instance_class_function_definition_start:
1531    // Guess here conflicts with an expression...
1532      declaration_specifiers declarator_function
1533       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; }
1534     | declaration_specifiers declarator_nofunction
1535       { $$ = MkClassFunction($1, null, $2, null); $$.loc = @$; }
1536       ;
1537
1538 instance_class_function_definition:
1539           instance_class_function_definition_start compound_statement
1540       { ProcessClassFunctionBody($1, $2); $$.loc = @$; }
1541         ;
1542
1543 data_member_initialization:
1544      postfix_expression '=' initializer_condition { $$ = MkMemberInitExp($1, $3); $$.loc = @$; $$.realLoc = @$; $$.initializer.loc.start = @2.end;}
1545    | initializer_condition                { $$ = MkMemberInit(null, $1); $$.loc = @$; $$.realLoc = @$;}
1546    ;
1547
1548 data_member_initialization_list:
1549      data_member_initialization
1550       { $$ = MkList(); ListAdd($$, $1); }
1551    | data_member_initialization_list ',' data_member_initialization
1552       { ((MemberInit)$1->last).loc.end = @3.start; ListAdd($1, $3); $$ = $1; }
1553    ;
1554
1555 data_member_initialization_list_coloned:
1556    data_member_initialization_list ';'
1557       { if($1->last) ((MemberInit)$1->last).loc.end = @2.end; $$ = $1; }
1558    ;
1559
1560 members_initialization_list_coloned:
1561      data_member_initialization_list_coloned                                        { MembersInit members = MkMembersInitList($1); $$ = MkList(); ListAdd($$, members); members.loc = @1; }
1562    | instance_class_function_definition                                             { $$ = MkList(); ListAdd($$, MkMembersInitMethod($1)); ((MembersInit)$$->last).loc = @1; }
1563    | members_initialization_list_coloned  data_member_initialization_list_coloned   { MembersInit members = MkMembersInitList($2); ListAdd($$, members); members.loc = @2; $$ = $1;  }
1564    | members_initialization_list_coloned  instance_class_function_definition        { ListAdd($$, MkMembersInitMethod($2)); ((MembersInit)$$->last).loc = @2;$$ = $1;  }
1565    | ';'                                                                            { MembersInit members = MkMembersInitList(MkList()); $$ = MkList(); ListAdd($$, members); members.loc = @1;  }
1566    | members_initialization_list_coloned ';'                                        { MembersInit members = MkMembersInitList(MkList()); ListAdd($$, members); members.loc = @2; $$ = $1; }
1567    ;
1568
1569 members_initialization_list:
1570      members_initialization_list_coloned
1571    | data_member_initialization_list                                       { $$ = MkList(); ListAdd($$, MkMembersInitList($1)); ((MembersInit)$$->last).loc = @1; }
1572    | members_initialization_list_coloned data_member_initialization_list   { ListAdd($1, MkMembersInitList($2));   ((MembersInit)$$->last).loc = @2; }
1573    ;
1574
1575 type_unit:
1576      parameter_declaration                            { parsedType = $1; }
1577    | parameter_declaration ':' constant_expression    { parsedType = $1; parsedType.bitCount = $3; }
1578    ;
1579
1580 %%